ManagementConsole::upgrade()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
namespace FlexyProject\GitHub\Receiver\Enterprise;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The Management Console API helps you manage your GitHub Enterprise installation.
8
 *
9
 * @link    https://developer.github.com/v3/enterprise/management_console/
10
 * @package GitHub\Receiver\Enterprise
11
 */
12
class ManagementConsole extends AbstractEnterprise
13
{
14
15
    /** Properties */
16
    protected $hostname = '';
17
    protected $password = '';
18
19
    /**
20
     * Get password
21
     *
22
     * @return string
23
     */
24
    public function getPassword(): string
25
    {
26
        return $this->password;
27
    }
28
29
    /**
30
     * Set password
31
     *
32
     * @param string $password
33
     *
34
     * @return ManagementConsole
35
     */
36
    public function setPassword(string $password): ManagementConsole
37
    {
38
        $this->password = $password;
39
40
        return $this;
41
    }
42
43
    /**
44
     * Get hostname
45
     *
46
     * @return string
47
     */
48
    public function getHostname(): string
49
    {
50
        return $this->hostname;
51
    }
52
53
    /**
54
     * Set hostname
55
     *
56
     * @param string $hostname
57
     *
58
     * @return ManagementConsole
59
     */
60
    public function setHostname(string $hostname): ManagementConsole
61
    {
62
        $this->hostname = $hostname;
63
64
        return $this;
65
    }
66
67
    /**
68
     * Upload a license and software package for the first time
69
     *
70
     * @link https://developer.github.com/v3/enterprise/management_console/#upload-a-license-and-software-package-for-the-first-time
71
     *
72
     * @param string $license
73
     * @param string $package
74
     * @param string $settings
75
     *
76
     * @return array
77
     */
78 View Code Duplication
    public function upload(string $license, string $package, string $settings = ''): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        $this->getApi()->setApiUrl(sprintf('http://license:%s@%s', md5($license), $this->getHostname()));
81
82
        return $this->getApi()->request(sprintf('/setup/api/start -F package=@%s -F license=@%s -F settings=<%s',
83
            $package, $license, $settings), Request::METHOD_POST);
84
    }
85
86
    /**
87
     * Upgrade a license or software package
88
     *
89
     * @link https://developer.github.com/v3/enterprise/management_console/#upgrade-a-license-or-software-package
90
     *
91
     * @param string $license
92
     * @param string $package
93
     *
94
     * @return array
95
     */
96 View Code Duplication
    public function upgrade(string $license = '', string $package = ''): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $this->getApi()->setApiUrl(sprintf('http://license:%s@%s', md5($license), $this->getHostname()));
99
100
        return $this->getApi()->request(sprintf('/setup/api/upgrade -F package=@%s -F license=@%s', $package, $license),
101
            Request::METHOD_POST);
102
    }
103
104
    /**
105
     * Check configuration status
106
     *
107
     * @link https://developer.github.com/v3/enterprise/management_console/#check-configuration-status
108
     * @return array
109
     */
110
    public function checkConfigurationStatus(): array
111
    {
112
        return $this->getApi()->request(sprintf('/setup/api/configcheck'));
113
    }
114
115
    /**
116
     * Start a configuration process
117
     *
118
     * @link https://developer.github.com/v3/enterprise/management_console/#start-a-configuration-process
119
     * @return array
120
     */
121
    public function startConfigurationProcess(): array
122
    {
123
        return $this->getApi()->request(sprintf('/setup/api/configure'), Request::METHOD_POST);
124
    }
125
126
    /**
127
     * Retrieve settings
128
     *
129
     * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-settings
130
     * @return array
131
     */
132
    public function retrieveSettings(): array
133
    {
134
        return $this->getApi()->request(sprintf('/setup/api/settings'));
135
    }
136
137
    /**
138
     * Modify settings
139
     *
140
     * @link https://developer.github.com/v3/enterprise/management_console/#modify-settings
141
     *
142
     * @param $settings
143
     *
144
     * @return array
145
     */
146
    public function modifySettings($settings): array
147
    {
148
        return $this->getApi()->request(sprintf('/setup/api/settings settings=%s', $settings), Request::METHOD_PUT);
149
    }
150
151
    /**
152
     * Check maintenance status
153
     *
154
     * @link https://developer.github.com/v3/enterprise/management_console/#check-maintenance-status
155
     * @return array
156
     */
157
    public function checkMaintenanceStatus(): array
158
    {
159
        return $this->getApi()->request(sprintf('/setup/api/maintenance'));
160
    }
161
162
    /**
163
     * Enable or disable maintenance mode
164
     *
165
     * @link https://developer.github.com/v3/enterprise/management_console/#enable-or-disable-maintenance-mode
166
     *
167
     * @param string $maintenance
168
     *
169
     * @return array
170
     */
171
    public function updateMaintenanceStatus(string $maintenance): array
172
    {
173
        return $this->getApi()->request(sprintf('/setup/api/maintenance -d maintenance=%s', $maintenance),
174
            Request::METHOD_POST);
175
    }
176
177
    /**
178
     * Retrieve authorized SSH keys
179
     *
180
     * @link https://developer.github.com/v3/enterprise/management_console/#retrieve-authorized-ssh-keys
181
     * @return array
182
     */
183
    public function retrieveAuthorizedSshKeys(): array
184
    {
185
        return $this->getApi()->request(sprintf('/setup/api/settings/authorized-keys'));
186
    }
187
188
    /**
189
     * Add a new authorized SSH key
190
     *
191
     * @link https://developer.github.com/v3/enterprise/management_console/#add-a-new-authorized-ssh-key
192
     *
193
     * @param string $authorizedKey
194
     *
195
     * @return array
196
     */
197
    public function addNewAuthorizedSshKeys(string $authorizedKey): array
198
    {
199
        return $this->getApi()->request(sprintf('/setup/api/settings/authorized-keys -F authorized_key=@%s',
200
            $authorizedKey), Request::METHOD_POST);
201
    }
202
203
    /**
204
     * Remove an authorized SSH key
205
     *
206
     * @link https://developer.github.com/v3/enterprise/management_console/#remove-an-authorized-ssh-key
207
     *
208
     * @param string $authorizedKey
209
     *
210
     * @return array
211
     */
212
    public function removeAuthorizedSshKeys(string $authorizedKey): array
213
    {
214
        return $this->getApi()->request(sprintf('/setup/api/settings/authorized-keys -F authorized_key=@%s',
215
            $authorizedKey), Request::METHOD_DELETE);
216
    }
217
}