-
-
Notifications
You must be signed in to change notification settings - Fork 598
Added ManagementConsole API and some missing tests. #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6bed128
Added the ManagementConsole class.
de4eeb4
Added a convenience method to the Enterprise class.
944ef80
Added ManagementConsole tests.
a603126
Back-filled other Enterprise tests.
daad20d
Removed the unneeded docblocks.
4a9c53d
Sending the hash as a parameter for now. Not ideal, but will refactor…
5529dea
Fixed docblock; no longer overriding "get" -- added "getWithLicenseHa…
5b36194
Should be decoding and not encoding the JSON.
9d4b593
Should be decoding and not encoding the JSON in the StatsTest as well.
cc01bce
Added second param to json_decode calls; checking that the license ha…
31ca116
Added remaining Stats tests.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Github\Api\Enterprise; | ||
|
||
use Github\Api\AbstractApi; | ||
|
||
class ManagementConsole extends AbstractApi | ||
{ | ||
/** | ||
* Checks the status of your installation’s most recent configuration process. | ||
* @link https://developer.github.com/v3/enterprise/management_console/#check-configuration-status | ||
* | ||
* @param string $hash md5 hash of your license | ||
* @return array array of configuration status information | ||
*/ | ||
public function configcheck($hash) | ||
{ | ||
return $this->getWithLicenseHash('/setup/api/configcheck', $hash); | ||
} | ||
|
||
/** | ||
* Retrieves your installation’s settings. | ||
* @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings | ||
* | ||
* @param string $hash md5 hash of your license | ||
* @return array array of settings | ||
*/ | ||
public function settings($hash) | ||
{ | ||
return $this->getWithLicenseHash('/setup/api/settings', $hash); | ||
} | ||
|
||
/** | ||
* Checks your installation’s maintenance status. | ||
* @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status | ||
* | ||
* @param string $hash md5 hash of your license | ||
* @return array array of maintenance status information | ||
*/ | ||
public function maintenance($hash) | ||
{ | ||
return $this->getWithLicenseHash('/setup/api/maintenance', $hash); | ||
} | ||
|
||
/** | ||
* Retrieves your installation’s authorized SSH keys. | ||
* @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys | ||
* | ||
* @param string $hash md5 hash of your license | ||
* @return array array of authorized keys | ||
*/ | ||
public function keys($hash) | ||
{ | ||
return $this->getWithLicenseHash('/setup/api/settings/authorized-keys', $hash); | ||
} | ||
|
||
/** | ||
* Sends an authenticated GET request. | ||
* | ||
* @param string $uri the request URI | ||
* @param string $hash md5 hash of your license | ||
* @return \Guzzle\Http\EntityBodyInterface|mixed|string | ||
*/ | ||
protected function getWithLicenseHash($uri, $hash) | ||
{ | ||
return $this->get($uri, array('license_md5' => rawurlencode($hash))); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\Enterprise; | ||
|
||
use Github\Tests\Api\TestCase; | ||
|
||
class LicenseTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldShowLicenseInformation() | ||
{ | ||
$expectedArray = array( | ||
'seats' => 1400, | ||
'seats_used' => 1316, | ||
'seats_available' => 84, | ||
'kind' => 'standard', | ||
'days_until_expiration' => 365, | ||
'expire_at' => '2016/02/06 12:41:52 -0600' | ||
); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('enterprise/settings/license') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->show()); | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\Enterprise\License'; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\Enterprise; | ||
|
||
use Github\Tests\Api\TestCase; | ||
|
||
class ManagementConsoleTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldShowConfigData() | ||
{ | ||
$expectedJson = '{ "status": "running", "progress": [ { "status": "DONE", "key": "Appliance core components" }, | ||
{ "status": "DONE", "key": "GitHub utilities" }, { "status": "DONE", "key": "GitHub applications" }, | ||
{ "status": "CONFIGURING", "key": "GitHub services" }, { "status": "PENDING", "key": | ||
"Reloading appliance services" } ] }'; | ||
$expectedArray = json_decode($expectedJson); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/setup/api/configcheck') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldShowSettingsData() | ||
{ | ||
$expectedJson = '{ "enterprise": { "private_mode": false, "github_hostname": "ghe.local", "auth_mode": | ||
"default", "storage_mode": "rootfs", "admin_password": null, "configuration_id": 1401777404, | ||
"configuration_run_count": 4, "package_version": "11.10.332", "avatar": { "enabled": false, "uri": "" }, | ||
"customer": { "name": "GitHub", "email": "stannis@themannis.biz", "uuid": | ||
"af6cac80-e4e1-012e-d822-1231380e52e9", | ||
"secret_key_data": "-----BEGIN PGP PRIVATE KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nlQcYBE5TCgsBEACk4yHpUcapplebaumBMXYMiLF+nCQ0lxpx...\n-----END PGP PRIVATE KEY BLOCK-----\n", | ||
"public_key_data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nmI0ETqzZYgEEALSe6snowdenXyqvLfSQ34HWD6C7....\n-----END PGP PUBLIC KEY BLOCK-----\n" }, | ||
"license": { "seats": 0, "evaluation": false, "expire_at": "2015-04-27T00:00:00-07:00", "perpetual": false, | ||
"unlimited_seating": true, "support_key": "ssh-rsa AAAAB3N....", "ssh_allowed": true }, "github_ssl": | ||
{ "enabled": false, "cert": null, "key": null }, "ldap": { "host": "", "port": "", "base": [ ], "uid": "", | ||
"bind_dn": "", "password": "", "method": "Plain", "user_groups": [ ], "admin_group": "" }, "cas": { "url": "" }, | ||
"github_oauth": { "client_id": "12313412", "client_secret": "kj123131132", "organization_name": | ||
"Homestar Runners", "organization_team": "homestarrunners/owners" }, "smtp": { "enabled": true, "address": | ||
"smtp.example.com", "authentication": "plain", "port": "1234", "domain": "blah", "username": "foo", "user_name": | ||
"mr_foo", "enable_starttls_auto": true, "password": "bar", "support_address": "enterprise@github.com", | ||
"noreply_address": "noreply@github.com" }, "dns": { "primary_nameserver": "8.8.8.8", "secondary_nameserver": | ||
"8.8.4.4" }, "ntp": { "primary_server": "0.ubuntu.pool.ntp.org", "secondary_server": "1.ubuntu.pool.ntp.org" }, | ||
"timezone": { "identifier": "UTC" }, "device": { "path": "/dev/xyz" }, "snmp": { "enabled": false, | ||
"community": "" }, "rsyslog": { "enabled": false, "server": "", "protocol_name": "TCP" }, "assets": { "storage": | ||
"file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true }, | ||
"collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password": | ||
"bar" } }, "run_list": [ "role[configure]" ] }'; | ||
$expectedArray = json_decode($expectedJson); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to use |
||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/setup/api/settings') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->settings($this->getLicenseHash())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldShowMaintenanceStatus() | ||
{ | ||
$expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800", | ||
"connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 }, | ||
{ "name": "resque jobs", "number": 54 } ] }'; | ||
$expectedArray = json_decode($expectedJson); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/setup/api/maintenance') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldShowAuthorizedKeys() | ||
{ | ||
$expectedJson = '[ { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": | ||
"ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" }, | ||
{ "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print": | ||
"ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]'; | ||
$expectedArray = json_decode($expectedJson); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/setup/api/settings/authorized-keys') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->keys($this->getLicenseHash())); | ||
} | ||
|
||
protected function getLicenseHash() | ||
{ | ||
return '1234567890abcdefghijklmnopqrstuv'; | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\Enterprise\ManagementConsole'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\Enterprise; | ||
|
||
use Github\Tests\Api\TestCase; | ||
|
||
class StatsTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldShowStats() | ||
{ | ||
$expectedJson = $this->getJson(); | ||
$expectedArray = json_encode($expectedJson); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('enterprise/stats/all') | ||
->will($this->returnValue($expectedArray)); | ||
|
||
$this->assertEquals($expectedArray, $api->show('all')); | ||
} | ||
|
||
protected function getJson() | ||
{ | ||
return '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51, | ||
"total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23, | ||
"inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0, | ||
"total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45, | ||
"suspended_users": 21 }, "pulls": { "total_pulls": 86, "merged_pulls": 60, "mergeable_pulls": 21, | ||
"unmergeable_pulls": 3 }, "issues": { "total_issues": 179, "open_issues": 83, "closed_issues": 96 }, | ||
"milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists": | ||
{ "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6, | ||
"total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } }'; | ||
} | ||
|
||
protected function getApiClass() | ||
{ | ||
return 'Github\Api\Enterprise\Stats'; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should check that get is called with the hash in the headers too, not only with the second argument