Skip to content

Commit

Permalink
Align ghesmanage client with management console client
Browse files Browse the repository at this point in the history
  • Loading branch information
alejndr0 committed Jun 3, 2024
1 parent f586f54 commit 7bc6dd5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 38 deletions.
5 changes: 5 additions & 0 deletions lib/octokit/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
rescue LoadError
Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-retry` gem'
end
begin
require 'faraday/multipart'
rescue LoadError
Octokit::Warnable.octokit_warn 'To use retry middleware with Faraday v2.0+, install `faraday-multipart` gem'
end
end

module Octokit
Expand Down
18 changes: 9 additions & 9 deletions lib/octokit/manage_ghes_client/manage_ghes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ManageGHESClient
module ManageAPI
# Get information about the maintenance status of the GHES instance
#
# @return [Sawyer::Resource] The maintenance mode status
# @return [nil]
def maintenance_mode
conn = authenticated_client

Expand All @@ -33,27 +33,27 @@ def set_maintenance_mode(enabled, options = {})
#
# @param license [String] The path to your .ghl license file.
#
# @see https://docs.github.com/en/enterprise-server@3.4/rest/enterprise-admin/management-console#create-a-github-license
# @return nil
# @return [nil]
def upload_license(license)
conn = authenticated_client
conn.request :multipart
params = {}
params[:license] = Faraday::FilePart.new(license, 'binary')
@last_response = conn.put('/manage/v1/config/license', params, { 'Content-Type' => 'multipart/form-data' })
params[:password] = @manage_ghes_password
@last_response = conn.post('/manage/v1/config/init', params, { 'Content-Type' => 'multipart/form-data' })
end

# Start a configuration process.
#
# @return nil
# @return [nil]
def start_configuration
conn = authenticated_client
@last_response = conn.post('/manage/v1/config/apply')
end

# Get information about the Enterprise installation
#
# @return [Sawyer::Resource] The installation information
# @return [nil]
def config_status
conn = authenticated_client
@last_response = conn.get('/manage/v1/config/apply')
Expand All @@ -62,7 +62,7 @@ def config_status

# Get information about the Enterprise installation
#
# @return [Sawyer::Resource] The settings
# @return [nil]
def settings
conn = authenticated_client
@last_response = conn.get('/manage/v1/config/settings')
Expand All @@ -88,7 +88,7 @@ def authorized_keys
# Add an authorized SSH keys on the Enterprise install
#
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
# @return [Sawyer::Resource] An array of authorized SSH keys
# @return [nil]
def add_authorized_key(key)
conn = authenticated_client
case key
Expand All @@ -113,7 +113,7 @@ def add_authorized_key(key)
# Removes an authorized SSH keys from the Enterprise install
#
# @param key Either the file path to a key, a File handler to the key, or the contents of the key itself
# @return [Sawyer::Resource] An array of authorized SSH keys
# @return [nil]
def remove_authorized_key(key)
conn = authenticated_client
case key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
"http_interactions": [
{
"request": {
"method": "put",
"uri": "<<MANAGE_GHES_ENDPOINT>>/manage/v1/config/license",
"method": "post",
"uri": "<<MANAGE_GHES_ENDPOINT>>/manage/v1/config/init",
"body": {
"encoding": "ASCII-8BIT",
"base64_string": "anqDHd6gSAjXRl5IUvRNla+HL\nwkjkmQMlgLD1iUomBHeBrw/LsuW+DrfUqvTaBFdAYxN5e1grmlHaBREkVADd\nqD/Tp1x8Wwte2oFVTRr3Q2AMwe5JyFsp6st0Vx7Vn8SHcxustqiH1fciJLt8\nQTmMr6yYHsZ+2YPySFDjirAbSH9xSX+zKG25VqDmMWwsjBIjaQMGfbaLDygO\nDpRvo63BnoPq2B/uxLHAE3gEUZWP8ukN9cuBPB8YxmWGpsrxeQrrfPZl4cG9\nQPBhSW+0NMmo5H3BQl/z8WZtje8uBwShb6Sc2RyqMyH2GDin3XTW78JzWl9i\nuyxOvG3FHwRnA2txkuM+54ikgwWO6vKKJFoan1X8_LOLNOTREAL_/eZ3FOUm1RCXbDrK7DwY\nqftO+hhL0kFZIz+O/Dg/a/OpeCP3UPcEaNmpkZbfXqpMsIxSGi96pisMJl6M\nRNJ6ZyiFf5CqpliiwCn9I3w9NWIXJhlLzimVwzX705s6a9ML5\n72gA8iFY3THXfNt5l7Wdmss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iFf5CqpliiwCn9I3w9NWIXJhlLzimVwzX705s6a9ML5\n72gA8iFY3THXfNt5l7WdmssXegborR+ITb8cwXDdAAFXIZBurX4uQUWcN+tB\n9W07iqmpR7UzmPPQhcNZX/gmDjnkfaXx9neyydM6rY1yWhzEZ14WJwJLIne0uqU90SeqKDSPwzaTMbEo2ItVUgDbbEqNf/tXU2ZKnnU68Aywt5bfjLOM8sV6\ndmZHUCx6ygqMpRnlJwnsW/ikq00hJsKHS0TSJq4EnDiZaCyZYwjR7eHn2uGP\n/ufqoXKDWIY6Wxr4pyLcauDFUBnq75lEn7nA9knoDHmgrBFCL9bQcM+/Wh+8\nZ7I1NG5XUubvWCH8ywLhm6a5ftPKPsQh5mDurB55+gUxatRqgXS9XnfxSnac\nwlP02RpRlxPKfbMZqVsO2KW2TYUGXTpFCyZYLCau1Uw/+qJ/8z1ugURLjzJI3j2x4I3v6Mc952\n0TcebG/ZvuTaKft6dP+ZW++86Oynnn3T6j8BDQotLS0tLS0tLS0tLS0tUnVi\neU11bHRpcGFydFBvc3QNCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0\nYTsgbmFtZT0icGFzc3dvcmQiDQoNC\n\n"
},
"headers": {
"User-Agent": [
"Octokit Ruby Gem 8.1.0"
],
"Content-Type": [
"multipart/form-data; boundary=-----------RubyMultipartPost-e8412453628eb4b99f71583f2234ae4f"
"multipart/form-data; boundary=-----------RubyMultipartPost-2cfc1d28d56dda99e4bebdcded8c4f41"
],
"Authorization": [
"Basic YXBpX2tleTpRMjBVcm45aWs="
],
"Content-Length": [
"17459"
"17583"
],
"Accept-Encoding": [
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
Expand All @@ -31,44 +31,29 @@
},
"response": {
"status": {
"code": 201,
"message": "Created"
"code": 202,
"message": "Accepted"
},
"headers": {
"Content-Security-Policy": [
"default-src 'none';"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Server": [
"GHES Manage"
],
"Strict-Transport-Security": [
"max-age=63072000; includeSubDomains; preload"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Frame-Options": [
"DENY"
],
"X-Xss-Protection": [
"0"
],
"Date": [
"Tue, 28 May 2024 10:16:58 GMT"
"Mon, 03 Jun 2024 11:12:05 GMT"
],
"Content-Length": [
"3"
],
"X-Frame-Options": [
"DENY"
]
},
"body": {
"encoding": "UTF-8",
"base64_string": "e30K\n"
}
},
"recorded_at": "Tue, 28 May 2024 10:16:58 GMT"
"recorded_at": "Mon, 03 Jun 2024 11:12:05 GMT"
}
],
"recorded_with": "VCR 6.2.0"
Expand Down
4 changes: 2 additions & 2 deletions spec/octokit/ghes_manage_client/ghes_manage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
describe '.upload_license', :vcr do
it 'upload a new license' do
@manage_ghes.upload_license(@license)
expect(@manage_ghes.last_response.status).to eq(201)
assert_requested :put, github_manage_ghes_url('/manage/v1/config/license')
expect(@manage_ghes.last_response.status).to eq(202)
assert_requested :post, github_manage_ghes_url('/manage/v1/config/init')
end
end # .upload_license

Expand Down

0 comments on commit 7bc6dd5

Please sign in to comment.