Class: Artifactory::Permissions::V2::ApiClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/artifactory/permissions/v2/api_client.rb

Constant Summary collapse

HTTP_ERRORS =
[
  EOFError,
  Errno::ECONNRESET,
  Errno::EINVAL,
  Net::HTTPBadResponse,
  Net::HTTPHeaderSyntaxError,
  Net::ProtocolError,
  Timeout::Error,
]
HANDLED_ERRORS =
[SocketError] + HTTP_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, api_key:) ⇒ ApiClient

Returns a new instance of ApiClient.



25
26
27
28
# File 'lib/artifactory/permissions/v2/api_client.rb', line 25

def initialize(endpoint:, api_key:)
  @endpoint = endpoint
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



23
24
25
# File 'lib/artifactory/permissions/v2/api_client.rb', line 23

def api_key
  @api_key
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



23
24
25
# File 'lib/artifactory/permissions/v2/api_client.rb', line 23

def endpoint
  @endpoint
end

Instance Method Details

#find_permission(name:) ⇒ Object



34
35
36
# File 'lib/artifactory/permissions/v2/api_client.rb', line 34

def find_permission(name:)
  get "/api/v2/security/permissions/#{url_safe name}"
end

#get(path) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/artifactory/permissions/v2/api_client.rb', line 43

def get(path)
  response = self.class.get uri_for(path), headers: headers

  handle_response response
rescue *handled_errors => err
  raise FatalError, err.message
end

#list_permissionsObject



30
31
32
# File 'lib/artifactory/permissions/v2/api_client.rb', line 30

def list_permissions
  get "/api/v2/security/permissions"
end

#put(path, data) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/artifactory/permissions/v2/api_client.rb', line 51

def put(path, data)
  response = self.class.put uri_for(path),
                            body: data.to_json,
                            headers: headers

  handle_response response
rescue *handled_errors => err
  raise FatalError, err.message
end

#save_permission_target(permission_target) ⇒ Object



38
39
40
41
# File 'lib/artifactory/permissions/v2/api_client.rb', line 38

def save_permission_target(permission_target)
  put "/api/v2/security/permissions/#{url_safe permission_target.name}",
      permission_target.payload
end