Class: UnimatrixCLI::Keymaker::ResourceOwner::RemoveCommand
- Defined in:
- lib/unimatrix_cli/keymaker/resource_owner/remove_command.rb
Instance Method Summary collapse
Methods inherited from Command
available_commands, descendants, #initialize, #read_file, #validate, #validate_collection, #write
Methods included from UnimatrixParser
Constructor Details
This class inherits a constructor from UnimatrixCLI::Command
Instance Method Details
#execute ⇒ Object
14 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/unimatrix_cli/keymaker/resource_owner/remove_command.rb', line 14 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? destroyed_count = 0 scoped_policies.each do | policy | body = { policy: { resource: policy[ 'resource' ] } } delete_response = make_request( endpoint, 'Delete', body ) if delete_response.empty? destroyed_count += 1 else write( message: "\n**Error removing policy**\n" + "Realm UUID: #{ policy[ 'realm_uuid' ] }\n" + "Resource: #{ policy[ 'resource' ] }\n" + "Error: #{ delete_response.inspect }\n\n", error: true ) end end if destroyed_count == scoped_policies.length write( message: "Successfully removed resource owner #{ @options[ :resource_owner_uuid ] } " + "from realm #{ @options[ :realm ] }" ) else write( message: "Error: unable to completely remove resource owner from realm " + "#{ @options[ :realm ] }, #{ destroyed_count } out of #{ scoped_policies.length } " + "policies were removed", error: true ) 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 |