Class: SSHKeyHub::Provider::GitHub
- Inherits:
-
Object
- Object
- SSHKeyHub::Provider::GitHub
- Defined in:
- lib/ssh_key_hub/provider/github.rb
Overview
GitHub SSH public key provider
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GitHub
constructor
A new instance of GitHub.
-
#keys_for(organization, team = nil) ⇒ Hash
Hash with keys by username with SortedSets.
-
#keys_for_org_team(organization, team) ⇒ Hash
Hash with keys by username with SortedSets.
-
#keys_for_whole_org(organization) ⇒ Hash
Hash with keys by username with SortedSets.
Constructor Details
#initialize(options = {}) ⇒ GitHub
Returns a new instance of GitHub
13 14 15 16 17 |
# File 'lib/ssh_key_hub/provider/github.rb', line 13 def initialize( = {}) = { auto_paginate: true } .merge(access_token: ENV['OCTOKIT_ACCESS_TOKEN']) unless ENV['OCTOKIT_ACCESS_TOKEN'].nil? @client = Octokit::Client.new(.merge()) end |
Instance Method Details
#keys_for(organization, team = nil) ⇒ Hash
Returns Hash with keys by username with SortedSets
38 39 40 41 42 43 44 |
# File 'lib/ssh_key_hub/provider/github.rb', line 38 def keys_for(organization, team = nil) if team.nil? keys_for_whole_org(organization) else keys_for_org_team(organization, team) end end |
#keys_for_org_team(organization, team) ⇒ Hash
Returns Hash with keys by username with SortedSets
28 29 30 31 32 33 |
# File 'lib/ssh_key_hub/provider/github.rb', line 28 def keys_for_org_team(organization, team) teams = @client.org_teams(organization).select { |t| t.name == team } raise 'Incorrect team' unless teams.size == 1 team_id = teams.first.id keys_for_members(@client.team_members(team_id)) end |
#keys_for_whole_org(organization) ⇒ Hash
Returns Hash with keys by username with SortedSets
21 22 23 |
# File 'lib/ssh_key_hub/provider/github.rb', line 21 def keys_for_whole_org(organization) keys_for_members(@client.org_members(organization)) end |