-
-
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
Changes from 6 commits
6bed128
de4eeb4
944ef80
a603126
daad20d
4a9c53d
5529dea
5b36194
9d4b593
cc01bce
31ca116
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?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->get('/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->get('/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->get('/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->get('/setup/api/settings/authorized-keys', $hash); | ||
} | ||
|
||
/** | ||
* Sends an authenticated GET request. | ||
* | ||
* @see \Github\Api\AbstractApi::get() | ||
* @param string $uri | ||
* @param array $hash | ||
* @return \Guzzle\Http\EntityBodyInterface|mixed|string | ||
*/ | ||
protected function get($uri, $hash) | ||
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. Overwriting the parent method with a different signature is a bad idea IMO. You should use a different method name instead |
||
{ | ||
return parent::get($uri, array('license_md5' => rawurlencode($hash))); | ||
} | ||
} |
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'; | ||
} | ||
} |
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_encode($expectedJson); | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/setup/api/configcheck') | ||
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 should check that get is called with the hash in the headers too, not only with the second argument |
||
->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_encode($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. shouldn't it decode the JSON to get an array instead of encoding it ? 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're 100% right. Missed that completely. Fixing now. |
||
|
||
$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_encode($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_encode($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'; | ||
} | ||
} |
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'; | ||
} | ||
} |
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.
this is wrong. Your argument is not an array (which is why the signature does not match)