Sha256: 27d14e8deadc84015649338a5aec95fd9d2a06b52ba4318e68086bd12677c136

Contents?: true

Size: 1.76 KB

Versions: 13

Compression:

Stored size: 1.76 KB

Contents

module Kontena::Cli::Cloud::Master
  class UpdateCommand < Kontena::Command

    include Kontena::Cli::Common

    callback_matcher 'cloud-master', 'update'

    requires_current_account_token

    parameter "MASTER_ID", "Master ID"

    option ['--redirect-uri'], '[URL]',      'Set master redirect URL'
    option ['--url'],          '[URL]',      'Set master URL'
    option ['--provider'],     '[NAME]',     'Set master provider'
    option ['--name'],         '[NAME]',     'Set master name',        hidden: true
    option ['--version'],      '[VERSION]',  'Set master version',     hidden: true
    option ['--owner'],        '[NAME]',     'Set master owner',       hidden: true

    def get_attributes
      cloud_client.get("user/masters/#{self.master_id}")["data"]["attributes"]
    rescue
      nil
    end

    def execute
      attrs = get_attributes
      unless attrs
        puts "Failed to obtain master credentials".colorize(:red)
        exit 1
      end

      attrs["name"]         = self.name         if self.name
      attrs["redirect-uri"] = self.redirect_uri if self.redirect_uri
      attrs["url"]          = self.url          if self.url
      attrs["provider"]     = self.provider     if self.provider
      attrs["version"]      = self.version      if self.version
      attrs["owner"]        = self.owner        if self.owner

      response = cloud_client.put(
        "master",
        { data: { attributes: attrs.reject{ |k, _| ['client-id', 'client-secret'].include?(k) } } },
        {},
        cloud_client.basic_auth_header(
          attrs["client-id"],
          attrs["client-secret"]
        ),
        false
      )

      if response
        puts "Master settings updated"
      else
        puts "Request failed"
        exit 1
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kontena-cli-0.16.0 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.rc3 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.rc2 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.rc1 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre9 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre8 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre7 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre6 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre5 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre4 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre3 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre2 lib/kontena/cli/cloud/master/update_command.rb
kontena-cli-0.16.0.pre1 lib/kontena/cli/cloud/master/update_command.rb