-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathdelete-resources.js
More file actions
120 lines (101 loc) · 3.08 KB
/
Copy pathdelete-resources.js
File metadata and controls
120 lines (101 loc) · 3.08 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const okta = require('../');
const utils = require('./utils');
let orgUrl = process.env.OKTA_CLIENT_ORGURL;
if (process.env.OKTA_USE_MOCK) {
orgUrl = `${orgUrl}/application-get-user`;
}
const client = new okta.Client({
scopes: ['okta.apps.manage', 'okta.users.manage'],
orgUrl: orgUrl,
token: process.env.OKTA_CLIENT_TOKEN,
requestExecutor: new okta.DefaultRequestExecutor()
});
async function cleanInlineHooks() {
const collection = client.listInlineHooks();
await collection.each(async (inlineHook) => {
await inlineHook.deactivate();
await inlineHook.delete();
});
}
async function cleanDomains() {
const domains = (await client.listDomains()).domains;
for (const domain of domains) {
if (domain.certificateSourceType === 'MANUAL') {
await client.deleteDomain(domain.id);
}
}
}
async function cleanAuthorizationServers() {
await client.listAuthorizationServers().each(
async (authorizationServer) => {
await authorizationServer.delete();
}
);
}
async function cleanNetworkZones() {
await client.listNetworkZones().each(
async networkZone => {
const canDelete = networkZone.name?.startsWith('node-sdk: ');
if (canDelete) {
try {
if (networkZone.status === 'ACTIVE') {
await client.deactivateNetworkZone(networkZone.id);
}
await client.deleteNetworkZone(networkZone.id);
} catch (err) {
console.error(err);
}
} else {
console.log(`Skipped network zone to remove ${networkZone.name}`);
}
}
);
}
async function cleanApplications() {
await client.listApplications().each(async (application) =>{
(application.label === 'Node SDK Service App' || application.label === 'Bacon Service Client') ?
console.log(`Skipped application to remove ${application.label}`) :
await utils.removeAppByLabel(client, application.label);
});
}
async function cleanTestUsers() {
await client.listUsers().each(async (user) => {
(user.profile.email.endsWith('okta.com')) ?
console.log(`Skipped user to remove ${user.profile.email}`) :
await utils.deleteUser(user);
});
}
async function cleanTestGroups() {
const url = `${client.baseUrl}/api/v1/groups`;
const request = {
method: 'get',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
}
};
return client.http.http(url, request)
.then(responce => responce.text())
.then(bodyResponce => JSON.parse(bodyResponce))
.then(user => {
user.forEach(element =>{
(element.profile.name === 'Everyone') ?
console.log(`Skipped group to remove ${element.profile.name}`) :
utils.cleanupGroup(client, element);
});
})
.catch(err => {
console.error(err);
});
}
describe('Clean all test resources', () => {
it('cleans resources', async () => {
await cleanNetworkZones();
await cleanAuthorizationServers();
await cleanTestUsers();
await cleanTestGroups();
await cleanApplications();
await cleanDomains();
await cleanInlineHooks();
});
});