Skip to content

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 11 commits into from
Dec 10, 2014
9 changes: 9 additions & 0 deletions lib/Github/Api/Enterprise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Github\Api;

use Github\Api\Enterprise\ManagementConsole;
use Github\Api\Enterprise\Stats;
use Github\Api\Enterprise\License;

Expand Down Expand Up @@ -29,4 +30,12 @@ public function license()
{
return new License($this->client);
}

/**
* @return ManagementConsole
*/
public function console()
{
return new ManagementConsole($this->client);
}
}
68 changes: 68 additions & 0 deletions lib/Github/Api/Enterprise/ManagementConsole.php
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)));
}
}
36 changes: 36 additions & 0 deletions test/Github/Tests/Api/Enterprise/LicenseTest.php
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 test/Github/Tests/Api/Enterprise/ManagementConsoleTest.php
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')
Copy link
Contributor

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

->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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to use json_decode(..., true), otherwise $expectedArray is not an array but an object


$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';
}
}
43 changes: 43 additions & 0 deletions test/Github/Tests/Api/Enterprise/StatsTest.php
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';
}
}
17 changes: 10 additions & 7 deletions test/Github/Tests/Api/EnterpriseTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* This file is part of the PHP GitHub API package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Github\Tests\Api;

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

/**
* @test
*/
public function shouldGetEnterpriseManagementConsoleApiObject()
{
$api = $this->getApiMock();

$this->assertInstanceOf('Github\Api\Enterprise\ManagementConsole', $api->console());
}

protected function getApiClass()
{
return 'Github\Api\Enterprise';
}
}