Skip to content

Commit 3fed6cb

Browse files
committed
feat(cli): migrate cloud project list/get to API v2
Signed-off-by: olivier dubo <olivier.dubo@ovhcloud.com>
1 parent f9520c1 commit 3fed6cb

4 files changed

Lines changed: 45 additions & 160 deletions

File tree

internal/assets/api-schemas/cloud_v2.json

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,52 +1248,6 @@
12481248
}
12491249
],
12501250
"x-expanded-response": "PublicCloudProjectProjectAsyncWithIAM"
1251-
},
1252-
"post": {
1253-
"summary": "Create a new cloud project",
1254-
"security": [
1255-
{
1256-
"oAuth2AuthCode": []
1257-
}
1258-
],
1259-
"requestBody": {
1260-
"required": true,
1261-
"content": {
1262-
"application/json": {
1263-
"schema": {
1264-
"$ref": "#/components/schemas/publicCloud.project.ProjectCreation"
1265-
}
1266-
}
1267-
}
1268-
},
1269-
"responses": {
1270-
"200": {
1271-
"description": "successful operation",
1272-
"content": {
1273-
"application/json": {
1274-
"schema": {
1275-
"$ref": "#/components/schemas/publicCloud.project.ProjectAsync"
1276-
}
1277-
}
1278-
}
1279-
}
1280-
},
1281-
"x-badges": [
1282-
{
1283-
"color": "orange",
1284-
"label": "Internal use only"
1285-
}
1286-
],
1287-
"x-iam-actions": [
1288-
{
1289-
"name": "publicCloudProject:apiovh:create",
1290-
"required": true
1291-
},
1292-
{
1293-
"name": "billingAccount:apiovh:subscription/publicCloudProject/create",
1294-
"required": true
1295-
}
1296-
]
12971251
}
12981252
},
12991253
"/publicCloud/project/{projectId}": {
@@ -1339,59 +1293,6 @@
13391293
"required": true
13401294
}
13411295
]
1342-
},
1343-
"put": {
1344-
"summary": "Update an existing cloud project",
1345-
"security": [
1346-
{
1347-
"oAuth2AuthCode": []
1348-
}
1349-
],
1350-
"parameters": [
1351-
{
1352-
"in": "path",
1353-
"name": "projectId",
1354-
"description": "Project ID",
1355-
"required": true,
1356-
"schema": {
1357-
"type": "string"
1358-
}
1359-
}
1360-
],
1361-
"requestBody": {
1362-
"required": true,
1363-
"content": {
1364-
"application/json": {
1365-
"schema": {
1366-
"$ref": "#/components/schemas/publicCloud.project.ProjectCreation"
1367-
}
1368-
}
1369-
}
1370-
},
1371-
"responses": {
1372-
"200": {
1373-
"description": "successful operation",
1374-
"content": {
1375-
"application/json": {
1376-
"schema": {
1377-
"$ref": "#/components/schemas/publicCloud.project.ProjectAsync"
1378-
}
1379-
}
1380-
}
1381-
}
1382-
},
1383-
"x-badges": [
1384-
{
1385-
"color": "orange",
1386-
"label": "Internal use only"
1387-
}
1388-
],
1389-
"x-iam-actions": [
1390-
{
1391-
"name": "publicCloudProject:apiovh:edit",
1392-
"required": true
1393-
}
1394-
]
13951296
}
13961297
},
13971298
"/publicCloud/project/{projectId}/rancher": {

internal/cmd/cloud_project_test.go

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,39 @@ import (
1212

1313
// TestCloudProjectListCmd tests the "cloud project list" command
1414
func (ms *MockSuite) TestCloudProjectListCmd(assert, require *td.T) {
15-
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project",
16-
httpmock.NewStringResponder(200, `["project-1", "project-2"]`).Once())
17-
18-
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-1",
19-
httpmock.NewStringResponder(200, `{
20-
"project_id": "project-1",
21-
"projectName": "Test Project 1",
22-
"status": "ok",
23-
"description": "First test project"
24-
}`).Once())
25-
26-
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-2",
27-
httpmock.NewStringResponder(200, `{
28-
"project_id": "project-2",
29-
"projectName": "Test Project 2",
30-
"status": "ok",
31-
"description": "Second test project"
32-
}`).Once())
15+
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v2/publicCloud/project",
16+
httpmock.NewStringResponder(200, `[
17+
{
18+
"id": "project-1",
19+
"resourceStatus": "READY",
20+
"currentState": {"name": "Test Project 1", "mode": "standard"}
21+
},
22+
{
23+
"id": "project-2",
24+
"resourceStatus": "READY",
25+
"currentState": {"name": "Test Project 2", "mode": "discovery"}
26+
}
27+
]`).Once())
3328

3429
out, err := cmd.Execute("cloud", "project", "list")
3530

3631
require.CmpNoError(err)
37-
assert.String(out, `
38-
┌────────────┬────────────────┬────────┬─────────────────────┐
39-
│ project_id │ projectName │ status │ description │
40-
├────────────┼────────────────┼────────┼─────────────────────┤
41-
│ project-1 │ Test Project 1 │ ok │ First test project │
42-
│ project-2 │ Test Project 2 │ ok │ Second test project │
43-
└────────────┴────────────────┴────────┴─────────────────────┘
44-
💡 Use option -o json or -o yaml to get the raw output with all information`[1:])
32+
assert.Cmp(out, td.Contains("project-1"))
33+
assert.Cmp(out, td.Contains("Test Project 1"))
34+
assert.Cmp(out, td.Contains("project-2"))
35+
assert.Cmp(out, td.Contains("discovery"))
4536
}
4637

4738
// TestCloudProjectListCmdAlias tests the "cloud project ls" command alias
4839
func (ms *MockSuite) TestCloudProjectListCmdAlias(assert, require *td.T) {
49-
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project",
50-
httpmock.NewStringResponder(200, `["project-1"]`).Once())
51-
52-
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-1",
53-
httpmock.NewStringResponder(200, `{
54-
"project_id": "project-1",
55-
"projectName": "Test Project",
56-
"status": "ok",
57-
"description": "Test project"
58-
}`).Once())
40+
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v2/publicCloud/project",
41+
httpmock.NewStringResponder(200, `[
42+
{
43+
"id": "project-1",
44+
"resourceStatus": "READY",
45+
"currentState": {"name": "Test Project", "mode": "standard"}
46+
}
47+
]`).Once())
5948

6049
out, err := cmd.Execute("cloud", "project", "ls")
6150

@@ -65,16 +54,15 @@ func (ms *MockSuite) TestCloudProjectListCmdAlias(assert, require *td.T) {
6554

6655
// TestCloudProjectGetCmd tests the "cloud project get" command
6756
func (ms *MockSuite) TestCloudProjectGetCmd(assert, require *td.T) {
68-
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-123",
57+
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v2/publicCloud/project/project-123",
6958
httpmock.NewStringResponder(200, `{
70-
"project_id": "project-123",
71-
"projectName": "My Cloud Project",
72-
"status": "ok",
73-
"description": "Production cloud project",
74-
"access": "full",
75-
"unleash": false,
76-
"manualQuota": false,
77-
"creationDate": "2023-01-15T10:30:00Z",
59+
"id": "project-123",
60+
"resourceStatus": "READY",
61+
"createdAt": "2023-01-15T10:30:00Z",
62+
"currentState": {
63+
"name": "My Cloud Project",
64+
"mode": "standard"
65+
},
7866
"iam": {
7967
"urn": "urn:v1:eu:resource:cloudProject:project-123"
8068
}
@@ -85,7 +73,7 @@ func (ms *MockSuite) TestCloudProjectGetCmd(assert, require *td.T) {
8573
require.CmpNoError(err)
8674
assert.Cmp(out, td.Contains("project-123"))
8775
assert.Cmp(out, td.Contains("My Cloud Project"))
88-
assert.Cmp(out, td.Contains("Production cloud project"))
76+
assert.Cmp(out, td.Contains("standard"))
8977
}
9078

9179
// TestCloudProjectEditCmd tests the "cloud project edit" command

internal/services/cloud/cloud_project.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
var (
25-
cloudprojectColumnsToDisplay = []string{"project_id", "projectName", "status", "description"}
25+
cloudprojectColumnsToDisplay = []string{"id", "currentState.name name", "currentState.mode mode", "resourceStatus"}
2626

2727
// Cloud project set by CLI flags
2828
CloudProject string
@@ -44,11 +44,11 @@ var (
4444
)
4545

4646
func ListCloudProject(_ *cobra.Command, _ []string) {
47-
common.ManageListRequest("/v1/cloud/project", "", cloudprojectColumnsToDisplay, flags.GenericFilters)
47+
common.ManageListRequestNoExpand("/v2/publicCloud/project", cloudprojectColumnsToDisplay, flags.GenericFilters)
4848
}
4949

5050
func GetCloudProject(_ *cobra.Command, args []string) {
51-
common.ManageObjectRequest("/v1/cloud/project", args[0], cloudProjectTemplate)
51+
common.ManageObjectRequest("/v2/publicCloud/project", args[0], cloudProjectTemplate)
5252
}
5353

5454
func EditCloudProject(cmd *cobra.Command, args []string) {
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
🚀 Cloud Project {{.ServiceName}}
22
=======
33

4-
_{{index .Result "description"}}_
5-
64
## General information
75

8-
**Project name**: {{index .Result "projectName"}}
9-
**Status**: {{index .Result "status"}}
10-
**Access**: {{index .Result "access"}}
11-
**Unleash**: {{index .Result "unleash"}}
12-
**Manual quota**: {{index .Result "manualQuota"}}
13-
**Creation date**: {{index .Result "creationDate"}}
14-
{{if index .Result "expiration"}}**Expiration**: {{index .Result "expiration"}}{{end}}
6+
**Name**: {{index .Result "currentState" "name"}}
7+
**Mode**: {{index .Result "currentState" "mode"}}
8+
**Status**: {{index .Result "resourceStatus"}}
9+
**Creation date**: {{index .Result "createdAt"}}
10+
**Update date**: {{index .Result "updatedAt"}}
1511

16-
## IAM information
12+
{{if index .Result "iam"}}## IAM information
1713

1814
**URN**: {{index .Result "iam" "urn"}}
1915
{{if index .Result "iam" "tags"}}
@@ -22,6 +18,6 @@ _{{index .Result "description"}}_
2218
| --- | --- |
2319
{{ range $key, $value := (index .Result "iam" "tags") }}| {{$key}} | {{$value}} |
2420
{{end}}
25-
{{end}}
21+
{{end}}{{end}}
2622

27-
💡 Use option -o json or -o yaml to get the raw output with all information
23+
💡 Use option -o json or -o yaml to get the raw output with all information

0 commit comments

Comments
 (0)