Class: SupportOps::GitLab::SSHKeys

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

Overview

Defines the class SSHKeys 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



21
22
23
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 21

def created_at
  @created_at
end

#expires_atString

Timestamp when the SSH key should auto-remove

Returns:

  • (String)

    the current value of expires_at



21
22
23
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 21

def expires_at
  @expires_at
end

#idInteger

ID value of the key

Returns:

  • (Integer)

    the current value of id



21
22
23
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 21

def id
  @id
end

#keyString

Public key value

Returns:

  • (String)

    the current value of key



21
22
23
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 21

def key
  @key
end

#titleString

Title for key

Returns:

  • (String)

    the current value of title



21
22
23
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 21

def title
  @title
end

#usage_typeString

Usage scope for the key; possible values: auth, signing, or auth_and_signing; default value: auth_and_signing

Returns:

  • (String)

    the current value of usage_type



21
22
23
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 21

def usage_type
  @usage_type
end

Class Method Details

.list(key: value) ⇒ Array

Lists all SSH 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::SSHKeys.list(user_id: 123456)
pp keys.count
# => 3
pp keys.last.usage_type
# => "auth"

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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/support_ops_gitlab/gitlab/ssh_keys.rb', line 51

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