Class: DexSync::UpdateKubeConfigService

Inherits:
Object
  • Object
show all
Defined in:
lib/dex_sync.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ UpdateKubeConfigService



44
45
46
# File 'lib/dex_sync.rb', line 44

def initialize(config)
  @config = config
end

Instance Method Details

#performObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/dex_sync.rb', line 48

def perform
  @config.clusters.each do |cluster|
     = { cross_client: cluster, offline_access: 'yes' }

    puts("Logging into dex app...#{cluster}")
    response = connection.post('login', )
    puts('Wait for it...')

    doc = Nokogiri::HTML(response.body)

    refresh_token = doc.css('form > input[name=refresh_token]').first['value']
    id_token      = doc.css('form > input[name=id_token]').first['value']

    @config.namespaces.each do |namespace|
      puts("Dowloading config for #{cluster}:#{namespace}")

      download_params = {
        refresh_token: refresh_token,
        id_token: id_token,
        namespace: namespace,
        internal: true
      }

      response = connection.post('download', download_params)

      downloaded_config = YAML.safe_load(response.body)

      expanded_path = File.expand_path(@config.download_path + "/#{cluster}-#{namespace}-internal")

      File.open(expanded_path, 'w') { |f| f.write(downloaded_config.to_yaml) }
    end
  end
end