Sha256: 457cf325a83f79fbfa23bd0ece56e5c1af9955114efc0f41c54a27bbd6e70e1f

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module Seira
  class Helpers
    include Seira::Commands

    class << self
      def rails_env(context:)
        if context[:cluster] == 'internal'
          'production'
        else
          context[:cluster]
        end
      end

      def fetch_pods(filters:, context:)
        filter_string = { app: context[:app] }.merge(filters).map { |k, v| "#{k}=#{v}" }.join(',')
        output = Seira::Commands.kubectl("get pods -o json --selector=#{filter_string}", context: context, return_output: true)
        JSON.parse(output)['items']
      end

      def log_link(context:, query:)
        link = context[:settings].log_link_format
        return nil if link.nil?
        link.gsub! 'APP', context[:app]
        link.gsub! 'CLUSTER', context[:cluster]
        link.gsub! 'QUERY', query
        link
      end

      def get_secret(key:, context:)
        Secrets.new(app: context[:app], action: 'get', args: [], context: context).get(key)
      end

      def shell_username
        `whoami`
      rescue
        'unknown'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
seira-0.4.3 lib/helpers.rb
seira-0.4.2 lib/helpers.rb
seira-0.4.1 lib/helpers.rb