Skip to content

Commit 8056cae

Browse files
authored
Setup for Object Storage API onboarding (#95)
1 parent d91b5ba commit 8056cae

File tree

7 files changed

+61
-4
lines changed

7 files changed

+61
-4
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ require (
5151
github.com/spf13/cast v1.6.0 // indirect
5252
github.com/stackitcloud/stackit-sdk-go/services/logme v0.10.0
5353
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0
54+
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.8.5
5455
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.10.0
5556
github.com/stackitcloud/stackit-sdk-go/services/redis v0.10.0
5657
github.com/subosito/gotenv v1.6.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0 h1:WxvySRZfkecOV
8989
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0/go.mod h1:GQ+UyuUOANO/kQOIhqLmMYRH34NbZShMrfmUY6hTSjo=
9090
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.11.0 h1:Ys1WYHlM/5ev5WmM3Qn/FboIlKeXbQSOU2PYlMQ2C9A=
9191
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.11.0/go.mod h1:n9bUnjBIAvpnyC5oNGFZKZ/mmoA9y7CBTFwi1KV62GA=
92+
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.8.5 h1:RbAorKhAoCPadWYp6tn6NZEWmafwfJvdNKW++SGc9Xo=
93+
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.8.5/go.mod h1:q6D+e173zF9ST5Nyj+StFlWTHjXutwCQ49mLBA1DrRA=
9294
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.10.0 h1:Uv6r3tooqHgECoq/fGu4qZ/ojkf7H2lFH2NpsMhMxXM=
9395
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.10.0/go.mod h1:VSwguERmACP2LSsk5OPLwTQxzt3CA8BasjB1qs+fjpI=
9496
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.9.1 h1:41M0IWsHFmt2KvoY/4vwWYNG94Tx3U3diSlYdz0thJE=

internal/cmd/config/set/set.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
logMeCustomEndpointFlag = "logme-custom-endpoint"
2424
mariaDBCustomEndpointFlag = "mariadb-custom-endpoint"
2525
mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint"
26+
objectStorageCustomEndpointFlag = "object-storage-custom-endpoint"
2627
openSearchCustomEndpointFlag = "opensearch-custom-endpoint"
2728
postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint"
2829
rabbitMQCustomEndpointFlag = "rabbitmq-custom-endpoint"
@@ -95,6 +96,7 @@ func configureFlags(cmd *cobra.Command) {
9596
cmd.Flags().String(logMeCustomEndpointFlag, "", "LogMe API base URL, used in calls to this API")
9697
cmd.Flags().String(mariaDBCustomEndpointFlag, "", "MariaDB API base URL, used in calls to this API")
9798
cmd.Flags().String(mongoDBFlexCustomEndpointFlag, "", "MongoDB Flex API base URL, used in calls to this API")
99+
cmd.Flags().String(objectStorageCustomEndpointFlag, "", "Object Storage API base URL, used in calls to this API")
98100
cmd.Flags().String(openSearchCustomEndpointFlag, "", "OpenSearch API base URL, used in calls to this API")
99101
cmd.Flags().String(postgresFlexCustomEndpointFlag, "", "PostgreSQL Flex API base URL, used in calls to this API")
100102
cmd.Flags().String(rabbitMQCustomEndpointFlag, "", "RabbitMQ API base URL, used in calls to this API")
@@ -113,6 +115,8 @@ func configureFlags(cmd *cobra.Command) {
113115
cobra.CheckErr(err)
114116
err = viper.BindPFlag(config.MongoDBFlexCustomEndpointKey, cmd.Flags().Lookup(mongoDBFlexCustomEndpointFlag))
115117
cobra.CheckErr(err)
118+
err = viper.BindPFlag(config.ObjectStorageCustomEndpointKey, cmd.Flags().Lookup(objectStorageCustomEndpointFlag))
119+
cobra.CheckErr(err)
116120
err = viper.BindPFlag(config.OpenSearchCustomEndpointKey, cmd.Flags().Lookup(openSearchCustomEndpointFlag))
117121
cobra.CheckErr(err)
118122
err = viper.BindPFlag(config.PostgresFlexCustomEndpointKey, cmd.Flags().Lookup(postgresFlexCustomEndpointFlag))

internal/cmd/config/unset/unset.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
logMeCustomEndpointFlag = "logme-custom-endpoint"
2626
mariaDBCustomEndpointFlag = "mariadb-custom-endpoint"
2727
mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint"
28+
objectStorageCustomEndpointFlag = "object-storage-custom-endpoint"
2829
openSearchCustomEndpointFlag = "opensearch-custom-endpoint"
2930
postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint"
3031
rabbitMQCustomEndpointFlag = "rabbitmq-custom-endpoint"
@@ -46,6 +47,7 @@ type inputModel struct {
4647
LogMeCustomEndpoint bool
4748
MariaDBCustomEndpoint bool
4849
MongoDBFlexCustomEndpoint bool
50+
ObjectStorageCustomEndpoint bool
4951
OpenSearchCustomEndpoint bool
5052
PostgresFlexCustomEndpoint bool
5153
RabbitMQCustomEndpoint bool
@@ -104,6 +106,9 @@ func NewCmd() *cobra.Command {
104106
if model.MongoDBFlexCustomEndpoint {
105107
viper.Set(config.MongoDBFlexCustomEndpointKey, "")
106108
}
109+
if model.ObjectStorageCustomEndpoint {
110+
viper.Set(config.ObjectStorageCustomEndpointKey, "")
111+
}
107112
if model.OpenSearchCustomEndpoint {
108113
viper.Set(config.OpenSearchCustomEndpointKey, "")
109114
}
@@ -149,6 +154,7 @@ func configureFlags(cmd *cobra.Command) {
149154
cmd.Flags().Bool(logMeCustomEndpointFlag, false, "LogMe API base URL. If unset, uses the default base URL")
150155
cmd.Flags().Bool(mariaDBCustomEndpointFlag, false, "MariaDB API base URL. If unset, uses the default base URL")
151156
cmd.Flags().Bool(mongoDBFlexCustomEndpointFlag, false, "MongoDB Flex API base URL. If unset, uses the default base URL")
157+
cmd.Flags().Bool(objectStorageCustomEndpointFlag, false, "Object Storage API base URL. If unset, uses the default base URL")
152158
cmd.Flags().Bool(openSearchCustomEndpointFlag, false, "OpenSearch API base URL. If unset, uses the default base URL")
153159
cmd.Flags().Bool(postgresFlexCustomEndpointFlag, false, "PostgreSQL Flex API base URL. If unset, uses the default base URL")
154160
cmd.Flags().Bool(rabbitMQCustomEndpointFlag, false, "RabbitMQ API base URL. If unset, uses the default base URL")
@@ -170,6 +176,7 @@ func parseInput(cmd *cobra.Command) *inputModel {
170176
LogMeCustomEndpoint: flags.FlagToBoolValue(cmd, logMeCustomEndpointFlag),
171177
MariaDBCustomEndpoint: flags.FlagToBoolValue(cmd, mariaDBCustomEndpointFlag),
172178
MongoDBFlexCustomEndpoint: flags.FlagToBoolValue(cmd, mongoDBFlexCustomEndpointFlag),
179+
ObjectStorageCustomEndpoint: flags.FlagToBoolValue(cmd, objectStorageCustomEndpointFlag),
173180
OpenSearchCustomEndpoint: flags.FlagToBoolValue(cmd, openSearchCustomEndpointFlag),
174181
PostgresFlexCustomEndpoint: flags.FlagToBoolValue(cmd, postgresFlexCustomEndpointFlag),
175182
RabbitMQCustomEndpoint: flags.FlagToBoolValue(cmd, rabbitMQCustomEndpointFlag),

internal/cmd/config/unset/unset_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool
1616
dnsCustomEndpointFlag: true,
1717
logMeCustomEndpointFlag: true,
1818
mariaDBCustomEndpointFlag: true,
19+
objectStorageCustomEndpointFlag: true,
1920
openSearchCustomEndpointFlag: true,
2021
rabbitMQCustomEndpointFlag: true,
2122
redisCustomEndpointFlag: true,
@@ -38,12 +39,13 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3839
DNSCustomEndpoint: true,
3940
LogMeCustomEndpoint: true,
4041
MariaDBCustomEndpoint: true,
41-
ServiceAccountCustomEndpoint: true,
42-
SKECustomEndpoint: true,
43-
ResourceManagerCustomEndpoint: true,
42+
ObjectStorageCustomEndpoint: true,
4443
OpenSearchCustomEndpoint: true,
45-
RedisCustomEndpoint: true,
4644
RabbitMQCustomEndpoint: true,
45+
RedisCustomEndpoint: true,
46+
ResourceManagerCustomEndpoint: true,
47+
ServiceAccountCustomEndpoint: true,
48+
SKECustomEndpoint: true,
4749
}
4850
for _, mod := range mods {
4951
mod(model)
@@ -76,6 +78,7 @@ func TestParseInput(t *testing.T) {
7678
model.DNSCustomEndpoint = false
7779
model.LogMeCustomEndpoint = false
7880
model.MariaDBCustomEndpoint = false
81+
model.ObjectStorageCustomEndpoint = false
7982
model.OpenSearchCustomEndpoint = false
8083
model.RabbitMQCustomEndpoint = false
8184
model.RedisCustomEndpoint = false

internal/pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
LogMeCustomEndpointKey = "logme_custom_endpoint"
2222
MariaDBCustomEndpointKey = "mariadb_custom_endpoint"
2323
MongoDBFlexCustomEndpointKey = "mongodbflex_custom_endpoint"
24+
ObjectStorageCustomEndpointKey = "object_storage_custom_endpoint"
2425
OpenSearchCustomEndpointKey = "opensearch_custom_endpoint"
2526
PostgresFlexCustomEndpointKey = "postgresflex_custom_endpoint"
2627
RabbitMQCustomEndpointKey = "rabbitmq_custom_endpoint"
@@ -50,6 +51,7 @@ var ConfigKeys = []string{
5051
DNSCustomEndpointKey,
5152
LogMeCustomEndpointKey,
5253
MariaDBCustomEndpointKey,
54+
ObjectStorageCustomEndpointKey,
5355
OpenSearchCustomEndpointKey,
5456
PostgresFlexCustomEndpointKey,
5557
ResourceManagerEndpointKey,
@@ -126,6 +128,7 @@ func setConfigDefaults() {
126128
viper.SetDefault(DNSCustomEndpointKey, "")
127129
viper.SetDefault(AuthorizationCustomEndpointKey, "")
128130
viper.SetDefault(MongoDBFlexCustomEndpointKey, "")
131+
viper.SetDefault(ObjectStorageCustomEndpointKey, "")
129132
viper.SetDefault(OpenSearchCustomEndpointKey, "")
130133
viper.SetDefault(PostgresFlexCustomEndpointKey, "")
131134
viper.SetDefault(ResourceManagerEndpointKey, "")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package client
2+
3+
import (
4+
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
5+
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
6+
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
11+
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
12+
)
13+
14+
func ConfigureClient(cmd *cobra.Command) (*objectstorage.APIClient, error) {
15+
var err error
16+
var apiClient *objectstorage.APIClient
17+
var cfgOptions []sdkConfig.ConfigurationOption
18+
19+
authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser)
20+
if err != nil {
21+
return nil, &errors.AuthError{}
22+
}
23+
cfgOptions = append(cfgOptions, authCfgOption, sdkConfig.WithRegion("eu01"))
24+
25+
customEndpoint := viper.GetString(config.ObjectStorageCustomEndpointKey)
26+
27+
if customEndpoint != "" {
28+
cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint))
29+
}
30+
31+
apiClient, err = objectstorage.NewAPIClient(cfgOptions...)
32+
if err != nil {
33+
return nil, &errors.AuthError{}
34+
}
35+
36+
return apiClient, nil
37+
}

0 commit comments

Comments
 (0)