class Octokit::ManageGHESClient
ManageGHESClient
is only meant to be used by GitHub Enterprise Server (GHES) operators and provides access to the Manage GHES API endpoints.
@see Octokit::Client
Use Octokit::Client
for regular API use for GitHub
and GitHub Enterprise.
@see developer.github.com/v3/enterprise-admin/manage-ghes/
Client
for the Manage GitHub Enterprise Server API
Public Class Methods
# File lib/octokit/manage_ghes_client.rb, line 21 def initialize(options = {}) # Use options passed in, but fall back to module defaults # rubocop:disable Style/HashEachMethods # # This may look like a `.keys.each` which should be replaced with `#each_key`, but # this doesn't actually work, since `#keys` is just a method we've defined ourselves. # The class doesn't fulfill the whole `Enumerable` contract. Octokit::Configurable.keys.each do |key| # rubocop:enable Style/HashEachMethods instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}")) end end
Public Instance Methods
Get information about the Enterprise installation
@return [nil]
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 64 def config_status conn = authenticated_client @last_response = conn.get('/manage/v1/config/apply') end
Modify the Enterprise settings
@param settings [Hash] A hash configuration of the new settings
@return [nil]
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 84 def edit_settings(settings) conn = authenticated_client @last_response = conn.put('/manage/v1/config/settings', settings.to_json.to_s) end
Get information about the Enterprise installation
@return [nil]
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 73 def settings conn = authenticated_client @last_response = conn.get('/manage/v1/config/settings') end
Start a configuration process.
@return [nil]
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 56 def start_configuration conn = authenticated_client @last_response = conn.post('/manage/v1/config/apply') end
Uploads a license for the first time
@param license [String] The path to your .ghl license file.
@return [nil]
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 37 def upload_license(license) conn = authenticated_client begin conn.request :multipart rescue Faraday::Error raise Faraday::Error, <<~ERROR The `faraday-multipart` gem is required to upload a license. Please add `gem "faraday-multipart"` to your Gemfile. ERROR end params = {} params[:license] = Faraday::FilePart.new(license, 'binary') params[:password] = @manage_ghes_password @last_response = conn.post('/manage/v1/config/init', params, { 'Content-Type' => 'multipart/form-data' }) end
Protected Instance Methods
# File lib/octokit/manage_ghes_client.rb, line 36 def endpoint manage_ghes_endpoint end
Set Manage GHES API endpoint
@param value [String] Manage GHES API endpoint
# File lib/octokit/manage_ghes_client.rb, line 43 def manage_ghes_endpoint=(value) reset_agent @manage_ghes_endpoint = value end
Set Manage GHES API password
@param value [String] Manage GHES API password
# File lib/octokit/manage_ghes_client.rb, line 59 def manage_ghes_password=(value) reset_agent @manage_ghes_password = value end
Set Manage GHES API username
@param value [String] Manage GHES API username
# File lib/octokit/manage_ghes_client.rb, line 51 def manage_ghes_username=(value) reset_agent @manage_ghes_username = value end
Private Instance Methods
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 157 def authenticated_client @authenticated_client ||= Faraday.new(url: @manage_ghes_endpoint) do |c| c.headers[:user_agent] = user_agent c.request :json c.response :json c.adapter Faraday.default_adapter if root_site_admin_assumed? username = 'api_key' elsif basic_authenticated? username = @manage_ghes_username end c.request(*FARADAY_BASIC_AUTH_KEYS, username, @manage_ghes_password) # Disabling SSL is essential for certain self-hosted Enterprise instances c.ssl[:verify] = false if connection_options[:ssl] && !connection_options[:ssl][:verify] c.use Octokit::Response::RaiseError end end
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 148 def basic_authenticated? !!(@manage_ghes_username && @manage_ghes_password) end
If no username is provided, we assume root site admin should be used
# File lib/octokit/manage_ghes_client/manage_ghes.rb, line 153 def root_site_admin_assumed? !@manage_ghes_username end