-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathclient.go
More file actions
35 lines (28 loc) · 987 Bytes
/
client.go
File metadata and controls
35 lines (28 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package client
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stackitcloud/stackit-cli/internal/pkg/auth"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-sdk-go/services/foo"
// (...)
)
func ConfigureClient(cmd *cobra.Command) (*foo.APIClient, error) {
var err error
var apiClient foo.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")) // Configuring region is needed if "foo" is a regional API
customEndpoint := viper.GetString(config.fooCustomEndpointKey)
if customEndpoint != "" {
cfgOptions = append(cfgOptions, sdkConfig.WithEndpoint(customEndpoint))
}
apiClient, err = foo.NewAPIClient(cfgOptions...)
if err != nil {
return nil, &errors.AuthError{}
}
return apiClient, nil
}