Class: Gitlab::BeyondIdentity::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/beyond_identity/client.rb

Defined Under Namespace

Classes: ApiError

Constant Summary collapse

API_URL =
"https://api.byndid.com/key-mgmt/v0/gpg/key/authorization/git-commit-signing"
Error =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(integration) ⇒ Client

Returns a new instance of Client.

Raises:



31
32
33
34
35
# File 'lib/gitlab/beyond_identity/client.rb', line 31

def initialize(integration)
  raise Error, 'integration is not activated' unless integration.activated?

  @integration = integration
end

Instance Attribute Details

#integrationObject (readonly)

Returns the value of attribute integration.



29
30
31
# File 'lib/gitlab/beyond_identity/client.rb', line 29

def integration
  @integration
end

Instance Method Details

#execute(params) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/beyond_identity/client.rb', line 37

def execute(params)
  options = { headers: headers, query: params }
  response = Gitlab::HTTP.get(API_URL, options)
  body = Gitlab::Json.parse(response.body) || {}

  raise ApiError.new(body.dig('error', 'message'), response.code) unless response.success?
  raise ApiError.new(body['message'], response.code) unless body['authorized']

  body
rescue JSON::ParserError
  raise ApiError.new('invalid response format', response.code)
end