Class: UnimatrixCLI::Keymaker::ResourceOwner::PoliciesCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/unimatrix_cli/keymaker/resource_owner/policies_command.rb

Instance Method Summary collapse

Methods inherited from Command

available_commands, descendants, #initialize, #read_file, #validate, #validate_collection, #write

Methods included from UnimatrixParser

included

Constructor Details

This class inherits a constructor from UnimatrixCLI::Command

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/unimatrix_cli/keymaker/resource_owner/policies_command.rb', line 15

def execute
  endpoint = "#{ Configuration.default_config[ 'keymaker_url' ] }/policies?" +
    "access_token=#{ Configuration.access_token }&" +
    "resource_owner_uuid=#{ @options[ :resource_owner_uuid ] }"
    
  policies_response = make_request( endpoint, 'Get' )
  
  if !policies_response[ 'error' ]
    unscoped_policies = policies_response[ 'policies' ]
    
    if unscoped_policies.present?
      scoped_policies = scope_policies( unscoped_policies )
      
      if scoped_policies.present?
        scoped_policies.each do | policy |
          write(
            message: "Resource: #{ policy[ 'resource' ] }\n" +
            "Actions: #{ policy[ 'actions' ] }\n\n"
          )
        end
      else
        write(
          message: "No policies found for resource owner with uuid " +
          "#{ @options[ :resource_owner_uuid ] } for realm #{ @options[ :realm ] }"
        )
      end
    else
      write(
        message: "No policies found for resource owner with uuid " +
        "#{ @options[ :resource_owner_uuid ] }"
      )
    end
  else
    write(
      message: "Error: error retrieving policies for resource owner " +
      "uuid #{ @options[ :resource_owner_uuid ] }\n" +
      "#{ policies_response.inspect }", error: true
    )
  end
end