-
Notifications
You must be signed in to change notification settings - Fork 4
/
ldutils
executable file
·225 lines (194 loc) · 9.15 KB
/
ldutils
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env node
let json = require('format-json');
let program = require('commander');
let LaunchDarklyUtils = require('./dist/src/LaunchDarklyUtils.js').LaunchDarklyUtils;
require('dotenv').config();
if (!process.env.LAUNCHDARKLY_API_TOKEN) {
console.log('missing environment var LAUNCHDARKLY_API_TOKEN - exiting..');
process.exit(1);
}
let log = console;
// fallback to bunyan logger if debug mode
if (process.env.LAUNCHDARKLY_API_LOGLEVEL === 'debug') log = undefined;
process.on('unhandledRejection', (reason, p) => {
console.error(json.plain({"error": reason}));
process.exit(1);
});
new LaunchDarklyUtils().create(process.env.LAUNCHDARKLY_API_TOKEN, log).then(function(ldUtils) {
program
.version('1.0.0')
.description('Manage LaunchDarkly flags and other assets from the command line.');
program
.command('getFeatureFlags <projectKey>')
.description('get all flags for a given project')
.action(function(projectKey) {
ldUtils.flags.getFeatureFlags(projectKey).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`getFeatureFlag <projectKey> <featureFlagKey> [environmentKeyQuery]`)
.description('get a single flag - with optional env')
.action(function(projectKey, featureFlagKey, environmentKeyQuery) {
ldUtils.flags.getFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`getFeatureFlagState <projectKey> <featureFlagKey> <environmentKeyQuery>`)
.description('get boolean flag state')
.action(function(projectKey, featureFlagKey, environmentKeyQuery) {
ldUtils.flags.getFeatureFlagState(projectKey, featureFlagKey, environmentKeyQuery).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`toggleFeatureFlag <projectKey> <featureFlagKey> <environmentKeyQuery> <value>`)
.description('set boolean flag state')
.action(function(projectKey, featureFlagKey, environmentKeyQuery, value) {
let enabled = value === 'true';
ldUtils.flags.toggleFeatureFlag(projectKey, featureFlagKey, environmentKeyQuery, enabled).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`migrateFeatureFlag <projectKey> <featureFlagKey> <fromEnv> <toEnv> (includeState)`)
.description('migrate flag settings from one environment to another')
.action(function(projectKey, featureFlagKey, fromEnv, toEnv, includeState) {
ldUtils.flags.migrateFeatureFlag(projectKey, featureFlagKey, fromEnv, toEnv, includeState).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`bulkMigrateFeatureFlags <projectKey> <featureFlagKeys> <fromEnv> <toEnv> (includeState)`)
.description('migrate multiple flag settings from one environment to another')
.action(function(projectKey, featureFlagKeys, fromEnv, toEnv, includeState) {
ldUtils.flags.bulkMigrateFeatureFlags(projectKey, featureFlagKeys, fromEnv, toEnv, includeState).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`restoreFeatureFlags <projectKey> <featureFlagKeys> <targetEnv> <backupJsonFile> (includeState)`)
.description('restore environment flag settings from a backup file - backup from getFeatureFlags')
.action(function(projectKey, featureFlagKeys, targetEnv, backupJsonFile, includeState) {
ldUtils.flags.restoreFeatureFlags(projectKey, featureFlagKeys, targetEnv, backupJsonFile, includeState).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getCustomRoles')
.description('get all custom roles in account')
.action(function() {
ldUtils.roles.getCustomRoles().then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getCustomRole <customRoleKey>')
.description('get custom role by key')
.action(function(customRoleKey) {
ldUtils.roles.getCustomRole(customRoleKey).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getCustomRoleById <customRoleId>')
.description('get custom role by id')
.action(function(customRoleId) {
ldUtils.roles.getCustomRoleById(customRoleId).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`createCustomRole <customRoleKey> <customRoleName> <customRolePolicyArray> [customRoleDescription]`)
.description('create custom role')
.action(function(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {
customRolePolicyArray = JSON.parse(customRolePolicyArray);
ldUtils.roles.createCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`updateCustomRole <customRoleKey> <customRoleName> <customRolePolicyArray> [customRoleDescription]`)
.description('update custom role')
.action(function(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {
customRolePolicyArray = JSON.parse(customRolePolicyArray);
ldUtils.roles.updateCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription).then(function(response) {
console.log(json.plain(response));
});
});
program
.command(`upsertCustomRole <customRoleKey> <customRoleName> <customRolePolicyArray> [customRoleDescription]`)
.description('create or update custom role')
.action(function(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription) {
customRolePolicyArray = JSON.parse(customRolePolicyArray);
ldUtils.roles.upsertCustomRole(customRoleKey, customRoleName, customRolePolicyArray, customRoleDescription).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('bulkUpsertCustomRoles <roleBulkLoadFile>')
.description('path to a file containing array of role json')
.action(function(roleBulkLoadFile) {
ldUtils.roles.bulkUpsertCustomRoles(roleBulkLoadFile).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('bulkUpsertCustomRoleFolder <roleFolder>')
.description('path to a directory containing multiple files of role json')
.action(function(roleFolder) {
ldUtils.roles.bulkUpsertCustomRoleFolder(roleFolder).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('inviteTeamMember <emailAddress> <initialRoleName>')
.description('Invite a New Team Member')
.action(function(emailAddress, initialRoleName) {
ldUtils.members.inviteTeamMember(emailAddress, initialRoleName).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getTeamMembers')
.description('list all team members in account')
.action(function() {
ldUtils.members.getTeamMembers().then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getTeamMember <memberId>')
.description('get a team member by id')
.action(function(memberId) {
ldUtils.members.getTeamMember(memberId).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getTeamMemberByEmail <emailAddress>')
.description('get a team member by email address')
.action(function(emailAddress) {
ldUtils.members.getTeamMemberByEmail(emailAddress).then(function(response) {
console.log(json.plain(response));
});
});
program
.command('getTeamMemberCustomRoles <emailAddress>')
.description('get a team members custom roles by email address')
.action(function(emailAddress) {
ldUtils.members.getTeamMemberCustomRoles(emailAddress).then(function(response) {
console.log(json.plain(response));
});
});
program.on('--help', function() {
console.log('\n See https://github.com/zotoio/launchdarkly-nodeutils/API.md for examples.\n');
});
if (process.argv.length < 3) {
program.help();
process.exit(1);
}
program
.parse(process.argv);
});