elestio 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +279 -264
- package/bin/elestio.js +5 -5
- package/package.json +42 -42
- package/src/api.js +105 -105
- package/src/cli.js +838 -829
- package/src/commands/access.js +132 -132
- package/src/commands/actions.js +427 -427
- package/src/commands/auth.js +146 -146
- package/src/commands/backups.js +215 -215
- package/src/commands/billing.js +106 -106
- package/src/commands/cicd.js +486 -484
- package/src/commands/projects.js +145 -145
- package/src/commands/services.js +294 -294
- package/src/commands/templates.js +188 -188
- package/src/commands/volumes.js +117 -117
- package/src/config.js +84 -84
- package/src/utils.js +162 -162
package/src/commands/projects.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import { apiRequest } from '../api.js';
|
|
2
|
-
import { formatTable, colors, log, outputJson } from '../utils.js';
|
|
3
|
-
|
|
4
|
-
export async function listProjects(json = false) {
|
|
5
|
-
const response = await apiRequest('/api/projects/getList');
|
|
6
|
-
|
|
7
|
-
if (response.status !== 'OK') {
|
|
8
|
-
throw new Error(response.message || 'Failed to list projects');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const projects = response.data?.projects || [];
|
|
12
|
-
|
|
13
|
-
if (json) {
|
|
14
|
-
outputJson(projects);
|
|
15
|
-
return projects;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (projects.length === 0) {
|
|
19
|
-
log('info', 'No projects found. Create one with: elestio projects create <name>');
|
|
20
|
-
return [];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const columns = [
|
|
24
|
-
{ key: 'projectID', label: 'ID' },
|
|
25
|
-
{ key: 'project_name', label: 'Name' },
|
|
26
|
-
{ key: 'role', label: 'Role' },
|
|
27
|
-
{ key: 'networkCIDR', label: 'Network CIDR' }
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
console.log(`\n${colors.bold}Projects (${projects.length})${colors.reset}\n`);
|
|
31
|
-
console.log(formatTable(projects, columns));
|
|
32
|
-
console.log('');
|
|
33
|
-
return projects;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function createProject(name, description = '', technicalEmails = '') {
|
|
37
|
-
if (!name) throw new Error('Project name is required');
|
|
38
|
-
|
|
39
|
-
const response = await apiRequest('/api/projects/addProject', 'POST', {
|
|
40
|
-
name, description, technicalEmails
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
if (response.status !== 'OK') {
|
|
44
|
-
throw new Error(response.message || 'Failed to create project');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
log('success', `Project "${name}" created`);
|
|
48
|
-
return response;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function editProject(projectId, name, description, technicalEmails) {
|
|
52
|
-
const body = { projectId: String(projectId) };
|
|
53
|
-
if (name) body.name = name;
|
|
54
|
-
if (description !== undefined) body.description = description;
|
|
55
|
-
if (technicalEmails !== undefined) body.technicalEmails = technicalEmails;
|
|
56
|
-
|
|
57
|
-
const response = await apiRequest('/api/projects/editProject', 'PUT', body);
|
|
58
|
-
|
|
59
|
-
if (response.status !== 'OK') {
|
|
60
|
-
throw new Error(response.message || 'Failed to edit project');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
log('success', `Project ${projectId} updated`);
|
|
64
|
-
return response;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export async function deleteProject(projectId, force = false) {
|
|
68
|
-
if (!force) throw new Error('Deleting a project requires --force flag');
|
|
69
|
-
|
|
70
|
-
const response = await apiRequest('/api/projects/deleteProject', 'DELETE', {
|
|
71
|
-
projectId: String(projectId)
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
if (response.status !== 'OK') {
|
|
75
|
-
throw new Error(response.message || 'Failed to delete project');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
log('success', `Project ${projectId} deleted`);
|
|
79
|
-
return response;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function listMembers(projectId, json = false) {
|
|
83
|
-
const response = await apiRequest('/api/projects/getMembersList', 'GET', {
|
|
84
|
-
projectId: String(projectId)
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
let members = [];
|
|
88
|
-
if (Array.isArray(response)) {
|
|
89
|
-
members = response;
|
|
90
|
-
} else if (response.status === 'OK') {
|
|
91
|
-
members = response.data?.projectMembers || response.data?.members || [];
|
|
92
|
-
} else if (response.status === 'KO' || response.message) {
|
|
93
|
-
throw new Error(response.message || 'Failed to list members');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (json) {
|
|
97
|
-
outputJson(members);
|
|
98
|
-
return members;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (members.length === 0) {
|
|
102
|
-
log('info', 'No members found');
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const columns = [
|
|
107
|
-
{ key: 'userID', label: 'User ID' },
|
|
108
|
-
{ key: 'email', label: 'Email' },
|
|
109
|
-
{ key: 'role', label: 'Role' }
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
console.log(`\n${colors.bold}Project Members${colors.reset}\n`);
|
|
113
|
-
console.log(formatTable(members, columns));
|
|
114
|
-
console.log('');
|
|
115
|
-
return members;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export async function addMember(projectId, email, role = 'admin') {
|
|
119
|
-
const response = await apiRequest('/api/projects/addMember', 'POST', {
|
|
120
|
-
projectId: String(projectId),
|
|
121
|
-
targetEmail: email,
|
|
122
|
-
role
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
if (response.status !== 'OK') {
|
|
126
|
-
throw new Error(response.message || 'Failed to add member');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
log('success', `Added ${email} as ${role} to project ${projectId}`);
|
|
130
|
-
return response;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function removeMember(projectId, memberId) {
|
|
134
|
-
const response = await apiRequest('/api/projects/deleteMember', 'DELETE', {
|
|
135
|
-
projectId: String(projectId),
|
|
136
|
-
targetId: String(memberId)
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
if (response.status !== 'OK' && response.status !== undefined) {
|
|
140
|
-
throw new Error(response.message || 'Failed to remove member');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
log('success', `Removed member ${memberId} from project ${projectId}`);
|
|
144
|
-
return response;
|
|
145
|
-
}
|
|
1
|
+
import { apiRequest } from '../api.js';
|
|
2
|
+
import { formatTable, colors, log, outputJson } from '../utils.js';
|
|
3
|
+
|
|
4
|
+
export async function listProjects(json = false) {
|
|
5
|
+
const response = await apiRequest('/api/projects/getList');
|
|
6
|
+
|
|
7
|
+
if (response.status !== 'OK') {
|
|
8
|
+
throw new Error(response.message || 'Failed to list projects');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const projects = response.data?.projects || [];
|
|
12
|
+
|
|
13
|
+
if (json) {
|
|
14
|
+
outputJson(projects);
|
|
15
|
+
return projects;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (projects.length === 0) {
|
|
19
|
+
log('info', 'No projects found. Create one with: elestio projects create <name>');
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const columns = [
|
|
24
|
+
{ key: 'projectID', label: 'ID' },
|
|
25
|
+
{ key: 'project_name', label: 'Name' },
|
|
26
|
+
{ key: 'role', label: 'Role' },
|
|
27
|
+
{ key: 'networkCIDR', label: 'Network CIDR' }
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
console.log(`\n${colors.bold}Projects (${projects.length})${colors.reset}\n`);
|
|
31
|
+
console.log(formatTable(projects, columns));
|
|
32
|
+
console.log('');
|
|
33
|
+
return projects;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function createProject(name, description = '', technicalEmails = '') {
|
|
37
|
+
if (!name) throw new Error('Project name is required');
|
|
38
|
+
|
|
39
|
+
const response = await apiRequest('/api/projects/addProject', 'POST', {
|
|
40
|
+
name, description, technicalEmails
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
if (response.status !== 'OK') {
|
|
44
|
+
throw new Error(response.message || 'Failed to create project');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
log('success', `Project "${name}" created`);
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function editProject(projectId, name, description, technicalEmails) {
|
|
52
|
+
const body = { projectId: String(projectId) };
|
|
53
|
+
if (name) body.name = name;
|
|
54
|
+
if (description !== undefined) body.description = description;
|
|
55
|
+
if (technicalEmails !== undefined) body.technicalEmails = technicalEmails;
|
|
56
|
+
|
|
57
|
+
const response = await apiRequest('/api/projects/editProject', 'PUT', body);
|
|
58
|
+
|
|
59
|
+
if (response.status !== 'OK') {
|
|
60
|
+
throw new Error(response.message || 'Failed to edit project');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log('success', `Project ${projectId} updated`);
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function deleteProject(projectId, force = false) {
|
|
68
|
+
if (!force) throw new Error('Deleting a project requires --force flag');
|
|
69
|
+
|
|
70
|
+
const response = await apiRequest('/api/projects/deleteProject', 'DELETE', {
|
|
71
|
+
projectId: String(projectId)
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (response.status !== 'OK') {
|
|
75
|
+
throw new Error(response.message || 'Failed to delete project');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
log('success', `Project ${projectId} deleted`);
|
|
79
|
+
return response;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export async function listMembers(projectId, json = false) {
|
|
83
|
+
const response = await apiRequest('/api/projects/getMembersList', 'GET', {
|
|
84
|
+
projectId: String(projectId)
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
let members = [];
|
|
88
|
+
if (Array.isArray(response)) {
|
|
89
|
+
members = response;
|
|
90
|
+
} else if (response.status === 'OK') {
|
|
91
|
+
members = response.data?.projectMembers || response.data?.members || [];
|
|
92
|
+
} else if (response.status === 'KO' || response.message) {
|
|
93
|
+
throw new Error(response.message || 'Failed to list members');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (json) {
|
|
97
|
+
outputJson(members);
|
|
98
|
+
return members;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (members.length === 0) {
|
|
102
|
+
log('info', 'No members found');
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const columns = [
|
|
107
|
+
{ key: 'userID', label: 'User ID' },
|
|
108
|
+
{ key: 'email', label: 'Email' },
|
|
109
|
+
{ key: 'role', label: 'Role' }
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
console.log(`\n${colors.bold}Project Members${colors.reset}\n`);
|
|
113
|
+
console.log(formatTable(members, columns));
|
|
114
|
+
console.log('');
|
|
115
|
+
return members;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function addMember(projectId, email, role = 'admin') {
|
|
119
|
+
const response = await apiRequest('/api/projects/addMember', 'POST', {
|
|
120
|
+
projectId: String(projectId),
|
|
121
|
+
targetEmail: email,
|
|
122
|
+
role
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (response.status !== 'OK') {
|
|
126
|
+
throw new Error(response.message || 'Failed to add member');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
log('success', `Added ${email} as ${role} to project ${projectId}`);
|
|
130
|
+
return response;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export async function removeMember(projectId, memberId) {
|
|
134
|
+
const response = await apiRequest('/api/projects/deleteMember', 'DELETE', {
|
|
135
|
+
projectId: String(projectId),
|
|
136
|
+
targetId: String(memberId)
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
if (response.status !== 'OK' && response.status !== undefined) {
|
|
140
|
+
throw new Error(response.message || 'Failed to remove member');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
log('success', `Removed member ${memberId} from project ${projectId}`);
|
|
144
|
+
return response;
|
|
145
|
+
}
|