123456789_123456789_123456789_123456789_123456789_

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

Authentication - Included

FARADAY_BASIC_AUTH_KEYS

Connection - Included

CONVENIENCE_HEADERS

Class Method Summary

Instance Attribute Summary

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

ManageAPI - Included

#configure_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

Response for last HTTP request.

#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 #auto_paginate.

#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
#fetch_client_id_and_secret, #options

Constructor Details

.new(options = {}) ⇒ ManageGHESClient

[ GitHub ]

  
# 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

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

[ GitHub ]

  
# 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

Parameters:

  • key

    Either the file path to a key, a File handler to the key, or the contents of the key itself

[ GitHub ]

  
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 99

def add_authorized_key(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 connection_options[:ssl] && !connection_options[: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 authorized_keys
  conn = authenticated_client
  @last_response = conn.get('/manage/v1/access/ssh')
end

#config_check

Alias for #config_status.

[ GitHub ]

  
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 68

alias config_check config_status

#config_statusnil Also known as: #config_check

Get information about the Enterprise installation

[ GitHub ]

  
# 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)

[ GitHub ]

  
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 144

alias delete_authorized_key remove_authorized_key

#edit_settings(settings) ⇒ nil

Modify the Enterprise settings

Parameters:

  • settings (Hash)

    A hash configuration of the new settings

[ GitHub ]

  
# 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.

[ GitHub ]

  
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 93

alias get_authorized_keys authorized_keys

#get_settings

Alias for #settings.

[ GitHub ]

  
# 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

Parameters:

  • key

    Either the file path to a key, a File handler to the key, or the contents of the key itself

[ GitHub ]

  
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 124

def remove_authorized_key(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

#settingsnil Also known as: #get_settings

Get information about the Enterprise installation

[ GitHub ]

  
# 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_configurationnil

Start a configuration process.

[ GitHub ]

  
# 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

Parameters:

  • license (String)

    The path to your .ghl license file.

[ GitHub ]

  
# 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