Class: EPC::Command::CreateRoleCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/role/create_role_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#create_role(role) ⇒ Object

Raises:



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/epc/command/role/create_role_command.rb', line 14

def create_role(role)
  raise FatalError, "You must specify a role name" if role.blank? 
  status, response, headers = client.post(EPC::Config::ROLES_PATH, {:name => role})

  if status.successful?
    say("Role [#{role}] created")
  else
    say_err("Request failed: [#{response[:message]}]")
  end
  return status, response[:id]
end

#execute(args = []) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/epc/command/role/create_role_command.rb', line 4

def execute(args = [])
  role = args[0]

  if @options[:file].present?
    return handle_file_role_creation
  else
    return create_role(role)[0]
  end
end

#handle_file_role_creationObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/epc/command/role/create_role_command.rb', line 26

def handle_file_role_creation
  contents = EPC::Config.read_content_as_json(@options[:file])
  role = contents["name"]
  status, role_id = create_role(role)

  return 1 unless status.successful?

  batch_add(role_id,contents)

  return 0

end