From d36a85e33913449aacbcfea4f31883e01b270361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blaisot?= Date: Thu, 23 Nov 2023 08:56:46 +0100 Subject: [PATCH 1/2] Clean code duplication --- cmd/root.go | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 8373334c235..6234324d91f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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" @@ -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 { From 524f298da1df105481202911ea2ae115949d28aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blaisot?= Date: Thu, 23 Nov 2023 08:57:53 +0100 Subject: [PATCH 2/2] Avoid double admin password request on instances add --- client/admin_client.go | 2 +- cmd/instances.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/admin_client.go b/client/admin_client.go index 46dd5a7593d..04487d3fd35 100644 --- a/client/admin_client.go +++ b/client/admin_client.go @@ -27,7 +27,7 @@ func (ac *AdminClient) NewInstanceClient(domain string, scopes ...string) (*Clie httpClient, clientURL, err := tlsclient.NewHTTPClient(tlsclient.HTTPEndpoint{ Host: config.GetConfig().Host, Port: config.GetConfig().Port, - Timeout: 5 * time.Minute, + Timeout: 15 * time.Minute, EnvPrefix: "COZY_HOST", }) if err != nil { diff --git a/cmd/instances.go b/cmd/instances.go index 10fb0d19f4b..4a515cf499d 100644 --- a/cmd/instances.go +++ b/cmd/instances.go @@ -217,7 +217,13 @@ be used as the error message. if len(flagApps) == 0 { return nil } - apps, err := newClient(domain, consts.Apps).ListApps(consts.Apps) + c, err := ac.NewInstanceClient(domain, consts.Apps) + if err != nil { + errPrintfln("Could not generate access to domain %s", domain) + errPrintfln("%s", err) + os.Exit(1) + } + apps, err := c.ListApps(consts.Apps) if err == nil && len(flagApps) != len(apps) { for _, slug := range flagApps { found := false