-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (51 loc) · 1.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const core = require('@actions/core');
const github = require('@actions/github');
const axios = require('axios');
const { ClientCredentials } = require('simple-oauth2');
async function run() {
const clientID = core.getInput('clientid');
const clientSecret = core.getInput('clientsecret');
if (!clientID || 0 === clientID.length) {
return core.setFailed(`Required input "clientid" is unset.`);
}
if (!clientSecret || 0 === clientSecret.length) {
return core.setFailed(`Required input "clientsecret" is unset.`)
}
const serverID = core.getInput('serverid');
if (!serverID || 0 === serverID.length) {
return core.setFailed(`Required input "serverid" is unset.`)
}
const bmcEntrypoint = core.getInput('bmcentrypoint');
const bmcTokenHost = core.getInput('bmctokenhost');
const bmcTokenPath = core.getInput('bmctokenpath');
if (!bmcEntrypoint || 0 === bmcEntrypoint.length) {
return core.setFailed(`Required input "bmcentrypoint" is unset.`)
}
if (!bmcTokenHost || 0 === bmcTokenHost.length) {
return core.setFailed(`Required input "bmctokenhost" is unset.`)
}
if (!bmcTokenPath || 0 === bmcTokenPath.length) {
return core.setFailed(`Required input "bmctokenpath" is unset.`)
}
try {
const client = new ClientCredentials({
client: { id: clientID, secret: clientSecret },
auth: { tokenHost: bmcTokenHost, tokenPath: bmcTokenPath },
options: { bodyFormat: "form" }
});
const accessToken = await client.getToken();
const response = await axios({
method: 'delete',
baseURL: bmcEntrypoint,
url: `/servers/${serverID}`,
headers: {
'Authorization': `Bearer ${accessToken.token.access_token}`,
'Content-Type': 'application/json'
}
});
core.setOutput('id', response.data.serverId);
} catch (error) {
core.setFailed(error.message);
}
}
run();