octokit 3.8.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +78 -5
- data/lib/octokit.rb +35 -9
- data/lib/octokit/client.rb +7 -196
- data/lib/octokit/client/commit_comments.rb +2 -2
- data/lib/octokit/client/contents.rb +15 -2
- data/lib/octokit/client/hooks.rb +9 -26
- data/lib/octokit/client/issues.rb +2 -1
- data/lib/octokit/client/licenses.rb +50 -0
- data/lib/octokit/client/organizations.rb +46 -6
- data/lib/octokit/client/pub_sub_hubbub.rb +1 -8
- data/lib/octokit/client/pull_requests.rb +2 -14
- data/lib/octokit/client/users.rb +1 -1
- data/lib/octokit/configurable.rb +19 -0
- data/lib/octokit/connection.rb +196 -0
- data/lib/octokit/default.rb +14 -0
- data/lib/octokit/enterprise_admin_client.rb +36 -0
- data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
- data/lib/octokit/enterprise_admin_client/license.rb +18 -0
- data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
- data/lib/octokit/enterprise_admin_client/users.rb +53 -0
- data/lib/octokit/enterprise_management_console_client.rb +50 -0
- data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
- data/lib/octokit/middleware/follow_redirects.rb +131 -0
- data/lib/octokit/repository.rb +2 -0
- data/lib/octokit/version.rb +2 -2
- data/lib/octokit/warnable.rb +17 -0
- metadata +14 -4
- data/lib/octokit/backports/uri.rb +0 -56
data/lib/octokit/default.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'octokit/middleware/follow_redirects'
|
1
2
|
require 'octokit/response/raise_error'
|
2
3
|
require 'octokit/response/feed_parser'
|
3
4
|
require 'octokit/version'
|
@@ -24,6 +25,7 @@ module Octokit
|
|
24
25
|
|
25
26
|
# Default Faraday middleware stack
|
26
27
|
MIDDLEWARE = RACK_BUILDER_CLASS.new do |builder|
|
28
|
+
builder.use Octokit::Middleware::FollowRedirects
|
27
29
|
builder.use Octokit::Response::RaiseError
|
28
30
|
builder.use Octokit::Response::FeedParser
|
29
31
|
builder.adapter Faraday.default_adapter
|
@@ -67,6 +69,18 @@ module Octokit
|
|
67
69
|
ENV['OCTOKIT_SECRET']
|
68
70
|
end
|
69
71
|
|
72
|
+
# Default management console password from ENV
|
73
|
+
# @return [String]
|
74
|
+
def management_console_password
|
75
|
+
ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD']
|
76
|
+
end
|
77
|
+
|
78
|
+
# Default management console endpoint from ENV
|
79
|
+
# @return [String]
|
80
|
+
def management_console_endpoint
|
81
|
+
ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT']
|
82
|
+
end
|
83
|
+
|
70
84
|
# Default options for Faraday::Connection
|
71
85
|
# @return [Hash]
|
72
86
|
def connection_options
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'octokit/connection'
|
2
|
+
require 'octokit/configurable'
|
3
|
+
require 'octokit/warnable'
|
4
|
+
require 'octokit/enterprise_admin_client/admin_stats'
|
5
|
+
require 'octokit/enterprise_admin_client/license'
|
6
|
+
require 'octokit/enterprise_admin_client/search_indexing'
|
7
|
+
require 'octokit/enterprise_admin_client/users'
|
8
|
+
|
9
|
+
module Octokit
|
10
|
+
|
11
|
+
# EnterpriseAdminClient is only meant to be used by GitHub Enterprise Admins
|
12
|
+
# and provides access the Admin only API endpoints including Admin Stats,
|
13
|
+
# Management Console, and the Search Indexing API.
|
14
|
+
#
|
15
|
+
# @see Octokit::Client Use Octokit::Client for regular API use for GitHub
|
16
|
+
# and GitHub Enterprise.
|
17
|
+
# @see https://developer.github.com/v3/enterprise/
|
18
|
+
class EnterpriseAdminClient
|
19
|
+
|
20
|
+
include Octokit::Configurable
|
21
|
+
include Octokit::Connection
|
22
|
+
include Octokit::Warnable
|
23
|
+
include Octokit::EnterpriseAdminClient::AdminStats
|
24
|
+
include Octokit::EnterpriseAdminClient::License
|
25
|
+
include Octokit::EnterpriseAdminClient::SearchIndexing
|
26
|
+
include Octokit::EnterpriseAdminClient::Users
|
27
|
+
|
28
|
+
def initialize(options = {})
|
29
|
+
# Use options passed in, but fall back to module defaults
|
30
|
+
Octokit::Configurable.keys.each do |key|
|
31
|
+
instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module Octokit
|
2
|
+
class EnterpriseAdminClient
|
3
|
+
|
4
|
+
# Methods for the Enterprise Admin Stats API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/enterprise/admin_stats/
|
7
|
+
module AdminStats
|
8
|
+
|
9
|
+
# Get all available stats
|
10
|
+
#
|
11
|
+
# @return [Sawyer::Resource] All available stats
|
12
|
+
# @example Get all available stats
|
13
|
+
# @client.admin_stats
|
14
|
+
def admin_stats
|
15
|
+
get_admin_stats "all"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get only repository-related stats
|
19
|
+
#
|
20
|
+
# @return [Sawyer::Resource] Only repository-related stats
|
21
|
+
# @example Get only repository-related stats
|
22
|
+
# @client.admin_repository_stats
|
23
|
+
def admin_repository_stats
|
24
|
+
get_admin_stats "repos"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Get only hooks-related stats
|
28
|
+
#
|
29
|
+
# @return [Sawyer::Resource] Only hooks-related stats
|
30
|
+
# @example Get only hooks-related stats
|
31
|
+
# @client.admin_hooks_stats
|
32
|
+
def admin_hooks_stats
|
33
|
+
get_admin_stats "hooks"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Get only pages-related stats
|
37
|
+
#
|
38
|
+
# @return [Sawyer::Resource] Only pages-related stats
|
39
|
+
# @example Get only pages-related stats
|
40
|
+
# @client.admin_pages_stats
|
41
|
+
def admin_pages_stats
|
42
|
+
get_admin_stats "pages"
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get only organization-related stats
|
46
|
+
#
|
47
|
+
# @return [Sawyer::Resource] Only organization-related stats
|
48
|
+
# @example Get only organization-related stats
|
49
|
+
# @client.admin_organization_stats
|
50
|
+
def admin_organization_stats
|
51
|
+
get_admin_stats "orgs"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get only user-related stats
|
55
|
+
#
|
56
|
+
# @return [Sawyer::Resource] Only user-related stats
|
57
|
+
# @example Get only user-related stats
|
58
|
+
# @client.admin_users_stats
|
59
|
+
def admin_users_stats
|
60
|
+
get_admin_stats "users"
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get only pull request-related stats
|
64
|
+
#
|
65
|
+
# @return [Sawyer::Resource] Only pull request-related stats
|
66
|
+
# @example Get only pull request-related stats
|
67
|
+
# @client.admin_pull_requests_stats
|
68
|
+
def admin_pull_requests_stats
|
69
|
+
get_admin_stats "pulls"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Get only issue-related stats
|
73
|
+
#
|
74
|
+
# @return [Sawyer::Resource] Only issue-related stats
|
75
|
+
# @example Get only issue-related stats
|
76
|
+
# @client.admin_issues_stats
|
77
|
+
def admin_issues_stats
|
78
|
+
get_admin_stats "issues"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Get only milestone-related stats
|
82
|
+
#
|
83
|
+
# @return [Sawyer::Resource] Only milestone-related stats
|
84
|
+
# @example Get only milestone-related stats
|
85
|
+
# @client.admin_milestones_stats
|
86
|
+
def admin_milestones_stats
|
87
|
+
get_admin_stats "milestones"
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get only gist-related stats
|
91
|
+
#
|
92
|
+
# @return [Sawyer::Resource] Only only gist-related stats
|
93
|
+
# @example Get only gist-related stats
|
94
|
+
# @client.admin_gits_stats
|
95
|
+
def admin_gists_stats
|
96
|
+
get_admin_stats "gists"
|
97
|
+
end
|
98
|
+
|
99
|
+
# Get only comment-related stats
|
100
|
+
#
|
101
|
+
# @return [Sawyer::Resource] Only comment-related stats
|
102
|
+
# @example Get only comment-related stats
|
103
|
+
# @client.admin_comments_stats
|
104
|
+
def admin_comments_stats
|
105
|
+
get_admin_stats "comments"
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
# @private Get enterprise stats
|
111
|
+
#
|
112
|
+
# @param metric [String] The metrics you are looking for
|
113
|
+
# @return [Sawyer::Resource] Magical unicorn stats
|
114
|
+
def get_admin_stats(metric)
|
115
|
+
get "enterprise/stats/#{metric}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Octokit
|
2
|
+
class EnterpriseAdminClient
|
3
|
+
|
4
|
+
# Methods for the Enterprise License API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/enterprise/license/
|
7
|
+
module License
|
8
|
+
|
9
|
+
# Get information about the Enterprise license
|
10
|
+
#
|
11
|
+
# @return [Sawyer::Resource] The license information
|
12
|
+
def license_info
|
13
|
+
get "enterprise/settings/license"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Octokit
|
2
|
+
class EnterpriseAdminClient
|
3
|
+
|
4
|
+
# Methods for the Enterprise Search Indexing API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/enterprise/search_indexing/
|
7
|
+
module SearchIndexing
|
8
|
+
|
9
|
+
# Queue a User or Organization to be indexed
|
10
|
+
#
|
11
|
+
# @param user [String] A GitHub Enterprise user or organization
|
12
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
13
|
+
def index_user(user)
|
14
|
+
queue_index user
|
15
|
+
end
|
16
|
+
alias :index_organization :index_user
|
17
|
+
|
18
|
+
# Queue a Repository to be indexed
|
19
|
+
#
|
20
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
21
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
22
|
+
def index_repository(repo)
|
23
|
+
queue_index Repository.new repo
|
24
|
+
end
|
25
|
+
|
26
|
+
# Queue a repository's Issues to be indexed
|
27
|
+
#
|
28
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
29
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
30
|
+
def index_repository_issues(repo)
|
31
|
+
queue_index "#{Repository.new repo}/issues"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Queue a repository's code to be indexed
|
35
|
+
#
|
36
|
+
# @param repo [String, Hash, Repository] A GitHub repository
|
37
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
38
|
+
def index_repository_code(repo)
|
39
|
+
queue_index "#{Repository.new repo}/code"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Queue a user's or organization's repositories to be indexed
|
43
|
+
#
|
44
|
+
# @param user [String] A GitHub Enterprise user or organization
|
45
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
46
|
+
def index_users_repositories(user)
|
47
|
+
queue_index "#{user}/*"
|
48
|
+
end
|
49
|
+
alias :index_organizations_repositories :index_users_repositories
|
50
|
+
|
51
|
+
# Queue an index of all the issues across all of a user's or
|
52
|
+
# organization's repositories
|
53
|
+
#
|
54
|
+
# @param user [String] A GitHub Enterprise user or organization
|
55
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
56
|
+
def index_users_repositories_issues(user)
|
57
|
+
queue_index "#{user}/*/issues"
|
58
|
+
end
|
59
|
+
alias :index_organizations_repositories_issues :index_users_repositories_issues
|
60
|
+
|
61
|
+
# Queue an index of all the code contained in all of a user's or
|
62
|
+
# organization's repositories
|
63
|
+
#
|
64
|
+
# @param user [String] A GitHub Enterprise user or organization
|
65
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
66
|
+
def index_users_repositories_code(user)
|
67
|
+
queue_index "#{user}/*/code"
|
68
|
+
end
|
69
|
+
alias :index_organizations_repositories_code :index_users_repositories_code
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
# @private Queue a target for indexing
|
74
|
+
#
|
75
|
+
# @param target [String] Target to index
|
76
|
+
# @return [Sawyer:Resource] Result of the queuing containing `:message`
|
77
|
+
def queue_index(target)
|
78
|
+
post "staff/indexing_jobs", :target => target
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Octokit
|
2
|
+
class EnterpriseAdminClient
|
3
|
+
|
4
|
+
# Methods for the Enterprise User Administration API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/users/administration/
|
7
|
+
module Users
|
8
|
+
# Promote an ordinary user to a site administrator
|
9
|
+
#
|
10
|
+
# @param user [String] Username of the user to promote.
|
11
|
+
# @return [Boolean] True if promote was successful, false otherwise.
|
12
|
+
# @see https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
|
13
|
+
# @example
|
14
|
+
# @admin_client.promote('holman')
|
15
|
+
def promote(user, options = {})
|
16
|
+
boolean_from_response :put, "users/#{user}/site_admin", options
|
17
|
+
end
|
18
|
+
|
19
|
+
# Demote a site administrator to an ordinary user
|
20
|
+
#
|
21
|
+
# @param user [String] Username of the user to demote.
|
22
|
+
# @return [Boolean] True if demote was successful, false otherwise.
|
23
|
+
# @see https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
|
24
|
+
# @example
|
25
|
+
# @admin_client.demote('holman')
|
26
|
+
def demote(user, options = {})
|
27
|
+
boolean_from_response :delete, "users/#{user}/site_admin", options
|
28
|
+
end
|
29
|
+
|
30
|
+
# Suspend a user.
|
31
|
+
#
|
32
|
+
# @param user [String] Username of the user to suspend.
|
33
|
+
# @return [Boolean] True if suspend was successful, false otherwise.
|
34
|
+
# @see https://developer.github.com/v3/users/administration/#suspend-a-user
|
35
|
+
# @example
|
36
|
+
# @admin_client.suspend('holman')
|
37
|
+
def suspend(user, options = {})
|
38
|
+
boolean_from_response :put, "users/#{user}/suspended", options
|
39
|
+
end
|
40
|
+
|
41
|
+
# Unsuspend a user.
|
42
|
+
#
|
43
|
+
# @param user [String] Username of the user to unsuspend.
|
44
|
+
# @return [Boolean] True if unsuspend was successful, false otherwise.
|
45
|
+
# @see https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
46
|
+
# @example
|
47
|
+
# @admin_client.unsuspend('holman')
|
48
|
+
def unsuspend(user, options = {})
|
49
|
+
boolean_from_response :delete, "users/#{user}/suspended", options
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'octokit/configurable'
|
2
|
+
require 'octokit/connection'
|
3
|
+
require 'octokit/warnable'
|
4
|
+
require 'octokit/enterprise_management_console_client/management_console'
|
5
|
+
|
6
|
+
module Octokit
|
7
|
+
|
8
|
+
# EnterpriseManagementConsoleClient is only meant to be used by GitHub Enterprise Admins
|
9
|
+
# and provides access to the management console API endpoints.
|
10
|
+
#
|
11
|
+
# @see Octokit::Client Use Octokit::Client for regular API use for GitHub
|
12
|
+
# and GitHub Enterprise.
|
13
|
+
# @see https://developer.github.com/v3/enterprise/management_console/
|
14
|
+
class EnterpriseManagementConsoleClient
|
15
|
+
|
16
|
+
include Octokit::Configurable
|
17
|
+
include Octokit::Connection
|
18
|
+
include Octokit::Warnable
|
19
|
+
include Octokit::EnterpriseManagementConsoleClient::ManagementConsole
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
# Use options passed in, but fall back to module defaults
|
23
|
+
Octokit::Configurable.keys.each do |key|
|
24
|
+
instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}"))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def endpoint
|
31
|
+
management_console_endpoint
|
32
|
+
end
|
33
|
+
|
34
|
+
# Set Enterprise Management Console password
|
35
|
+
#
|
36
|
+
# @param value [String] Management console admin password
|
37
|
+
def management_console_password=(value)
|
38
|
+
reset_agent
|
39
|
+
@management_console_password = value
|
40
|
+
end
|
41
|
+
|
42
|
+
# Set Enterprise Management Console endpoint
|
43
|
+
#
|
44
|
+
# @param value [String] Management console endpoint
|
45
|
+
def management_console_endpoint=(value)
|
46
|
+
reset_agent
|
47
|
+
@management_console_endpoint = value
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
module Octokit
|
2
|
+
class EnterpriseManagementConsoleClient
|
3
|
+
|
4
|
+
# Methods for the Enterprise Management Console API
|
5
|
+
#
|
6
|
+
# @see https://developer.github.com/v3/enterprise/management_console
|
7
|
+
module ManagementConsole
|
8
|
+
|
9
|
+
# Uploads a license for the first time
|
10
|
+
#
|
11
|
+
# @param license [String] The path to your .ghl license file.
|
12
|
+
# @param settings [Hash] A hash configuration of the initial settings.
|
13
|
+
#
|
14
|
+
# @see http: //git.io/j5NT
|
15
|
+
# @return nil
|
16
|
+
def upload_license(license, settings = nil)
|
17
|
+
conn = faraday_configuration
|
18
|
+
|
19
|
+
params = { }
|
20
|
+
params[:license] = Faraday::UploadIO.new(license, 'binary')
|
21
|
+
params[:password] = @management_console_password
|
22
|
+
params[:settings] = "#{settings.to_json}" unless settings.nil?
|
23
|
+
|
24
|
+
@last_response = conn.post("/setup/api/start", params)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Start a configuration process.
|
28
|
+
#
|
29
|
+
# @return nil
|
30
|
+
def start_configuration
|
31
|
+
post "/setup/api/configure", password_hash
|
32
|
+
end
|
33
|
+
|
34
|
+
# Upgrade an Enterprise installation
|
35
|
+
#
|
36
|
+
# @param license [String] The path to your .ghl license file.
|
37
|
+
#
|
38
|
+
# @return nil
|
39
|
+
def upgrade(license)
|
40
|
+
conn = faraday_configuration
|
41
|
+
|
42
|
+
params = { }
|
43
|
+
params[:license] = Faraday::UploadIO.new(license, 'binary')
|
44
|
+
params[:api_key] = @management_console_password
|
45
|
+
@last_response = conn.post("/setup/api/upgrade", params)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Get information about the Enterprise installation
|
49
|
+
#
|
50
|
+
# @return [Sawyer::Resource] The installation information
|
51
|
+
def config_status
|
52
|
+
get "/setup/api/configcheck", password_hash
|
53
|
+
end
|
54
|
+
alias :config_check :config_status
|
55
|
+
|
56
|
+
# Get information about the Enterprise installation
|
57
|
+
#
|
58
|
+
# @return [Sawyer::Resource] The settings
|
59
|
+
def settings
|
60
|
+
get "/setup/api/settings", password_hash
|
61
|
+
end
|
62
|
+
alias :get_settings :settings
|
63
|
+
|
64
|
+
# Modify the Enterprise settings
|
65
|
+
#
|
66
|
+
# @param settings [Hash] A hash configuration of the new settings
|
67
|
+
#
|
68
|
+
# @return [nil]
|
69
|
+
def edit_settings(settings)
|
70
|
+
queries = password_hash
|
71
|
+
queries[:query][:settings] = "#{settings.to_json}"
|
72
|
+
put "/setup/api/settings", queries
|
73
|
+
end
|
74
|
+
|
75
|
+
# Get information about the Enterprise maintenance status
|
76
|
+
#
|
77
|
+
# @return [Sawyer::Resource] The maintenance status
|
78
|
+
def maintenance_status
|
79
|
+
get "/setup/api/maintenance", password_hash
|
80
|
+
end
|
81
|
+
alias :get_maintenance_status :maintenance_status
|
82
|
+
|
83
|
+
# Start (or turn off) the Enterprise maintenance mode
|
84
|
+
#
|
85
|
+
# @param maintenance [Hash] A hash configuration of the maintenance settings
|
86
|
+
# @return [nil]
|
87
|
+
def set_maintenance_status(maintenance)
|
88
|
+
queries = password_hash
|
89
|
+
queries[:query][:maintenance] = "#{maintenance.to_json}"
|
90
|
+
post "/setup/api/maintenance", queries
|
91
|
+
end
|
92
|
+
alias :edit_maintenance_status :set_maintenance_status
|
93
|
+
|
94
|
+
# Fetch the authorized SSH keys on the Enterprise install
|
95
|
+
#
|
96
|
+
# @return [Sawyer::Resource] An array of authorized SSH keys
|
97
|
+
def authorized_keys
|
98
|
+
get "/setup/api/settings/authorized-keys", password_hash
|
99
|
+
end
|
100
|
+
alias :get_authorized_keys :authorized_keys
|
101
|
+
|
102
|
+
# Add an authorized SSH keys on the Enterprise install
|
103
|
+
#
|
104
|
+
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
|
105
|
+
# @return [Sawyer::Resource] An array of authorized SSH keys
|
106
|
+
def add_authorized_key(key)
|
107
|
+
queries = password_hash
|
108
|
+
case key
|
109
|
+
when String
|
110
|
+
if File.exist?(key)
|
111
|
+
key = File.open(key, "r")
|
112
|
+
content = key.read.strip
|
113
|
+
key.close
|
114
|
+
else
|
115
|
+
content = key
|
116
|
+
end
|
117
|
+
when File
|
118
|
+
content = key.read.strip
|
119
|
+
key.close
|
120
|
+
end
|
121
|
+
|
122
|
+
queries[:query][:authorized_key] = content
|
123
|
+
post "/setup/api/settings/authorized-keys", queries
|
124
|
+
end
|
125
|
+
|
126
|
+
# Removes an authorized SSH keys from the Enterprise install
|
127
|
+
#
|
128
|
+
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
|
129
|
+
# @return [Sawyer::Resource] An array of authorized SSH keys
|
130
|
+
def remove_authorized_key(key)
|
131
|
+
queries = password_hash
|
132
|
+
case key
|
133
|
+
when String
|
134
|
+
if File.exist?(key)
|
135
|
+
key = File.open(key, "r")
|
136
|
+
content = key.read.strip
|
137
|
+
key.close
|
138
|
+
else
|
139
|
+
content = key
|
140
|
+
end
|
141
|
+
when File
|
142
|
+
content = key.read.strip
|
143
|
+
key.close
|
144
|
+
end
|
145
|
+
|
146
|
+
queries[:query][:authorized_key] = content
|
147
|
+
delete "/setup/api/settings/authorized-keys", queries
|
148
|
+
end
|
149
|
+
alias :delete_authorized_key :remove_authorized_key
|
150
|
+
|
151
|
+
end
|
152
|
+
private
|
153
|
+
|
154
|
+
def password_hash
|
155
|
+
{ :query => { :api_key => @management_console_password } }
|
156
|
+
end
|
157
|
+
|
158
|
+
# We fall back to raw Faraday for handling the licenses because I'm suspicious
|
159
|
+
# that Sawyer isn't handling binary POSTs correctly: http://git.io/jMir
|
160
|
+
def faraday_configuration
|
161
|
+
@faraday_configuration ||= Faraday.new(:url => @management_console_endpoint) do |http|
|
162
|
+
http.headers[:user_agent] = user_agent
|
163
|
+
http.request :multipart
|
164
|
+
http.request :url_encoded
|
165
|
+
|
166
|
+
# Disabling SSL is essential for certain self-hosted Enterprise instances
|
167
|
+
if self.connection_options[:ssl] && !self.connection_options[:ssl][:verify]
|
168
|
+
http.ssl[:verify] = false
|
169
|
+
end
|
170
|
+
|
171
|
+
http.use Octokit::Response::RaiseError
|
172
|
+
http.adapter Faraday.default_adapter
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|