Class: Octokit::ManageGHESClient

Inherits:
Object
  • Object
show all
Includes:
Configurable, Connection, ManageAPI, Warnable
Defined in:
lib/octokit/manage_ghes_client.rb,
lib/octokit/manage_ghes_client/manage_ghes.rb

Overview

Client for the Manage GitHub Enterprise Server API

Defined Under Namespace

Modules: ManageAPI

Constant Summary

Constants included from Connection

Connection::CONVENIENCE_HEADERS

Constants included from Authentication

Authentication::FARADAY_BASIC_AUTH_KEYS

Instance Attribute Summary

Attributes included from Configurable

#access_token, #api_endpoint, #auto_paginate, #bearer_token, #client_id, #client_secret, #connection_options, #default_media_type, #login, #manage_ghes_endpoint, #manage_ghes_password, #manage_ghes_username, #management_console_endpoint, #management_console_password, #middleware, #netrc, #netrc_file, #password, #per_page, #proxy, #ssl_verify_mode, #user_agent, #web_endpoint

Instance Method Summary collapse

Methods included from ManageAPI

#maintenance_mode, #set_maintenance_mode

Methods included from Warnable

octokit_warn

Methods included from Connection

#agent, #delete, #get, #head, #last_response, #paginate, #patch, #post, #put, #root

Methods included from Authentication

#application_authenticated?, #bearer_authenticated?, #token_authenticated?, #user_authenticated?

Methods included from Configurable

#configure, keys, #netrc?, #reset!, #same_options?

Constructor Details

#initialize(options = {}) ⇒ ManageGHESClient

Returns a new instance of ManageGHESClient.



21
22
23
24
25
26
27
28
29
30
31
32
# 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 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

Returns:

  • (nil)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# 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

#authorized_keysObject Also known as: get_authorized_keys



89
90
91
92
# 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_statusnil Also known as: config_check

Get information about the Enterprise installation

Returns:

  • (nil)


64
65
66
67
# 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

#edit_settings(settings) ⇒ nil

Modify the Enterprise settings

Parameters:

  • settings (Hash)

    A hash configuration of the new settings

Returns:

  • (nil)


84
85
86
87
# 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

#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

Returns:

  • (nil)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# 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

Returns:

  • (nil)


73
74
75
76
# 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.

Returns:

  • (nil)


56
57
58
59
# 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.

Returns:

  • (nil)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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