Class: Seira::Settings
- Inherits:
-
Object
- Object
- Seira::Settings
- Defined in:
- lib/seira/settings.rb
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
'.seira.yml'.freeze
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
Instance Method Summary collapse
- #applications ⇒ Object
- #clusters ⇒ Object
- #config_for_app(app_name) ⇒ Object
- #expected_environment_variable_during_deploys ⇒ Object
- #full_cluster_name_for_shorthand(shorthand) ⇒ Object
-
#initialize(config_path: DEFAULT_CONFIG_PATH) ⇒ Settings
constructor
A new instance of Settings.
- #log_link_format ⇒ Object
- #organization_id ⇒ Object
- #project_for_cluster(cluster) ⇒ Object
- #region_for_cluster(cluster) ⇒ Object
- #settings ⇒ Object
- #teleport_auth(cluster) ⇒ Object
- #teleport_cluster(cluster) ⇒ Object
- #teleport_kubernetes_cluster(cluster) ⇒ Object
- #teleport_role_requirements(cluster) ⇒ Object
- #terminal_prefix(application, cluster) ⇒ Object
- #use_teleport?(cluster) ⇒ Boolean
- #valid_cluster_names ⇒ Object
- #zone_for_cluster(cluster) ⇒ Object
Constructor Details
#initialize(config_path: DEFAULT_CONFIG_PATH) ⇒ Settings
Returns a new instance of Settings.
10 11 12 |
# File 'lib/seira/settings.rb', line 10 def initialize(config_path: DEFAULT_CONFIG_PATH) @config_path = config_path end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
8 9 10 |
# File 'lib/seira/settings.rb', line 8 def config_path @config_path end |
Instance Method Details
#applications ⇒ Object
23 24 25 |
# File 'lib/seira/settings.rb', line 23 def applications settings['seira']['applications'].map { |app| app['name'] } end |
#clusters ⇒ Object
35 36 37 |
# File 'lib/seira/settings.rb', line 35 def clusters settings['seira']['clusters'] end |
#config_for_app(app_name) ⇒ Object
27 28 29 |
# File 'lib/seira/settings.rb', line 27 def config_for_app(app_name) settings['seira']['applications'].find { |app| app['name'] == app_name } end |
#expected_environment_variable_during_deploys ⇒ Object
67 68 69 |
# File 'lib/seira/settings.rb', line 67 def expected_environment_variable_during_deploys settings['seira']['expected_environment_variable_during_deploys'] end |
#full_cluster_name_for_shorthand(shorthand) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/seira/settings.rb', line 43 def full_cluster_name_for_shorthand(shorthand) return shorthand if valid_cluster_names.include?(shorthand) # Try iterating through each cluster to find the relevant alias clusters.each do |cluster_name, | next if ['aliases'].nil? || ['aliases'].empty? return cluster_name if ['aliases'].include?(shorthand) end nil end |
#log_link_format ⇒ Object
39 40 41 |
# File 'lib/seira/settings.rb', line 39 def log_link_format settings['seira']['log_link_format'] end |
#organization_id ⇒ Object
19 20 21 |
# File 'lib/seira/settings.rb', line 19 def organization_id settings['seira']['organization_id'] end |
#project_for_cluster(cluster) ⇒ Object
55 56 57 |
# File 'lib/seira/settings.rb', line 55 def project_for_cluster(cluster) settings['seira']['clusters'][cluster]['project'] end |
#region_for_cluster(cluster) ⇒ Object
59 60 61 |
# File 'lib/seira/settings.rb', line 59 def region_for_cluster(cluster) settings['seira']['clusters'][cluster]['region'] end |
#settings ⇒ Object
14 15 16 17 |
# File 'lib/seira/settings.rb', line 14 def settings return @_settings if defined?(@_settings) @_settings = parse_settings end |
#teleport_auth(cluster) ⇒ Object
83 84 85 |
# File 'lib/seira/settings.rb', line 83 def teleport_auth(cluster) settings['seira']['clusters'][cluster].dig('teleport', 'auth') end |
#teleport_cluster(cluster) ⇒ Object
79 80 81 |
# File 'lib/seira/settings.rb', line 79 def teleport_cluster(cluster) settings['seira']['clusters'][cluster].dig('teleport', 'cluster') end |
#teleport_kubernetes_cluster(cluster) ⇒ Object
87 88 89 |
# File 'lib/seira/settings.rb', line 87 def teleport_kubernetes_cluster(cluster) settings['seira']['clusters'][cluster].dig('teleport', 'kubernetes_cluster') || cluster end |
#teleport_role_requirements(cluster) ⇒ Object
91 92 93 94 95 |
# File 'lib/seira/settings.rb', line 91 def teleport_role_requirements(cluster) requirements = settings['seira']['clusters'][cluster].dig('teleport', 'role_requirements') || [] requirements.map { |r| Seira::Teleport::RoleRequirement.new(r) } end |
#terminal_prefix(application, cluster) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/seira/settings.rb', line 97 def terminal_prefix(application, cluster) settings['seira']['applications'].each do |app| if app['name'] == application return app.fetch('terminal_prefix', '') if app['terminal_prefix_envs'].nil? return app.fetch('terminal_prefix', '') if app['terminal_prefix_envs'].include? cluster return '' end end end |
#use_teleport?(cluster) ⇒ Boolean
71 72 73 74 75 76 77 |
# File 'lib/seira/settings.rb', line 71 def use_teleport?(cluster) teleport_enabled = settings['seira']['clusters'][cluster].dig('teleport', 'enabled') return false if teleport_enabled.nil? teleport_enabled || ENV['SEIRA_TELEPORT_ENABLED'] == 'true' end |
#valid_cluster_names ⇒ Object
31 32 33 |
# File 'lib/seira/settings.rb', line 31 def valid_cluster_names settings['seira']['clusters'].keys end |
#zone_for_cluster(cluster) ⇒ Object
63 64 65 |
# File 'lib/seira/settings.rb', line 63 def zone_for_cluster(cluster) settings['seira']['clusters'][cluster]['zone'] end |