Sha256: 7855817f74b182bd8054a3af8f529f2a8db76a03e91f2b47d8c2859a4306e527

Contents?: true

Size: 1.7 KB

Versions: 43

Compression:

Stored size: 1.7 KB

Contents

require_relative '../../common'
require_relative 'role/add_command'

module Kontena::Cli::Master::User
  class InviteCommand < Kontena::Command
    include Kontena::Cli::Common

    parameter "EMAIL ...", "List of emails"

    option ['-r', '--roles'], '[ROLES]', 'Comma separated list of roles to assign to the invited users'
    option ['-c', '--code'], :flag, 'Only output the invite code'
    option '--external-id', '[EXTERNAL ID]', 'Assign external id to user', hidden: true
    option '--return', :flag, 'Return the code', hidden: true

    requires_current_master
    requires_current_master_token

    def execute
      if self.roles
        roles = self.roles.split(',')
      else
        roles = []
      end
      external_id = nil
      if email_list.size == 1 && self.external_id
        external_id = self.external_id
      end
      email_list.each do |email|
        begin
          data = { email: email, external_id: external_id, response_type: 'invite' }
          response = client.post('/oauth2/authorize', data)
          if self.code?
            puts response['invite_code']
          elsif self.return?
            return response
          else
            puts "Invitation created for #{response['email']}".colorize(:green)
            puts "  * code:    #{response['invite_code']}"
            puts "  * command: kontena master join #{current_master.url} #{response['invite_code']}"
          end
          roles.each do |role|
            raise "Failed to add role" unless Kontena.run(["master", "user", "role", "add", role, email])
          end
        rescue => ex
          logger.error(ex)
          exit_with_error "Failed to invite #{email} : #{ex.message}"
        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
kontena-cli-1.4.3 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.3.rc1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.2 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.2.rc1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.2.pre1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.1.rc1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.1.pre1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.3.5 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.3.5.rc1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.rc2 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.rc1 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre14 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre13 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre12 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre11 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre10 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre9 lib/kontena/cli/master/user/invite_command.rb
kontena-cli-1.4.0.pre8 lib/kontena/cli/master/user/invite_command.rb