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)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 92

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



82
83
84
85
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 82

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)


57
58
59
60
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 57

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)


77
78
79
80
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 77

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)


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 117

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)


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

def settings
  conn = authenticated_client
  @last_response = conn.get('/manage/v1/config/settings')
end

#start_configurationnil

Start a configuration process.

Returns:

  • (nil)


49
50
51
52
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 49

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
# File 'lib/octokit/manage_ghes_client/manage_ghes.rb', line 37

def upload_license(license)
  conn = authenticated_client
  conn.request :multipart
  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