Class: SupportOps::GitLab::GPGKeys

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/gpg_keys.rb

Overview

TODO:

Defines the class GPGKeys within the module SupportOps::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #delete!, #diffs, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #revoke!, #rotate!, #save!, #ssh_keys, #status, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks

Constructor Details

This class inherits a constructor from SupportOps::GitLab::Base

Instance Attribute Details

#created_atString

Timestamp for when the key was created

Returns:

  • (String)

    the current value of created_at



18
19
20
# File 'lib/support_ops_gitlab/gitlab/gpg_keys.rb', line 18

def created_at
  @created_at
end

#idInteger

ID value of the key

Returns:

  • (Integer)

    the current value of id



18
19
20
# File 'lib/support_ops_gitlab/gitlab/gpg_keys.rb', line 18

def id
  @id
end

#keyString

Public key value

Returns:

  • (String)

    the current value of key



18
19
20
# File 'lib/support_ops_gitlab/gitlab/gpg_keys.rb', line 18

def key
  @key
end

Class Method Details

.list(key: value) ⇒ Array

Lists all GPG keys for a user

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.example.com/api/v4'
  config.token = 'abc123'
end

keys = SupportOps::GitLab::GPGKeys.list(user_id: 123456)
pp keys.count
# => 3
pp keys.last.id
# => 789

Parameters:

  • user_id (Integer optional)

    The user ID to get SSH keys of (not including this does it for the current user)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/support_ops_gitlab/gitlab/gpg_keys.rb', line 48

def self.list(**args)
  args[:user_id] = nil unless args[:user_id]
  url = if args[:user_id].nil?
          'user/gpg_keys'
        else
          "users/#{args[:user_id]}/gpg_keys"
        end
  response = client.connection.get(url)
  body = Oj.load(response.body)
  raise "Unable to get GPG keys of user => #{body}" if response.status != 200
  body.map { |g| GPGKeys.new(g) }
end