Skip to content

Commit 40207d4

Browse files
committed
Merge pull request #203 from guillermoandrae/master
Added ManagementConsole API and some missing tests.
2 parents def1ed9 + 31ca116 commit 40207d4

File tree

6 files changed

+326
-7
lines changed

6 files changed

+326
-7
lines changed

lib/Github/Api/Enterprise.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Github\Api;
44

5+
use Github\Api\Enterprise\ManagementConsole;
56
use Github\Api\Enterprise\Stats;
67
use Github\Api\Enterprise\License;
78

@@ -29,4 +30,12 @@ public function license()
2930
{
3031
return new License($this->client);
3132
}
33+
34+
/**
35+
* @return ManagementConsole
36+
*/
37+
public function console()
38+
{
39+
return new ManagementConsole($this->client);
40+
}
3241
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
namespace Github\Api\Enterprise;
4+
5+
use Github\Api\AbstractApi;
6+
7+
class ManagementConsole extends AbstractApi
8+
{
9+
/**
10+
* Checks the status of your installation’s most recent configuration process.
11+
* @link https://developer.github.com/v3/enterprise/management_console/#check-configuration-status
12+
*
13+
* @param string $hash md5 hash of your license
14+
* @return array array of configuration status information
15+
*/
16+
public function configcheck($hash)
17+
{
18+
return $this->getWithLicenseHash('/setup/api/configcheck', $hash);
19+
}
20+
21+
/**
22+
* Retrieves your installation’s settings.
23+
* @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings
24+
*
25+
* @param string $hash md5 hash of your license
26+
* @return array array of settings
27+
*/
28+
public function settings($hash)
29+
{
30+
return $this->getWithLicenseHash('/setup/api/settings', $hash);
31+
}
32+
33+
/**
34+
* Checks your installation’s maintenance status.
35+
* @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
36+
*
37+
* @param string $hash md5 hash of your license
38+
* @return array array of maintenance status information
39+
*/
40+
public function maintenance($hash)
41+
{
42+
return $this->getWithLicenseHash('/setup/api/maintenance', $hash);
43+
}
44+
45+
/**
46+
* Retrieves your installation’s authorized SSH keys.
47+
* @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys
48+
*
49+
* @param string $hash md5 hash of your license
50+
* @return array array of authorized keys
51+
*/
52+
public function keys($hash)
53+
{
54+
return $this->getWithLicenseHash('/setup/api/settings/authorized-keys', $hash);
55+
}
56+
57+
/**
58+
* Sends an authenticated GET request.
59+
*
60+
* @param string $uri the request URI
61+
* @param string $hash md5 hash of your license
62+
* @return \Guzzle\Http\EntityBodyInterface|mixed|string
63+
*/
64+
protected function getWithLicenseHash($uri, $hash)
65+
{
66+
return $this->get($uri, array('license_md5' => rawurlencode($hash)));
67+
}
68+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Enterprise;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class LicenseTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldShowLicenseInformation()
13+
{
14+
$expectedArray = array(
15+
'seats' => 1400,
16+
'seats_used' => 1316,
17+
'seats_available' => 84,
18+
'kind' => 'standard',
19+
'days_until_expiration' => 365,
20+
'expire_at' => '2016/02/06 12:41:52 -0600'
21+
);
22+
23+
$api = $this->getApiMock();
24+
$api->expects($this->once())
25+
->method('get')
26+
->with('enterprise/settings/license')
27+
->will($this->returnValue($expectedArray));
28+
29+
$this->assertEquals($expectedArray, $api->show());
30+
}
31+
32+
protected function getApiClass()
33+
{
34+
return 'Github\Api\Enterprise\License';
35+
}
36+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Enterprise;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class ManagementConsoleTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldShowConfigData()
13+
{
14+
$expectedJson = '{ "status": "running", "progress": [ { "status": "DONE", "key": "Appliance core components" },
15+
{ "status": "DONE", "key": "GitHub utilities" }, { "status": "DONE", "key": "GitHub applications" },
16+
{ "status": "CONFIGURING", "key": "GitHub services" }, { "status": "PENDING", "key":
17+
"Reloading appliance services" } ] }';
18+
$expectedArray = json_decode($expectedJson, true);
19+
20+
$api = $this->getApiMock();
21+
$api->expects($this->once())
22+
->method('get')
23+
->with('/setup/api/configcheck', array('license_md5' => $this->getLicenseHash()))
24+
->will($this->returnValue($expectedArray));
25+
26+
$this->assertEquals($expectedArray, $api->configcheck($this->getLicenseHash()));
27+
}
28+
29+
/**
30+
* @test
31+
*/
32+
public function shouldShowSettingsData()
33+
{
34+
$expectedJson = '{ "enterprise": { "private_mode": false, "github_hostname": "ghe.local", "auth_mode":
35+
"default", "storage_mode": "rootfs", "admin_password": null, "configuration_id": 1401777404,
36+
"configuration_run_count": 4, "package_version": "11.10.332", "avatar": { "enabled": false, "uri": "" },
37+
"customer": { "name": "GitHub", "email": "stannis@themannis.biz", "uuid":
38+
"af6cac80-e4e1-012e-d822-1231380e52e9",
39+
"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",
40+
"public_key_data": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1.4.10 (GNU/Linux)\n\nmI0ETqzZYgEEALSe6snowdenXyqvLfSQ34HWD6C7....\n-----END PGP PUBLIC KEY BLOCK-----\n" },
41+
"license": { "seats": 0, "evaluation": false, "expire_at": "2015-04-27T00:00:00-07:00", "perpetual": false,
42+
"unlimited_seating": true, "support_key": "ssh-rsa AAAAB3N....", "ssh_allowed": true }, "github_ssl":
43+
{ "enabled": false, "cert": null, "key": null }, "ldap": { "host": "", "port": "", "base": [ ], "uid": "",
44+
"bind_dn": "", "password": "", "method": "Plain", "user_groups": [ ], "admin_group": "" }, "cas": { "url": "" },
45+
"github_oauth": { "client_id": "12313412", "client_secret": "kj123131132", "organization_name":
46+
"Homestar Runners", "organization_team": "homestarrunners/owners" }, "smtp": { "enabled": true, "address":
47+
"smtp.example.com", "authentication": "plain", "port": "1234", "domain": "blah", "username": "foo", "user_name":
48+
"mr_foo", "enable_starttls_auto": true, "password": "bar", "support_address": "enterprise@github.com",
49+
"noreply_address": "noreply@github.com" }, "dns": { "primary_nameserver": "8.8.8.8", "secondary_nameserver":
50+
"8.8.4.4" }, "ntp": { "primary_server": "0.ubuntu.pool.ntp.org", "secondary_server": "1.ubuntu.pool.ntp.org" },
51+
"timezone": { "identifier": "UTC" }, "device": { "path": "/dev/xyz" }, "snmp": { "enabled": false,
52+
"community": "" }, "rsyslog": { "enabled": false, "server": "", "protocol_name": "TCP" }, "assets": { "storage":
53+
"file", "bucket": null, "host_name": null, "key_id": null, "access_key": null }, "pages": { "enabled": true },
54+
"collectd": { "enabled": false, "server": "", "port": "", "encryption": "", "username": "foo", "password":
55+
"bar" } }, "run_list": [ "role[configure]" ] }';
56+
$expectedArray = json_decode($expectedJson, true);
57+
58+
$api = $this->getApiMock();
59+
$api->expects($this->once())
60+
->method('get')
61+
->with('/setup/api/settings', array('license_md5' => $this->getLicenseHash()))
62+
->will($this->returnValue($expectedArray));
63+
64+
$this->assertEquals($expectedArray, $api->settings($this->getLicenseHash()));
65+
}
66+
67+
/**
68+
* @test
69+
*/
70+
public function shouldShowMaintenanceStatus()
71+
{
72+
$expectedJson = '{ "status": "scheduled", "scheduled_time": "Tuesday, January 22 at 15 => 34 -0800",
73+
"connection_services": [ { "name": "git operations", "number": 0 }, { "name": "mysql queries", "number": 233 },
74+
{ "name": "resque jobs", "number": 54 } ] }';
75+
$expectedArray = json_decode($expectedJson, true);
76+
77+
$api = $this->getApiMock();
78+
$api->expects($this->once())
79+
->method('get')
80+
->with('/setup/api/maintenance', array('license_md5' => $this->getLicenseHash()))
81+
->will($this->returnValue($expectedArray));
82+
83+
$this->assertEquals($expectedArray, $api->maintenance($this->getLicenseHash()));
84+
}
85+
86+
/**
87+
* @test
88+
*/
89+
public function shouldShowAuthorizedKeys()
90+
{
91+
$expectedJson = '[ { "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print":
92+
"ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" },
93+
{ "key": "ssh-rsa AAAAB3NzaC1yc2EAAAAB...", "pretty-print":
94+
"ssh-rsa 01:14:0f:f2:0f:e2:fe:e8:f4:72:62:af:75:f7:1a:88:3e:04:92:64" } ]';
95+
$expectedArray = json_decode($expectedJson, true);
96+
97+
$api = $this->getApiMock();
98+
$api->expects($this->once())
99+
->method('get')
100+
->with('/setup/api/settings/authorized-keys', array('license_md5' => $this->getLicenseHash()))
101+
->will($this->returnValue($expectedArray));
102+
$this->assertEquals($expectedArray, $api->keys($this->getLicenseHash()));
103+
}
104+
105+
protected function getLicenseHash()
106+
{
107+
return '1234567890abcdefghijklmnopqrstuv';
108+
}
109+
110+
protected function getApiClass()
111+
{
112+
return 'Github\Api\Enterprise\ManagementConsole';
113+
}
114+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Enterprise;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class StatsTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldShowStats()
13+
{
14+
$expectedArray = $this->getStatsData();
15+
16+
$api = $this->getApiMock();
17+
$api->expects($this->once())
18+
->method('get')
19+
->with('enterprise/stats/all')
20+
->will($this->returnValue($expectedArray));
21+
22+
$this->assertEquals($expectedArray, $api->show('all'));
23+
}
24+
25+
/**
26+
* @test
27+
* @dataProvider getTypes
28+
*/
29+
public function shouldShowStatsByType($type)
30+
{
31+
$expectedArray = $this->getStatsData($type);
32+
33+
$api = $this->getApiMock();
34+
$api->expects($this->once())
35+
->method('get')
36+
->with(sprintf('enterprise/stats/%s', $type))
37+
->will($this->returnValue($expectedArray));
38+
39+
$this->assertEquals($expectedArray, call_user_func(array($api, $type)));
40+
}
41+
42+
/**
43+
* @return array
44+
*/
45+
public function getTypes()
46+
{
47+
return array(
48+
array('issues'),
49+
array('hooks'),
50+
array('milestones'),
51+
array('orgs'),
52+
array('comments'),
53+
array('pages'),
54+
array('users'),
55+
array('gists'),
56+
array('pulls'),
57+
array('repos'),
58+
array('all')
59+
);
60+
}
61+
62+
/**
63+
* @param string $key
64+
* @return mixed
65+
*/
66+
protected function getStatsData($key = '')
67+
{
68+
$json = '{"repos":{"total_repos": 212, "root_repos": 194, "fork_repos": 18, "org_repos": 51,
69+
"total_pushes": 3082, "total_wikis": 15 }, "hooks": { "total_hooks": 27, "active_hooks": 23,
70+
"inactive_hooks": 4 }, "pages": { "total_pages": 36 }, "orgs": { "total_orgs": 33, "disabled_orgs": 0,
71+
"total_teams": 60, "total_team_members": 314 }, "users": { "total_users": 254, "admin_users": 45,
72+
"suspended_users": 21 }, "pulls": { "total_pulls": 86, "merged_pulls": 60, "mergeable_pulls": 21,
73+
"unmergeable_pulls": 3 }, "issues": { "total_issues": 179, "open_issues": 83, "closed_issues": 96 },
74+
"milestones": { "total_milestones": 7, "open_milestones": 6, "closed_milestones": 1 }, "gists":
75+
{ "total_gists": 178, "private_gists": 151, "public_gists": 25 }, "comments": { "total_commit_comments": 6,
76+
"total_gist_comments": 28, "total_issue_comments": 366, "total_pull_request_comments": 30 } }';
77+
$stats = json_decode($json, true);
78+
if (is_null($key)) {
79+
return $stats;
80+
} elseif (array_key_exists($key, $stats)) {
81+
return $stats[$key];
82+
}
83+
}
84+
85+
protected function getApiClass()
86+
{
87+
return 'Github\Api\Enterprise\Stats';
88+
}
89+
}

test/Github/Tests/Api/EnterpriseTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?php
2-
/**
3-
* This file is part of the PHP GitHub API package.
4-
*
5-
* For the full copyright and license information, please view the LICENSE
6-
* file that was distributed with this source code.
7-
*/
82

93
namespace Github\Tests\Api;
104

@@ -30,9 +24,18 @@ public function shouldGetEnterpriseLicenseApiObject()
3024
$this->assertInstanceOf('Github\Api\Enterprise\License', $api->license());
3125
}
3226

27+
/**
28+
* @test
29+
*/
30+
public function shouldGetEnterpriseManagementConsoleApiObject()
31+
{
32+
$api = $this->getApiMock();
33+
34+
$this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console());
35+
}
36+
3337
protected function getApiClass()
3438
{
3539
return 'Github\Api\Enterprise';
3640
}
3741
}
38-

0 commit comments

Comments
 (0)