Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup for Object Storage API onboarding #95

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/stackitcloud/stackit-sdk-go/services/logme v0.10.0
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.8.5
github.com/stackitcloud/stackit-sdk-go/services/rabbitmq v0.10.0
github.com/stackitcloud/stackit-sdk-go/services/redis v0.10.0
github.com/subosito/gotenv v1.6.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0 h1:WxvySRZfkecOV
github.com/stackitcloud/stackit-sdk-go/services/mariadb v0.10.0/go.mod h1:GQ+UyuUOANO/kQOIhqLmMYRH34NbZShMrfmUY6hTSjo=
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.11.0 h1:Ys1WYHlM/5ev5WmM3Qn/FboIlKeXbQSOU2PYlMQ2C9A=
github.com/stackitcloud/stackit-sdk-go/services/mongodbflex v0.11.0/go.mod h1:n9bUnjBIAvpnyC5oNGFZKZ/mmoA9y7CBTFwi1KV62GA=
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.8.5 h1:RbAorKhAoCPadWYp6tn6NZEWmafwfJvdNKW++SGc9Xo=
github.com/stackitcloud/stackit-sdk-go/services/objectstorage v0.8.5/go.mod h1:q6D+e173zF9ST5Nyj+StFlWTHjXutwCQ49mLBA1DrRA=
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.10.0 h1:Uv6r3tooqHgECoq/fGu4qZ/ojkf7H2lFH2NpsMhMxXM=
github.com/stackitcloud/stackit-sdk-go/services/opensearch v0.10.0/go.mod h1:VSwguERmACP2LSsk5OPLwTQxzt3CA8BasjB1qs+fjpI=
github.com/stackitcloud/stackit-sdk-go/services/postgresflex v0.9.1 h1:41M0IWsHFmt2KvoY/4vwWYNG94Tx3U3diSlYdz0thJE=
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
logMeCustomEndpointFlag = "logme-custom-endpoint"
mariaDBCustomEndpointFlag = "mariadb-custom-endpoint"
mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint"
objectStorageCustomEndpointFlag = "object-storage-custom-endpoint"
openSearchCustomEndpointFlag = "opensearch-custom-endpoint"
postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint"
rabbitMQCustomEndpointFlag = "rabbitmq-custom-endpoint"
Expand Down Expand Up @@ -95,6 +96,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(logMeCustomEndpointFlag, "", "LogMe API base URL, used in calls to this API")
cmd.Flags().String(mariaDBCustomEndpointFlag, "", "MariaDB API base URL, used in calls to this API")
cmd.Flags().String(mongoDBFlexCustomEndpointFlag, "", "MongoDB Flex API base URL, used in calls to this API")
cmd.Flags().String(objectStorageCustomEndpointFlag, "", "Object Storage API base URL, used in calls to this API")
cmd.Flags().String(openSearchCustomEndpointFlag, "", "OpenSearch API base URL, used in calls to this API")
cmd.Flags().String(postgresFlexCustomEndpointFlag, "", "PostgreSQL Flex API base URL, used in calls to this API")
cmd.Flags().String(rabbitMQCustomEndpointFlag, "", "RabbitMQ API base URL, used in calls to this API")
Expand All @@ -113,6 +115,8 @@ func configureFlags(cmd *cobra.Command) {
cobra.CheckErr(err)
err = viper.BindPFlag(config.MongoDBFlexCustomEndpointKey, cmd.Flags().Lookup(mongoDBFlexCustomEndpointFlag))
cobra.CheckErr(err)
err = viper.BindPFlag(config.ObjectStorageCustomEndpointKey, cmd.Flags().Lookup(objectStorageCustomEndpointFlag))
cobra.CheckErr(err)
err = viper.BindPFlag(config.OpenSearchCustomEndpointKey, cmd.Flags().Lookup(openSearchCustomEndpointFlag))
cobra.CheckErr(err)
err = viper.BindPFlag(config.PostgresFlexCustomEndpointKey, cmd.Flags().Lookup(postgresFlexCustomEndpointFlag))
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/config/unset/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
logMeCustomEndpointFlag = "logme-custom-endpoint"
mariaDBCustomEndpointFlag = "mariadb-custom-endpoint"
mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint"
objectStorageCustomEndpointFlag = "object-storage-custom-endpoint"
openSearchCustomEndpointFlag = "opensearch-custom-endpoint"
postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint"
rabbitMQCustomEndpointFlag = "rabbitmq-custom-endpoint"
Expand All @@ -46,6 +47,7 @@ type inputModel struct {
LogMeCustomEndpoint bool
MariaDBCustomEndpoint bool
MongoDBFlexCustomEndpoint bool
ObjectStorageCustomEndpoint bool
OpenSearchCustomEndpoint bool
PostgresFlexCustomEndpoint bool
RabbitMQCustomEndpoint bool
Expand Down Expand Up @@ -104,6 +106,9 @@ func NewCmd() *cobra.Command {
if model.MongoDBFlexCustomEndpoint {
viper.Set(config.MongoDBFlexCustomEndpointKey, "")
}
if model.ObjectStorageCustomEndpoint {
viper.Set(config.ObjectStorageCustomEndpointKey, "")
}
if model.OpenSearchCustomEndpoint {
viper.Set(config.OpenSearchCustomEndpointKey, "")
}
Expand Down Expand Up @@ -149,6 +154,7 @@ func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(logMeCustomEndpointFlag, false, "LogMe API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(mariaDBCustomEndpointFlag, false, "MariaDB API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(mongoDBFlexCustomEndpointFlag, false, "MongoDB Flex API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(objectStorageCustomEndpointFlag, false, "Object Storage API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(openSearchCustomEndpointFlag, false, "OpenSearch API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(postgresFlexCustomEndpointFlag, false, "PostgreSQL Flex API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(rabbitMQCustomEndpointFlag, false, "RabbitMQ API base URL. If unset, uses the default base URL")
Expand All @@ -170,6 +176,7 @@ func parseInput(cmd *cobra.Command) *inputModel {
LogMeCustomEndpoint: flags.FlagToBoolValue(cmd, logMeCustomEndpointFlag),
MariaDBCustomEndpoint: flags.FlagToBoolValue(cmd, mariaDBCustomEndpointFlag),
MongoDBFlexCustomEndpoint: flags.FlagToBoolValue(cmd, mongoDBFlexCustomEndpointFlag),
ObjectStorageCustomEndpoint: flags.FlagToBoolValue(cmd, objectStorageCustomEndpointFlag),
OpenSearchCustomEndpoint: flags.FlagToBoolValue(cmd, openSearchCustomEndpointFlag),
PostgresFlexCustomEndpoint: flags.FlagToBoolValue(cmd, postgresFlexCustomEndpointFlag),
RabbitMQCustomEndpoint: flags.FlagToBoolValue(cmd, rabbitMQCustomEndpointFlag),
Expand Down
11 changes: 7 additions & 4 deletions internal/cmd/config/unset/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool
dnsCustomEndpointFlag: true,
logMeCustomEndpointFlag: true,
mariaDBCustomEndpointFlag: true,
objectStorageCustomEndpointFlag: true,
openSearchCustomEndpointFlag: true,
rabbitMQCustomEndpointFlag: true,
redisCustomEndpointFlag: true,
Expand All @@ -38,12 +39,13 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
DNSCustomEndpoint: true,
LogMeCustomEndpoint: true,
MariaDBCustomEndpoint: true,
ServiceAccountCustomEndpoint: true,
SKECustomEndpoint: true,
ResourceManagerCustomEndpoint: true,
ObjectStorageCustomEndpoint: true,
OpenSearchCustomEndpoint: true,
RedisCustomEndpoint: true,
RabbitMQCustomEndpoint: true,
RedisCustomEndpoint: true,
ResourceManagerCustomEndpoint: true,
ServiceAccountCustomEndpoint: true,
SKECustomEndpoint: true,
}
for _, mod := range mods {
mod(model)
Expand Down Expand Up @@ -76,6 +78,7 @@ func TestParseInput(t *testing.T) {
model.DNSCustomEndpoint = false
model.LogMeCustomEndpoint = false
model.MariaDBCustomEndpoint = false
model.ObjectStorageCustomEndpoint = false
model.OpenSearchCustomEndpoint = false
model.RabbitMQCustomEndpoint = false
model.RedisCustomEndpoint = false
Expand Down
3 changes: 3 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
LogMeCustomEndpointKey = "logme_custom_endpoint"
MariaDBCustomEndpointKey = "mariadb_custom_endpoint"
MongoDBFlexCustomEndpointKey = "mongodbflex_custom_endpoint"
ObjectStorageCustomEndpointKey = "object_storage_custom_endpoint"
OpenSearchCustomEndpointKey = "opensearch_custom_endpoint"
PostgresFlexCustomEndpointKey = "postgresflex_custom_endpoint"
RabbitMQCustomEndpointKey = "rabbitmq_custom_endpoint"
Expand Down Expand Up @@ -50,6 +51,7 @@ var ConfigKeys = []string{
DNSCustomEndpointKey,
LogMeCustomEndpointKey,
MariaDBCustomEndpointKey,
ObjectStorageCustomEndpointKey,
OpenSearchCustomEndpointKey,
PostgresFlexCustomEndpointKey,
ResourceManagerEndpointKey,
Expand Down Expand Up @@ -126,6 +128,7 @@ func setConfigDefaults() {
viper.SetDefault(DNSCustomEndpointKey, "")
viper.SetDefault(AuthorizationCustomEndpointKey, "")
viper.SetDefault(MongoDBFlexCustomEndpointKey, "")
viper.SetDefault(ObjectStorageCustomEndpointKey, "")
viper.SetDefault(OpenSearchCustomEndpointKey, "")
viper.SetDefault(PostgresFlexCustomEndpointKey, "")
viper.SetDefault(ResourceManagerEndpointKey, "")
Expand Down
37 changes: 37 additions & 0 deletions internal/pkg/services/object-storage/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package client

import (
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"

"github.com/spf13/cobra"
"github.com/spf13/viper"
sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
)

func ConfigureClient(cmd *cobra.Command) (*objectstorage.APIClient, error) {
var err error
var apiClient *objectstorage.APIClient
var cfgOptions []sdkConfig.ConfigurationOption

authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser)
if err != nil {
return nil, &errors.AuthError{}
}
cfgOptions = append(cfgOptions, authCfgOption, sdkConfig.WithRegion("eu01"))

customEndpoint := viper.GetString(config.ObjectStorageCustomEndpointKey)

if customEndpoint != "" {
cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint))
}

apiClient, err = objectstorage.NewAPIClient(cfgOptions...)
if err != nil {
return nil, &errors.AuthError{}
}

return apiClient, nil
}