@@ -2,46 +2,12 @@ package client
22
33import (
44 "github.com/spf13/viper"
5- "github.com/stackitcloud/stackit-cli/internal/pkg/auth"
6- "github.com/stackitcloud/stackit-cli/internal/pkg/config"
7- "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
5+ genericclient "github.com/stackitcloud/stackit-cli/internal/pkg/generic-client"
86 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
9- "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
10- sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config"
117 "github.com/stackitcloud/stackit-sdk-go/services/foo"
128 // (...)
139)
1410
1511func ConfigureClient (p * print.Printer , cliVersion string ) (* foo.APIClient , error ) {
16- authCfgOption , err := auth .AuthenticationConfig (p , auth .AuthorizeUser )
17- if err != nil {
18- return nil , & errors.AuthError {}
19- }
20-
21- region := viper .GetString (config .RegionKey )
22- cfgOptions := []sdkConfig.ConfigurationOption {
23- utils .UserAgentConfigOption (cliVersion ),
24- sdkConfig .WithRegion (region ), // Configuring region is needed if "foo" is a regional API
25- authCfgOption ,
26- }
27-
28- customEndpoint := viper .GetString (config .fooCustomEndpointKey )
29-
30- if customEndpoint != "" {
31- cfgOptions = append (cfgOptions , sdkConfig .WithEndpoint (customEndpoint ))
32- }
33-
34- if p .IsVerbosityDebug () {
35- cfgOptions = append (cfgOptions ,
36- sdkConfig .WithMiddleware (print .RequestResponseCapturer (p , nil )),
37- )
38- }
39-
40- apiClient , err := foo .NewAPIClient (cfgOptions ... )
41- if err != nil {
42- p .Debug (print .ErrorLevel , "create new API client: %v" , err )
43- return nil , & errors.AuthError {}
44- }
45-
46- return apiClient , nil
12+ return genericclient .ConfigureClientGeneric (p , cliVersion , viper .GetString (config .fooCustomEndpointKey ), false , genericclient.CreateApiClient [* foo.APIClient ](foo .NewAPIClient ))
4713}
0 commit comments