Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 0 additions & 99 deletions internal/assets/api-schemas/cloud_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1248,52 +1248,6 @@
}
],
"x-expanded-response": "PublicCloudProjectProjectAsyncWithIAM"
},
"post": {
"summary": "Create a new cloud project",
"security": [
{
"oAuth2AuthCode": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/publicCloud.project.ProjectCreation"
}
}
}
},
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/publicCloud.project.ProjectAsync"
}
}
}
}
},
"x-badges": [
{
"color": "orange",
"label": "Internal use only"
}
],
"x-iam-actions": [
{
"name": "publicCloudProject:apiovh:create",
"required": true
},
{
"name": "billingAccount:apiovh:subscription/publicCloudProject/create",
"required": true
}
]
}
},
"/publicCloud/project/{projectId}": {
Expand Down Expand Up @@ -1339,59 +1293,6 @@
"required": true
}
]
},
"put": {
"summary": "Update an existing cloud project",
"security": [
{
"oAuth2AuthCode": []
}
],
"parameters": [
{
"in": "path",
"name": "projectId",
"description": "Project ID",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/publicCloud.project.ProjectCreation"
}
}
}
},
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/publicCloud.project.ProjectAsync"
}
}
}
}
},
"x-badges": [
{
"color": "orange",
"label": "Internal use only"
}
],
"x-iam-actions": [
{
"name": "publicCloudProject:apiovh:edit",
"required": true
}
]
}
},
"/publicCloud/project/{projectId}/rancher": {
Expand Down
80 changes: 34 additions & 46 deletions internal/cmd/cloud_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,39 @@ import (

// TestCloudProjectListCmd tests the "cloud project list" command
func (ms *MockSuite) TestCloudProjectListCmd(assert, require *td.T) {
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project",
httpmock.NewStringResponder(200, `["project-1", "project-2"]`).Once())

httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-1",
httpmock.NewStringResponder(200, `{
"project_id": "project-1",
"projectName": "Test Project 1",
"status": "ok",
"description": "First test project"
}`).Once())

httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-2",
httpmock.NewStringResponder(200, `{
"project_id": "project-2",
"projectName": "Test Project 2",
"status": "ok",
"description": "Second test project"
}`).Once())
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v2/publicCloud/project",
httpmock.NewStringResponder(200, `[
{
"id": "project-1",
"resourceStatus": "READY",
"currentState": {"name": "Test Project 1", "mode": "standard"}
},
{
"id": "project-2",
"resourceStatus": "READY",
"currentState": {"name": "Test Project 2", "mode": "discovery"}
}
]`).Once())

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

require.CmpNoError(err)
assert.String(out, `
┌────────────┬────────────────┬────────┬─────────────────────┐
│ project_id │ projectName │ status │ description │
├────────────┼────────────────┼────────┼─────────────────────┤
│ project-1 │ Test Project 1 │ ok │ First test project │
│ project-2 │ Test Project 2 │ ok │ Second test project │
└────────────┴────────────────┴────────┴─────────────────────┘
💡 Use option -o json or -o yaml to get the raw output with all information`[1:])
assert.Cmp(out, td.Contains("project-1"))
assert.Cmp(out, td.Contains("Test Project 1"))
assert.Cmp(out, td.Contains("project-2"))
assert.Cmp(out, td.Contains("discovery"))
}

// TestCloudProjectListCmdAlias tests the "cloud project ls" command alias
func (ms *MockSuite) TestCloudProjectListCmdAlias(assert, require *td.T) {
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project",
httpmock.NewStringResponder(200, `["project-1"]`).Once())

httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-1",
httpmock.NewStringResponder(200, `{
"project_id": "project-1",
"projectName": "Test Project",
"status": "ok",
"description": "Test project"
}`).Once())
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v2/publicCloud/project",
httpmock.NewStringResponder(200, `[
{
"id": "project-1",
"resourceStatus": "READY",
"currentState": {"name": "Test Project", "mode": "standard"}
}
]`).Once())

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

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

// TestCloudProjectGetCmd tests the "cloud project get" command
func (ms *MockSuite) TestCloudProjectGetCmd(assert, require *td.T) {
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v1/cloud/project/project-123",
httpmock.RegisterResponder("GET", "https://eu.api.ovh.com/v2/publicCloud/project/project-123",
httpmock.NewStringResponder(200, `{
"project_id": "project-123",
"projectName": "My Cloud Project",
"status": "ok",
"description": "Production cloud project",
"access": "full",
"unleash": false,
"manualQuota": false,
"creationDate": "2023-01-15T10:30:00Z",
"id": "project-123",
"resourceStatus": "READY",
"createdAt": "2023-01-15T10:30:00Z",
"currentState": {
"name": "My Cloud Project",
"mode": "standard"
},
"iam": {
"urn": "urn:v1:eu:resource:cloudProject:project-123"
}
Expand All @@ -85,7 +73,7 @@ func (ms *MockSuite) TestCloudProjectGetCmd(assert, require *td.T) {
require.CmpNoError(err)
assert.Cmp(out, td.Contains("project-123"))
assert.Cmp(out, td.Contains("My Cloud Project"))
assert.Cmp(out, td.Contains("Production cloud project"))
assert.Cmp(out, td.Contains("standard"))
}

// TestCloudProjectEditCmd tests the "cloud project edit" command
Expand Down
6 changes: 3 additions & 3 deletions internal/services/cloud/cloud_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

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

// Cloud project set by CLI flags
CloudProject string
Expand All @@ -44,11 +44,11 @@ var (
)

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

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

func EditCloudProject(cmd *cobra.Command, args []string) {
Expand Down
20 changes: 8 additions & 12 deletions internal/services/cloud/templates/cloud_project.tmpl
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
🚀 Cloud Project {{.ServiceName}}
=======

_{{index .Result "description"}}_

## General information

**Project name**: {{index .Result "projectName"}}
**Status**: {{index .Result "status"}}
**Access**: {{index .Result "access"}}
**Unleash**: {{index .Result "unleash"}}
**Manual quota**: {{index .Result "manualQuota"}}
**Creation date**: {{index .Result "creationDate"}}
{{if index .Result "expiration"}}**Expiration**: {{index .Result "expiration"}}{{end}}
**Name**: {{index .Result "currentState" "name"}}
**Mode**: {{index .Result "currentState" "mode"}}
**Status**: {{index .Result "resourceStatus"}}
**Creation date**: {{index .Result "createdAt"}}
**Update date**: {{index .Result "updatedAt"}}

## IAM information
{{if index .Result "iam"}}## IAM information

**URN**: {{index .Result "iam" "urn"}}
{{if index .Result "iam" "tags"}}
Expand All @@ -22,6 +18,6 @@ _{{index .Result "description"}}_
| --- | --- |
{{ range $key, $value := (index .Result "iam" "tags") }}| {{$key}} | {{$value}} |
{{end}}
{{end}}
{{end}}{{end}}

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