Skip to content

Commit 648e470

Browse files
feat(instance): add project to others resources (#519)
1 parent 64702d7 commit 648e470

File tree

8 files changed

+463
-170
lines changed

8 files changed

+463
-170
lines changed

api/instance/v1/instance_sdk.go

Lines changed: 161 additions & 25 deletions
Large diffs are not rendered by default.

api/instance/v1/instance_sdk_server_test.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ func TestServerUpdate(t *testing.T) {
2828
enableIPv6 = true
2929
bootType = BootTypeLocal
3030
tags = []string{"foo", "bar"}
31-
organization = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
31+
project = "14d2f7ae-9775-414c-9bed-6810e060d500"
3232
)
3333

3434
t.Run("create server", func(t *testing.T) {
3535
// Create server
3636
createServerResponse, err := instanceAPI.CreateServer(&CreateServerRequest{
3737
Zone: zone,
3838
Name: name,
39-
Organization: organization,
39+
Project: &project,
4040
Image: image,
4141
EnableIPv6: enableIPv6,
4242
CommercialType: commercialType,
4343
Tags: tags,
4444
DynamicIPRequired: dynamicIPRequired,
45+
BootType: &bootType,
4546
})
4647
testhelpers.AssertNoError(t, err)
4748
serverID = createServerResponse.Server.ID
@@ -53,7 +54,8 @@ func TestServerUpdate(t *testing.T) {
5354
}
5455

5556
testhelpers.Equals(t, name, createServerResponse.Server.Name)
56-
testhelpers.Equals(t, organization, createServerResponse.Server.Organization)
57+
testhelpers.Equals(t, project, createServerResponse.Server.Project)
58+
testhelpers.Equals(t, project, createServerResponse.Server.Organization)
5759
testhelpers.Equals(t, image, createServerResponse.Server.Image.ID)
5860
testhelpers.Equals(t, enableIPv6, createServerResponse.Server.EnableIPv6)
5961
testhelpers.Equals(t, bootType, createServerResponse.Server.BootType)
@@ -62,6 +64,27 @@ func TestServerUpdate(t *testing.T) {
6264
testhelpers.Equals(t, *dynamicIPRequired, createServerResponse.Server.DynamicIPRequired)
6365
})
6466

67+
t.Run("create server with orga (deprecated)", func(t *testing.T) {
68+
// Create server
69+
createServerResponse, err := instanceAPI.CreateServer(&CreateServerRequest{
70+
Zone: zone,
71+
Name: name,
72+
Organization: &project,
73+
Image: image,
74+
})
75+
testhelpers.AssertNoError(t, err)
76+
77+
testhelpers.Equals(t, project, createServerResponse.Server.Project)
78+
testhelpers.Equals(t, project, createServerResponse.Server.Organization)
79+
80+
// Delete Server
81+
err = instanceAPI.DeleteServer(&DeleteServerRequest{
82+
Zone: zone,
83+
ServerID: createServerResponse.Server.ID,
84+
})
85+
testhelpers.AssertNoError(t, err)
86+
})
87+
6588
t.Run("update server", func(t *testing.T) {
6689
var (
6790
newName = "some_new_name_for_server"
@@ -79,7 +102,8 @@ func TestServerUpdate(t *testing.T) {
79102
testhelpers.AssertNoError(t, err)
80103

81104
// Initial values that are not altered in the above request should remaining the same
82-
testhelpers.Equals(t, organization, updateServerResponse.Server.Organization)
105+
testhelpers.Equals(t, project, updateServerResponse.Server.Project)
106+
testhelpers.Equals(t, project, updateServerResponse.Server.Organization)
83107
testhelpers.Equals(t, image, updateServerResponse.Server.Image.ID)
84108
testhelpers.Equals(t, enableIPv6, updateServerResponse.Server.EnableIPv6)
85109
testhelpers.Equals(t, bootType, updateServerResponse.Server.BootType)

api/instance/v1/instance_utils_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ func TestInstanceHelpers(t *testing.T) {
1818
instanceAPI := NewAPI(client)
1919

2020
var (
21-
serverID string
22-
ipID string
23-
volumeID string
24-
zone = scw.ZoneFrPar1
25-
organization = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
26-
image = "f974feac-abae-4365-b988-8ec7d1cec10d"
27-
reverse = &NullableStringValue{Value: "1.1.1.1"}
28-
nullReverse = &NullableStringValue{Null: true}
21+
serverID string
22+
ipID string
23+
volumeID string
24+
zone = scw.ZoneFrPar1
25+
project = "d429f6a1-c0a6-48cf-8b5a-1f9dfe76ffd3"
26+
image = "f974feac-abae-4365-b988-8ec7d1cec10d"
27+
reverse = &NullableStringValue{Value: "1.1.1.1"}
28+
nullReverse = &NullableStringValue{Null: true}
2929
)
3030

3131
t.Run("create server", func(t *testing.T) {
3232
createServerResponse, err := instanceAPI.CreateServer(&CreateServerRequest{
33-
Zone: zone,
34-
Name: "instance_utils_test",
35-
Organization: organization,
36-
Image: image,
33+
Zone: zone,
34+
Name: "instance_utils_test",
35+
Project: &project,
36+
Image: image,
3737
})
3838
testhelpers.AssertNoError(t, err)
3939
serverID = createServerResponse.Server.ID
@@ -45,8 +45,8 @@ func TestInstanceHelpers(t *testing.T) {
4545
t.Run("test ip related functions", func(t *testing.T) {
4646
// Create IP
4747
createIPResponse, err := instanceAPI.CreateIP(&CreateIPRequest{
48-
Zone: zone,
49-
Organization: &organization,
48+
Zone: zone,
49+
Project: &project,
5050
})
5151
testhelpers.AssertNoError(t, err)
5252
ipID = createIPResponse.IP.ID

api/instance/v1/security_group_utils.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type UpdateSecurityGroupRequest struct {
1818
OutboundDefaultPolicy *SecurityGroupPolicy `json:"outbound_default_policy,omitempty"`
1919
Stateful *bool `json:"stateful,omitempty"`
2020
OrganizationDefault *bool `json:"organization_default,omitempty"`
21+
ProjectDefault *bool `json:"project_default,omitempty"`
2122
}
2223

2324
type UpdateSecurityGroupResponse struct {
@@ -54,7 +55,9 @@ func (s *API) UpdateSecurityGroup(req *UpdateSecurityGroupRequest, opts ...scw.R
5455
Name: getSGResponse.SecurityGroup.Name,
5556
Description: getSGResponse.SecurityGroup.Description,
5657
Organization: getSGResponse.SecurityGroup.Organization,
58+
Project: getSGResponse.SecurityGroup.Project,
5759
OrganizationDefault: getSGResponse.SecurityGroup.OrganizationDefault,
60+
ProjectDefault: getSGResponse.SecurityGroup.ProjectDefault,
5861
OutboundDefaultPolicy: getSGResponse.SecurityGroup.OutboundDefaultPolicy,
5962
InboundDefaultPolicy: getSGResponse.SecurityGroup.InboundDefaultPolicy,
6063
Stateful: getSGResponse.SecurityGroup.Stateful,
@@ -84,6 +87,9 @@ func (s *API) UpdateSecurityGroup(req *UpdateSecurityGroupRequest, opts ...scw.R
8487
if req.OrganizationDefault != nil {
8588
setRequest.OrganizationDefault = *req.OrganizationDefault
8689
}
90+
if req.ProjectDefault != nil {
91+
setRequest.ProjectDefault = *req.ProjectDefault
92+
}
8793

8894
setRes, err := s.setSecurityGroup(setRequest, opts...)
8995
if err != nil {

api/instance/v1/security_group_utils_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
1919
instanceAPI := NewAPI(client)
2020

2121
var (
22-
zone = scw.ZoneFrPar1
23-
organization = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
22+
zone = scw.ZoneFrPar1
23+
project = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
2424
)
2525

2626
createResponse, err := instanceAPI.CreateSecurityGroup(&CreateSecurityGroupRequest{
@@ -30,7 +30,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
3030
Stateful: true,
3131
InboundDefaultPolicy: SecurityGroupPolicyAccept,
3232
OutboundDefaultPolicy: SecurityGroupPolicyDrop,
33-
Organization: organization,
33+
Project: &project,
3434
})
3535

3636
testhelpers.AssertNoError(t, err)
@@ -47,7 +47,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
4747
InboundDefaultPolicy: &drop,
4848
OutboundDefaultPolicy: &accept,
4949
// Keep false here, switch it to true is too dangerous for the one who update the test cassette.
50-
OrganizationDefault: scw.BoolPtr(false),
50+
ProjectDefault: scw.BoolPtr(false),
5151
})
5252

5353
testhelpers.AssertNoError(t, err)
@@ -56,6 +56,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
5656
testhelpers.Equals(t, SecurityGroupPolicyDrop, updateResponse.SecurityGroup.InboundDefaultPolicy)
5757
testhelpers.Equals(t, SecurityGroupPolicyAccept, updateResponse.SecurityGroup.OutboundDefaultPolicy)
5858
testhelpers.Equals(t, false, updateResponse.SecurityGroup.Stateful)
59+
testhelpers.Equals(t, false, updateResponse.SecurityGroup.ProjectDefault)
5960
testhelpers.Equals(t, false, updateResponse.SecurityGroup.OrganizationDefault)
6061

6162
err = instanceAPI.DeleteSecurityGroup(&DeleteSecurityGroupRequest{
@@ -75,8 +76,8 @@ func TestAPI_UpdateSecurityGroupRule(t *testing.T) {
7576
instanceAPI := NewAPI(client)
7677

7778
var (
78-
zone = scw.ZoneFrPar1
79-
organization = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
79+
zone = scw.ZoneFrPar1
80+
project = "b3ba839a-dcf2-4b0a-ac81-fc32370052a0"
8081
)
8182

8283
bootstrap := func(t *testing.T) (*SecurityGroup, *SecurityGroupRule, func()) {
@@ -87,7 +88,7 @@ func TestAPI_UpdateSecurityGroupRule(t *testing.T) {
8788
Stateful: true,
8889
InboundDefaultPolicy: SecurityGroupPolicyAccept,
8990
OutboundDefaultPolicy: SecurityGroupPolicyDrop,
90-
Organization: organization,
91+
Project: &project,
9192
})
9293

9394
testhelpers.AssertNoError(t, err)

api/instance/v1/server_utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAPI_ServerUserData(t *testing.T) {
4949
CommercialType: "DEV1-S",
5050
Name: namegenerator.GetRandomName("srv"),
5151
Image: "f974feac-abae-4365-b988-8ec7d1cec10d",
52-
Organization: "14d2f7ae-9775-414c-9bed-6810e060d500",
52+
Project: scw.StringPtr("14d2f7ae-9775-414c-9bed-6810e060d500"),
5353
})
5454
testhelpers.AssertNoError(t, err)
5555

@@ -88,7 +88,7 @@ func TestAPI_AllServerUserData(t *testing.T) {
8888
CommercialType: "DEV1-S",
8989
Name: namegenerator.GetRandomName("srv"),
9090
Image: "f974feac-abae-4365-b988-8ec7d1cec10d",
91-
Organization: "14d2f7ae-9775-414c-9bed-6810e060d500",
91+
Project: scw.StringPtr("14d2f7ae-9775-414c-9bed-6810e060d500"),
9292
})
9393
testhelpers.AssertNoError(t, err)
9494

0 commit comments

Comments
 (0)