Skip to content
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
15 changes: 15 additions & 0 deletions pkg/shared/connection/api/api.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package api

import (
"net/http"
"net/url"

"github.com/redhat-developer/app-services-cli/pkg/api/generic"
"github.com/redhat-developer/app-services-cli/pkg/api/rbac"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
connectormgmtclient "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/client"

amsclient "github.com/redhat-developer/app-services-sdk-go/accountmgmt/apiv1/client"
Expand All @@ -22,4 +26,15 @@ type API interface {
AccountMgmt() amsclient.AppServicesApi
RBAC() rbac.RbacAPI
GenericAPI() generic.GenericAPI
GetConfig() Config
}

type Config struct {
AccessToken string
MasAccessToken string
ApiURL *url.URL
ConsoleURL *url.URL
UserAgent string
HTTPClient *http.Client
Logger logging.Logger
}
33 changes: 7 additions & 26 deletions pkg/shared/connection/api/defaultapi/default_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/redhat-developer/app-services-cli/internal/build"
"github.com/redhat-developer/app-services-cli/pkg/api/generic"
"github.com/redhat-developer/app-services-cli/pkg/api/rbac"
"github.com/redhat-developer/app-services-cli/pkg/core/logging"
"github.com/redhat-developer/app-services-cli/pkg/shared/connection/api"
"github.com/redhat-developer/app-services-cli/pkg/shared/svcstatus"
amsclient "github.com/redhat-developer/app-services-sdk-go/accountmgmt/apiv1/client"
Expand All @@ -33,38 +32,20 @@ import (

// defaultAPI is a type which defines a number of API creator functions
type defaultAPI struct {
AccessToken string
MasAccessToken string
ApiURL *url.URL
ConsoleURL *url.URL
UserAgent string
HTTPClient *http.Client
Logger logging.Logger
}

type Config struct {
AccessToken string
MasAccessToken string
ApiURL *url.URL
ConsoleURL *url.URL
UserAgent string
HTTPClient *http.Client
Logger logging.Logger
api.Config
}

// New creates a new default API client wrapper
func New(cfg *Config) api.API {
func New(cfg *api.Config) api.API {
return &defaultAPI{
AccessToken: cfg.AccessToken,
MasAccessToken: cfg.MasAccessToken,
ApiURL: cfg.ApiURL,
ConsoleURL: cfg.ConsoleURL,
UserAgent: cfg.UserAgent,
HTTPClient: cfg.HTTPClient,
Logger: cfg.Logger,
Config: *cfg,
}
}

func (a *defaultAPI) GetConfig() api.Config {
return a.Config
}

// KafkaMgmt returns a new Kafka Management API client instance
func (a *defaultAPI) KafkaMgmt() kafkamgmtclient.DefaultApi {
tc := a.CreateOAuthTransport(a.AccessToken)
Expand Down
2 changes: 1 addition & 1 deletion pkg/shared/connection/kcconnection/keycloak_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (c *Connection) Logout(ctx context.Context) (err error) {

// API Creates a new API type which is a single type for multiple APIs
func (c *Connection) API() api.API {
apiClient := defaultapi.New(&defaultapi.Config{
apiClient := defaultapi.New(&api.Config{
HTTPClient: c.defaultHTTPClient,
UserAgent: build.DefaultUserAgentPrefix + build.Version,
MasAccessToken: c.MASToken.AccessToken,
Expand Down