class Octokit::ManageGHESClient

@see developer.github.com/v3/enterprise-admin/manage-ghes/
and GitHub Enterprise.
@see Octokit::Client Use Octokit::Client for regular API use for GitHub
and provides access to the Manage GHES API endpoints.
ManageGHESClient is only meant to be used by GitHub Enterprise Server (GHES) operators

def add_authorized_key(key)

Returns:
  • (nil) -

Parameters:
  • key () -- Either the file path to a key, a File handler to the key, or the contents of the key itself
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

def authenticated_client

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

def authorized_keys

def authorized_keys
  conn = authenticated_client
  @last_response = conn.get('/manage/v1/access/ssh')
end

def basic_authenticated?

def basic_authenticated?
  !!(@manage_ghes_username && @manage_ghes_password)
end

def config_status

Returns:
  • (nil) -
def config_status
  conn = authenticated_client
  @last_response = conn.get('/manage/v1/config/apply')
end

def edit_settings(settings)

Returns:
  • (nil) -

Parameters:
  • settings (Hash) -- A hash configuration of the new settings
def edit_settings(settings)
  conn = authenticated_client
  @last_response = conn.put('/manage/v1/config/settings', settings.to_json.to_s)
end

def endpoint

def endpoint
  manage_ghes_endpoint
end

def initialize(options = {})

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

def manage_ghes_endpoint=(value)

Parameters:
  • value (String) -- Manage GHES API endpoint
def manage_ghes_endpoint=(value)
  reset_agent
  @manage_ghes_endpoint = value
end

def manage_ghes_password=(value)

Parameters:
  • value (String) -- Manage GHES API password
def manage_ghes_password=(value)
  reset_agent
  @manage_ghes_password = value
end

def manage_ghes_username=(value)

Parameters:
  • value (String) -- Manage GHES API username
def manage_ghes_username=(value)
  reset_agent
  @manage_ghes_username = value
end

def remove_authorized_key(key)

Returns:
  • (nil) -

Parameters:
  • key () -- Either the file path to a key, a File handler to the key, or the contents of the key itself
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

def root_site_admin_assumed?

If no username is provided, we assume root site admin should be used
def root_site_admin_assumed?
  !@manage_ghes_username
end

def settings

Returns:
  • (nil) -
def settings
  conn = authenticated_client
  @last_response = conn.get('/manage/v1/config/settings')
end

def start_configuration

Returns:
  • (nil) -
def start_configuration
  conn = authenticated_client
  @last_response = conn.post('/manage/v1/config/apply')
end

def upload_license(license)

Returns:
  • (nil) -

Parameters:
  • license (String) -- The path to your .ghl license file.
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