Class: Octokit::ManageGHESClient
| Relationships & Source Files | |
| Namespace Children | |
|
Modules:
| |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | lib/octokit/manage_ghes_client.rb, lib/octokit/manage_ghes_client/manage_ghes.rb |
Overview
ManageGHESClient is only meant to be used by GitHub Enterprise Server (GHES) operators
and provides access to the Manage GHES API endpoints.
Constant Summary
Class Method Summary
- .new(options = {}) ⇒ ManageGHESClient constructor
Instance Attribute Summary
- #basic_authenticated? ⇒ Boolean readonly private
-
#root_site_admin_assumed? ⇒ Boolean
readonly
private
If no username is provided, we assume root site admin should be used.
Authentication - Included
| #application_authenticated? | Indicates if the client has OAuth Application client_id and secret credentials to make anonymous requests at a higher rate limit. |
| #basic_authenticated? | Indicates if the client was supplied Basic Auth username and password. |
| #bearer_authenticated? | Indicates if the client was supplied a bearer token. |
| #token_authenticated? | Indicates if the client was supplied an OAuth access token. |
| #user_authenticated? | Indicates if the client was supplied an OAuth access token or Basic Auth username and password. |
Configurable - Included
Instance Method Summary
-
#add_authorized_key(key) ⇒ nil
Add an authorized SSH keys on the Enterprise install.
- #authorized_keys (also: #get_authorized_keys)
-
#config_check
Alias for #config_status.
-
#config_status ⇒ nil
(also: #config_check)
Get information about the Enterprise installation.
-
#delete_authorized_key(key)
Alias for #remove_authorized_key.
-
#edit_settings(settings) ⇒ nil
Modify the Enterprise settings.
-
#get_authorized_keys
Alias for #authorized_keys.
-
#get_settings
Alias for #settings.
-
#remove_authorized_key(key) ⇒ nil
(also: #delete_authorized_key)
Removes an authorized SSH keys from the Enterprise install.
-
#settings ⇒ nil
(also: #get_settings)
Get information about the Enterprise installation.
-
#start_configuration ⇒ nil
Start a configuration process.
-
#upload_license(license) ⇒ nil
Uploads a license for the first time.
- #authenticated_client private
ManageAPI - Included
| #configure_maintenance_mode | Alias for ManageAPI#set_maintenance_mode. |
| #maintenance_mode | Get information about the maintenance status of the GHES instance. |
| #set_maintenance_mode | Configure the maintenance mode of the GHES instance. |
Warnable - Included
| #octokit_warn | Wrapper around Kernel#warn to print warnings unless OCTOKIT_SILENT is set to true. |
Connection - Included
| #agent | Hypermedia agent for the GitHub API. |
| #delete | Make a HTTP DELETE request. |
| #get | Make a HTTP GET request. |
| #head | Make a HTTP HEAD request. |
| #last_response |
|
| #paginate | Make one or more HTTP GET requests, optionally fetching the next page of results from URL in Link response header based on value in |
| #patch | Make a HTTP PATCH request. |
| #post | Make a HTTP POST request. |
| #put | Make a HTTP PUT request. |
| #root | Fetch the root resource for the API. |
| #boolean_from_response | Executes the request, checking if it was successful. |
| #parse_query_and_convenience_headers, #request, #reset_agent, #response_data_correctly_encoded, #sawyer_options | |
Authentication - Included
Configurable - Included
| #configure | Set configuration options using a block. |
| #reset! | Reset configuration options to default values. |
| #same_options? | Compares client options to a Hash of requested options. |
| #setup | Alias for Configurable#reset!. |
| #fetch_client_id_and_secret, #options | |
Constructor Details
.new(options = {}) ⇒ ManageGHESClient
# File 'lib/octokit/manage_ghes_client.rb', line 21
def initialize( = {}) # 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}", [key] || Octokit.instance_variable_get(:"@#{key}")) end end
Instance Attribute Details
#basic_authenticated? ⇒ Boolean (readonly, private)
[ GitHub ]
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 148
def basic_authenticated? !!(@manage_ghes_username && @manage_ghes_password) end
#root_site_admin_assumed? ⇒ Boolean (readonly, private)
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
Instance Method Details
#add_authorized_key(key) ⇒ nil
Add an authorized SSH keys on the Enterprise install
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 99
def (key) conn = authenticated_client case key when String if File.exist?(key) key = File.open(key, 'r') content = key.read.strip key.close else content = key end when File content = key.read.strip key.close end queries = {} queries[:key] = content @last_response = conn.post('/manage/v1/access/ssh', queries) end
#authenticated_client (private)
[ GitHub ]# 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 [:ssl] && ![:ssl][:verify] c.use Octokit::Response::RaiseError end end
#authorized_keys Also known as: #get_authorized_keys
[ GitHub ]# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 89
def conn = authenticated_client @last_response = conn.get('/manage/v1/access/ssh') end
#config_check
Alias for #config_status.
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 68
alias config_check config_status
#config_status ⇒ nil
Also known as: #config_check
Get information about the Enterprise installation
# 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
#delete_authorized_key(key)
Alias for #remove_authorized_key.
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 144
alias
#edit_settings(settings) ⇒ nil
Modify the Enterprise settings
# 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_authorized_keys
Alias for #authorized_keys.
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 93
alias
#get_settings
Alias for #settings.
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 77
alias get_settings settings
#remove_authorized_key(key) ⇒ nil
Also known as: #delete_authorized_key
Removes an authorized SSH keys from the Enterprise install
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 124
def (key) conn = authenticated_client case key when String if File.exist?(key) key = File.open(key, 'r') content = key.read.strip key.close else content = key end when File content = key.read.strip key.close end queries = {} queries[:key] = content @last_response = conn.run_request(:delete, '/manage/v1/access/ssh', queries, nil) end
#settings ⇒ nil
Also known as: #get_settings
Get information about the Enterprise installation
# 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_configuration ⇒ nil
Start a configuration process.
# 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
#upload_license(license) ⇒ nil
Uploads a license for the first time
# 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