Skip to content

Commit bff17ae

Browse files
committed
replace cmd context with background context
Signed-off-by: matewolf <[email protected]>
1 parent 28c17fb commit bff17ae

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

cli/cmd/hub/login/login.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func runCmd(cmd *cobra.Command, opts *options.LoginOptions, idpClient idp.Client
7474
defer server.Shutdown(ctx)
7575

7676
// Open the browser
77-
if err := openBrowser(); err != nil {
77+
if err := openBrowser(authConfig); err != nil {
7878
return err
7979
}
8080

@@ -116,9 +116,9 @@ func runCmd(cmd *cobra.Command, opts *options.LoginOptions, idpClient idp.Client
116116
return nil
117117
}
118118

119-
func openBrowser() error {
119+
func openBrowser(authConfig *configUtils.AuthConfig) error {
120120
params := url.Values{}
121121
params.Add("redirectUri", fmt.Sprintf("http://localhost:%d", config.LocalWebserverPort))
122-
loginPageWithRedirect := fmt.Sprintf("%s?%s", config.DefaultLoginPageAddress, params.Encode())
122+
loginPageWithRedirect := fmt.Sprintf("%s/%s/login?%s", authConfig.IdpFrontendAddress, authConfig.IdpProductId, params.Encode())
123123
return browser.OpenURL(loginPageWithRedirect)
124124
}

cli/cmd/hub/push/push.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package push
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"strings"
@@ -12,7 +13,7 @@ import (
1213
hubClient "github.com/agntcy/dir/cli/hub/client"
1314
"github.com/agntcy/dir/cli/options"
1415
"github.com/agntcy/dir/cli/util/agent"
15-
"github.com/agntcy/dir/cli/util/context"
16+
contextUtils "github.com/agntcy/dir/cli/util/context"
1617
"github.com/agntcy/dir/cli/util/token"
1718
"github.com/agntcy/hub/api/v1alpha1"
1819
)
@@ -27,23 +28,23 @@ func NewCommand(hubOpts *options.HubOptions) *cobra.Command {
2728

2829
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
2930
// Check if the user is logged in
30-
secret, ok := context.GetCurrentHubSecretFromContext(cmd.Context())
31+
secret, ok := contextUtils.GetCurrentHubSecretFromContext(cmd.Context())
3132
if !ok || secret.TokenSecret == nil {
3233
return fmt.Errorf("You need to be logged in to push to the hub.\nUse `dirctl hub login` command to login.")
3334
}
3435

3536
// Check if the access token is expired
36-
idpClient, ok := context.GetIdpClientFromContext(cmd.Context())
37+
idpClient, ok := contextUtils.GetIdpClientFromContext(cmd.Context())
3738
if !ok {
3839
return fmt.Errorf("failed to get IDP client from context")
3940
}
4041

41-
secretStore, ok := context.GetSecretStoreFromContext(cmd.Context())
42+
secretStore, ok := contextUtils.GetSecretStoreFromContext(cmd.Context())
4243
if !ok {
4344
return fmt.Errorf("failed to get secret store from context")
4445
}
4546

46-
serverAddr, ok := context.GetCurrentServerAddressFromContext(cmd.Context())
47+
serverAddr, ok := contextUtils.GetCurrentServerAddressFromContext(cmd.Context())
4748
if !ok {
4849
return fmt.Errorf("failed to get current server address")
4950
}
@@ -62,7 +63,7 @@ func NewCommand(hubOpts *options.HubOptions) *cobra.Command {
6263
}
6364

6465
cmd.RunE = func(cmd *cobra.Command, args []string) error {
65-
secret, ok := context.GetCurrentHubSecretFromContext(cmd.Context())
66+
secret, ok := contextUtils.GetCurrentHubSecretFromContext(cmd.Context())
6667
if !ok {
6768
return fmt.Errorf("You need to be logged in to push to the hub.\nUse `dirctl hub login` command to login.")
6869
}
@@ -96,7 +97,7 @@ func NewCommand(hubOpts *options.HubOptions) *cobra.Command {
9697
return err
9798
}
9899

99-
ctx := metadata.NewOutgoingContext(cmd.Context(), metadata.Pairs("authorization", fmt.Sprintf("Bearer %s", secret.AccessToken)))
100+
ctx := metadata.NewOutgoingContext(context.Background(), metadata.Pairs("authorization", fmt.Sprintf("Bearer %s", secret.AccessToken)))
100101
resp, err := hc.PushAgent(ctx, agentBytes, repoId, tag)
101102
if err != nil {
102103
return fmt.Errorf("failed to push agent: %w", err)

cli/config/constants.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ const (
55

66
DefaultHubAddress = "https://phoenix.dev.outshift.ai"
77

8-
DefaultLoginPageAddress = "https://id.staging.eticloud.io/0bc16ceb-80d9-4179-8849-ec8248882a35/login"
9-
DefaultHubBackendAddress = "localhost:8080"
8+
DefaultLoginPageAddress = "https://id.staging.eticloud.io/0bc16ceb-80d9-4179-8849-ec8248882a35/login"
109
)

0 commit comments

Comments
 (0)