Skip to content

Commit

Permalink
Clean code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
sblaisot committed Nov 23, 2023
1 parent 2c217fe commit d36a85e
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/cozy/cozy-stack/client/request"
build "github.com/cozy/cozy-stack/pkg/config"
"github.com/cozy/cozy-stack/pkg/config/config"
"github.com/cozy/cozy-stack/pkg/consts"
"github.com/cozy/cozy-stack/pkg/tlsclient"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -57,32 +56,7 @@ func newClientSafe(domain string, scopes ...string) (*client.Client, error) {
// We may want in the future rely on OAuth to handle the permissions with
// more granularity.
ac := newAdminClient()
token, err := ac.GetToken(&client.TokenOptions{
Domain: domain,
Subject: "CLI",
Audience: consts.CLIAudience,
Scope: scopes,
})
if err != nil {
return nil, err
}

httpClient, clientURL, err := tlsclient.NewHTTPClient(tlsclient.HTTPEndpoint{
Host: config.GetConfig().Host,
Port: config.GetConfig().Port,
Timeout: 15 * time.Minute,
EnvPrefix: "COZY_HOST",
})
if err != nil {
return nil, err
}
return &client.Client{
Scheme: clientURL.Scheme,
Addr: clientURL.Host,
Domain: domain,
Client: httpClient,
Authorizer: &request.BearerAuthorizer{Token: token},
}, nil
return ac.NewInstanceClient(domain, scopes...)
}

func newClient(domain string, scopes ...string) *client.Client {
Expand Down

0 comments on commit d36a85e

Please sign in to comment.