Class: SSHKeyHub::Provider::GitLab

Inherits:
Object
  • Object
show all
Defined in:
lib/ssh_key_hub/provider/gitlab.rb

Overview

GitLab SSH public key provider

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GitLab

Returns a new instance of GitLab

Parameters:

  • options (Hash) (defaults to: {})

    GitLab credentials for Gitlab::Client

Options Hash (options):

  • :private_token (String)

    OAuth2 access token for authentication

  • :endpoint (String)

    Base URL for API requests. default: api.gitlab.com/v3



13
14
15
16
17
18
19
# File 'lib/ssh_key_hub/provider/gitlab.rb', line 13

def initialize(options = {})
  default_options = { endpoint: ENV['GITLAB_API_ENDPOINT'] || 'https://gitlab.com/api/v3' }
  @client = Gitlab.client(default_options.merge(options))
  current_user = @client.user
  @web_url = current_user.web_url.gsub(current_user.username, '')
  @is_admin = current_user.is_admin
end

Instance Method Details

#keys_for(group, project = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ssh_key_hub/provider/gitlab.rb', line 35

def keys_for(group, project = nil)
  if project.nil?
    keys_for_whole_group(group)
  else
    keys_for_group_project(group, project)
  end
end

#keys_for_group_project(group, project) ⇒ Hash

Returns Hash with keys by username with SortedSets

Parameters:

  • GitLab (String)

    project

  • group (String)

    GitLab group

Returns:

  • (Hash)

    Hash with keys by username with SortedSets



30
31
32
33
# File 'lib/ssh_key_hub/provider/gitlab.rb', line 30

def keys_for_group_project(group, project)
  users = @client.team_members "#{group}/#{project}"
  keys_for_members users
end

#keys_for_whole_group(group) ⇒ Hash

Returns Hash with keys by username with SortedSets

Parameters:

  • group (String)

    GitLab group

Returns:

  • (Hash)

    Hash with keys by username with SortedSets



23
24
25
# File 'lib/ssh_key_hub/provider/gitlab.rb', line 23

def keys_for_whole_group(group)
  keys_for_members(@client.group_members(group))
end