Class: DexSync::UpdateKubeConfigService

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ UpdateKubeConfigService

Returns a new instance of UpdateKubeConfigService.



40
41
42
# File 'lib/dex_sync.rb', line 40

def initialize(config)
  @config = config
end

Instance Method Details

#performObject



44
45
46
47
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
# File 'lib/dex_sync.rb', line 44

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)

      config = YAML.safe_load(response.body)

      File.open(File.expand_path("~/.kubeconfigs/#{cluster}-#{namespace}-internal"), 'w') do |f|
        f.write(config.to_yaml)
      end
    end
  end
end