Skip to content

Commit c9b6927

Browse files
committed
refactor: Use bundle instead of sdk-go-container-registry
1 parent 25ab0b6 commit c9b6927

File tree

80 files changed

+18222
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+18222
-125
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/iancoleman/strcase v0.3.0
1818
github.com/ionos-cloud/sdk-go-api-gateway v1.0.0
1919
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0
20+
github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2 v2.0.2
2021
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1
2122
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0
2223
github.com/ionos-cloud/sdk-go-bundle/products/vpn/v2 v2.0.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ github.com/ionos-cloud/sdk-go-api-gateway v1.0.0 h1:T+JzarV1Iw7NjWQfEuv5bESnHoCL
116116
github.com/ionos-cloud/sdk-go-api-gateway v1.0.0/go.mod h1:TkSlamP+qKRT8cgBaZEN8rawanVluOR0dXbXXdmmwTY=
117117
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0 h1:8fRICa4i+GJHrCgnLe8t3uwfahkg7pcDDwoLkH3B2Xc=
118118
github.com/ionos-cloud/sdk-go-bundle/products/cdn/v2 v2.1.0/go.mod h1:BF6R+j1GdJEMImxkeh32qjIVWqsBfgi6VgyfsY5ezIA=
119+
github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2 v2.0.2 h1:+f8+Gfnm/a1ZkBpw643sUDG7Zin8Paj7PPHFHLc9XbY=
120+
github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2 v2.0.2/go.mod h1:MqxTZ40QJv2yq2qlNAzIABRwCKV4oDf7tRSbtwQIk0g=
119121
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1 h1:GXxdNKl7haQnHO1QewZeXazur5+LDCpHqvP+nNObGaA=
120122
github.com/ionos-cloud/sdk-go-bundle/products/logging/v2 v2.1.1/go.mod h1:N0ifRq3ENqGg6qht1WPrVgSkcavPS5SRWlNfkHUZbfQ=
121123
github.com/ionos-cloud/sdk-go-bundle/products/monitoring/v2 v2.0.0 h1:gVh+jd0o8ROtJLWqUB6/VU8vSLdj/kRYAz/qbMO7z7I=

ionoscloud/data_source_container_registry.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12-
cr "github.com/ionos-cloud/sdk-go-container-registry"
12+
cr "github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2"
1313

1414
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
1515
crService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/containerregistry"
@@ -159,18 +159,17 @@ func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData
159159
return diags
160160
}
161161

162-
results = *registries.Items
162+
results = registries.Items
163163
if nameOk {
164164
partialMatch := d.Get("partial_match").(bool)
165165

166166
log.Printf("[INFO] Using data source for container registry by name with partial_match %t and name: %s", partialMatch, name)
167167

168-
if registries.Items != nil && len(*registries.Items) > 0 {
168+
if registries.Items != nil && len(registries.Items) > 0 {
169169
var registriesByName []cr.RegistryResponse
170-
for _, registryItem := range *registries.Items {
171-
if registryItem.Properties != nil && registryItem.Properties.Name != nil &&
172-
(partialMatch && strings.Contains(*registryItem.Properties.Name, name) ||
173-
!partialMatch && strings.EqualFold(*registryItem.Properties.Name, name)) {
170+
for _, registryItem := range registries.Items {
171+
if partialMatch && strings.Contains(registryItem.Properties.Name, name) ||
172+
!partialMatch && strings.EqualFold(registryItem.Properties.Name, name) {
174173
registriesByName = append(registriesByName, registryItem)
175174
}
176175
}
@@ -185,7 +184,7 @@ func dataSourceContainerRegistryRead(ctx context.Context, d *schema.ResourceData
185184
if locationOk {
186185
var registriesByLocation []cr.RegistryResponse
187186
for _, registryItem := range results {
188-
if registryItem.Properties != nil && registryItem.Properties.Name != nil && strings.EqualFold(*registryItem.Properties.Location, location) {
187+
if strings.EqualFold(registryItem.Properties.Location, location) {
189188
registriesByLocation = append(registriesByLocation, registryItem)
190189
}
191190
}

ionoscloud/data_source_container_registry_token.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12-
cr "github.com/ionos-cloud/sdk-go-container-registry"
12+
cr "github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2"
1313

1414
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
1515
crService "github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services/containerregistry"
@@ -129,11 +129,10 @@ func dataSourceContainerRegistryTokenRead(ctx context.Context, d *schema.Resourc
129129

130130
log.Printf("[INFO] Using data source for container token by name with partial_match %t and name: %s", partialMatch, name)
131131

132-
if tokens.Items != nil && len(*tokens.Items) > 0 {
133-
for _, tokenItem := range *tokens.Items {
134-
if tokenItem.Properties != nil && tokenItem.Properties.Name != nil &&
135-
(partialMatch && strings.Contains(*tokenItem.Properties.Name, name) ||
136-
!partialMatch && strings.EqualFold(*tokenItem.Properties.Name, name)) {
132+
if tokens.Items != nil && len(tokens.Items) > 0 {
133+
for _, tokenItem := range tokens.Items {
134+
if partialMatch && strings.Contains(tokenItem.Properties.Name, name) ||
135+
!partialMatch && strings.EqualFold(tokenItem.Properties.Name, name) {
137136
results = append(results, tokenItem)
138137
}
139138
}
@@ -151,11 +150,8 @@ func dataSourceContainerRegistryTokenRead(ctx context.Context, d *schema.Resourc
151150
if token.Id != nil {
152151
d.SetId(*token.Id)
153152
}
154-
if token.Properties == nil {
155-
return diag.FromErr(fmt.Errorf("no token properties found with the specified id = %s", *token.Id))
156-
}
157153

158-
if err := crService.SetTokenData(d, *token.Properties); err != nil {
154+
if err := crService.SetTokenData(d, token.Properties); err != nil {
159155
return diag.FromErr(err)
160156
}
161157

ionoscloud/resource_container_registry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1313
"github.com/hashicorp/terraform-plugin-testing/terraform"
14-
cr "github.com/ionos-cloud/sdk-go-container-registry"
14+
cr "github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2"
1515
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/services"
1616
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
1717
)

ionoscloud/resource_container_registry_token.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,13 @@ func resourceContainerRegistryTokenCreate(ctx context.Context, d *schema.Resourc
117117

118118
d.SetId(*registryTokenResponse.Id)
119119

120-
if registryTokenResponse.Properties == nil {
121-
return diag.FromErr(fmt.Errorf("no token properties found with the specified id = %s", *registryTokenResponse.Id))
122-
}
123-
124120
if fileStr != "" {
125-
if err := utils.WriteToFile(fileStr, *registryTokenResponse.Properties.Credentials.Password); err != nil {
121+
if err := utils.WriteToFile(fileStr, registryTokenResponse.Properties.Credentials.Password); err != nil {
126122
return diag.FromErr(err)
127123
}
128124
}
129125

130-
if err = crService.SetTokenData(d, *registryTokenResponse.Properties); err != nil {
126+
if err = crService.SetTokenData(d, registryTokenResponse.Properties); err != nil {
131127
return diag.FromErr(err)
132128
}
133129
return nil
@@ -152,11 +148,7 @@ func resourceContainerRegistryTokenRead(ctx context.Context, d *schema.ResourceD
152148

153149
log.Printf("[INFO] Successfully retrieved registry token %s: %+v", d.Id(), registryToken)
154150

155-
if registryToken.Properties == nil {
156-
return diag.FromErr(fmt.Errorf("no token properties found with the specified id = %s", *registryToken.Id))
157-
}
158-
159-
if err := crService.SetTokenData(d, *registryToken.Properties); err != nil {
151+
if err := crService.SetTokenData(d, registryToken.Properties); err != nil {
160152
return diag.FromErr(err)
161153
}
162154

@@ -223,11 +215,8 @@ func resourceContainerRegistryTokenImport(ctx context.Context, d *schema.Resourc
223215
if registryToken.Id != nil {
224216
d.SetId(*registryToken.Id)
225217
}
226-
if registryToken.Properties == nil {
227-
return nil, fmt.Errorf("no token properties found with the specified id = %s", *registryToken.Id)
228-
}
229218

230-
if err := crService.SetTokenData(d, *registryToken.Properties); err != nil {
219+
if err := crService.SetTokenData(d, registryToken.Properties); err != nil {
231220
return nil, err
232221
}
233222

ionoscloud/resource_container_registry_token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1818
"github.com/hashicorp/terraform-plugin-testing/terraform"
19-
cr "github.com/ionos-cloud/sdk-go-container-registry"
19+
cr "github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2"
2020
)
2121

2222
func TestAccContainerRegistryTokenBasic(t *testing.T) {

services/containerregistry/client.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,33 @@ package containerregistry
33
import (
44
"fmt"
55
"net/http"
6-
"os"
76
"runtime"
87

98
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils/constant"
109

1110
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
12-
cr "github.com/ionos-cloud/sdk-go-container-registry"
11+
cr "github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2"
12+
"github.com/ionos-cloud/sdk-go-bundle/shared"
1313

1414
"github.com/ionos-cloud/terraform-provider-ionoscloud/v6/utils"
1515
)
1616

1717
type Client struct {
18-
sdkClient *cr.APIClient
18+
sdkClient cr.APIClient
1919
}
2020

2121
func NewClient(username, password, token, url, version, terraformVersion string, insecure bool) *Client {
22-
newConfigRegistry := cr.NewConfiguration(username, password, token, url)
22+
newConfigRegistry := shared.NewConfiguration(username, password, token, url)
2323

24-
if os.Getenv(constant.IonosDebug) != "" {
25-
newConfigRegistry.Debug = true
26-
}
2724
newConfigRegistry.MaxRetries = constant.MaxRetries
2825
newConfigRegistry.MaxWaitTime = constant.MaxWaitTime
29-
30-
newConfigRegistry.HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}
3126
newConfigRegistry.UserAgent = fmt.Sprintf(
3227
"terraform-provider/%s_ionos-cloud-sdk-go-container-cr/%s_hashicorp-terraform/%s_terraform-plugin-sdk/%s_os/%s_arch/%s",
3328
version, cr.Version, terraformVersion, meta.SDKVersionString(), runtime.GOOS, runtime.GOARCH)
34-
35-
return &Client{
36-
sdkClient: cr.NewAPIClient(newConfigRegistry),
29+
client := &Client{
30+
sdkClient: *cr.NewAPIClient(newConfigRegistry),
3731
}
32+
client.sdkClient.GetConfig().HTTPClient = &http.Client{Transport: utils.CreateTransport(insecure)}
33+
34+
return client
3835
}

services/containerregistry/locations.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"github.com/google/uuid"
88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
cr "github.com/ionos-cloud/sdk-go-container-registry"
10+
cr "github.com/ionos-cloud/sdk-go-bundle/products/containerregistry/v2"
11+
"github.com/ionos-cloud/sdk-go-bundle/shared"
1112
)
1213

13-
func (c *Client) GetAllLocations(ctx context.Context) (cr.LocationsResponse, *cr.APIResponse, error) {
14+
func (c *Client) GetAllLocations(ctx context.Context) (cr.LocationsResponse, *shared.APIResponse, error) {
1415
versions, apiResponse, err := c.sdkClient.LocationsApi.LocationsGet(ctx).Execute()
1516
apiResponse.LogInfo()
1617
return versions, apiResponse, err
@@ -23,7 +24,7 @@ func SetCRLocationsData(d *schema.ResourceData, locations cr.LocationsResponse)
2324

2425
if locations.Items != nil {
2526
var locationList []string
26-
for _, location := range *locations.Items {
27+
for _, location := range locations.Items {
2728
locationList = append(locationList, *location.Id)
2829
}
2930
err := d.Set("locations", locationList)

0 commit comments

Comments
 (0)