class UC3::UC3Client
Base class for UC3 client classes
Constants
- ECS_DBSNAPSHOT
- ECS_DEV
- ECS_EPHEMERAL
- ECS_PRD
- ECS_STG
- STATHASH
- STATUS
Attributes
Public Class Methods
Source
# File app/lib/client/uc3_client.rb, line 31 def self.client UC3::UC3Client.clients.fetch(self.class.to_s, UC3Client.new) end
Source
# File app/lib/client/uc3_client.rb, line 86 def self.cluster_name ENV.fetch('ECS_STACK_NAME', 'mrt-ecs-dev-stack') end
Source
# File app/lib/client/uc3_client.rb, line 94 def self.dbsnapshot_stack? stack_name == ECS_DBSNAPSHOT end
Source
# File app/lib/client/uc3_client.rb, line 189 def self.deployed_tag?(tag, itags) arr = itags.clone arr << tag arr.each do |t| return true if t =~ /^(ecs-.*|dev|stg|prd|latest)$/ end false end
Source
# File app/lib/client/uc3_client.rb, line 198 def self.keep_artifact_version?(ver) ver =~ /^\d+\.\d+-SNAPSHOT$/ end
Source
# File app/lib/client/uc3_client.rb, line 130 def self.load_config(filename) config = YAML.safe_load_file(filename, aliases: true) JSON.parse(config.to_json, symbolize_names: true) end
Source
# File app/lib/client/uc3_client.rb, line 140 def self.lookup_map(map, key: nil, symbolize_names: false) unless ENV.fetch('MERRITT_ECS', '').empty? ssm = Aws::SSM::Client.new( region: UC3::UC3Client.region ) end map = map.fetch(key, {}) unless key.nil? map.clone.each do |key, value| if key == '_fixed' map[key].each do |k, v| map[k] = v end end if value.key?('ssm') && !ssm.nil? begin resp = ssm.get_parameter(name: value['ssm'], with_decryption: true) map[key] = resp.parameter.value rescue StandardError map[key] = value.fetch('default', 'not-applicable') end elsif value.key?('env') map[key] = ENV.fetch(value['env'], value.fetch('default', '')) elsif value.key?('val') map[key] = value['val'] end case value.fetch('type', 'string') when 'int' map[key] = map[key].to_i when 'float' map[key] = map[key].to_f end end map = JSON.parse(map.to_json, symbolize_names: true) if symbolize_names map end
Source
# File app/lib/client/uc3_client.rb, line 135 def self.lookup_map_by_filename(filename, key: nil, symbolize_names: false) map = YAML.safe_load_file(filename, aliases: true) lookup_map(map, key: key, symbolize_names: symbolize_names) end
Source
# File app/lib/client/uc3_client.rb, line 35 def initialize(enabled: true, message: '') UC3Client.clients[self.class.to_s] = { name: self.class.to_s, enabled: enabled, message: message } @enabled = enabled end
Source
# File app/lib/client/uc3_client.rb, line 82 def self.region ENV['AWS_REGION'] || 'us-west-2' end
Source
# File app/lib/client/uc3_client.rb, line 177 def self.resolve_lookup(filename, map) YAML.safe_load(Mustache.render(File.read(filename), map)) end
Source
# File app/lib/client/uc3_client.rb, line 185 def self.semantic_prefix_tag?(tag) !(tag =~ /^\d+\.\d+\.\d+(\..+)?$/).nil? end
Source
# File app/lib/client/uc3_client.rb, line 181 def self.semantic_tag?(tag) !(tag =~ /^\d+\.\d+\.\d+$/).nil? end
Source
# File app/lib/client/uc3_client.rb, line 90 def self.stack_name ENV.fetch('MERRITT_ECS', 'ecs-dev') end
Source
# File app/lib/client/uc3_client.rb, line 50 def self.status_compare(stat1, stat2) status_index(stat1) > status_index(stat2) ? stat1 : stat2 end
Source
# File app/lib/client/uc3_client.rb, line 42 def self.status_index(stat) STATHASH.fetch(stat.to_sym, 0) end
Source
# File app/lib/client/uc3_client.rb, line 46 def self.status_resolve(stat) STATUS[status_index(stat)] end
Public Instance Methods
Source
# File app/lib/client/uc3_client.rb, line 116 def client_list table = AdminUI::FilterTable.new( columns: [ AdminUI::Column.new(:name, header: 'Client'), AdminUI::Column.new(:enabled, header: 'Enabled'), AdminUI::Column.new(:message, header: 'Message') ] ) self.class.clients.sort.each do |_key, value| table.add_row(AdminUI::Row.make_row(table.columns, value)) end table end
Source
# File app/lib/client/uc3_client.rb, line 98 def context table = AdminUI::FilterTable.new( columns: [ AdminUI::Column.new(:key, header: 'Key'), AdminUI::Column.new(:value, header: 'Value') ] ) ENV.sort.each do |key, value| v = key =~ /(KEY|TOKEN|SECRET)/ ? '***' : value table.add_row(AdminUI::Row.new([key, v])) end table end
Source
# File app/lib/client/uc3_client.rb, line 72 def date_format(date, convert_timezone: false) return '' if date.nil? || date.to_s.empty? d = DateTime.parse(date.to_s).to_time return '' if d.nil? d = d.localtime if convert_timezone d.strftime('%Y-%m-%d %H:%M:%S') end
Source
# File app/lib/client/uc3_client.rb, line 54 def record_status(path, status) qc = UC3Query::QueryClient.client return unless !qc.nil? && qc.enabled begin params = {} params['check_name'] = path params['status'] = status.to_s qc.query_update( '/ops/log-consistency', params, purpose: 'Record Consistency status' ) rescue StandardError => e puts "Error recording status for #{path}: #{e.message}" end end