1
1
package push
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"fmt"
6
7
"strings"
@@ -12,7 +13,7 @@ import (
12
13
hubClient "github.com/agntcy/dir/cli/hub/client"
13
14
"github.com/agntcy/dir/cli/options"
14
15
"github.com/agntcy/dir/cli/util/agent"
15
- "github.com/agntcy/dir/cli/util/context"
16
+ contextUtils "github.com/agntcy/dir/cli/util/context"
16
17
"github.com/agntcy/dir/cli/util/token"
17
18
"github.com/agntcy/hub/api/v1alpha1"
18
19
)
@@ -27,23 +28,23 @@ func NewCommand(hubOpts *options.HubOptions) *cobra.Command {
27
28
28
29
cmd .PreRunE = func (cmd * cobra.Command , args []string ) error {
29
30
// Check if the user is logged in
30
- secret , ok := context .GetCurrentHubSecretFromContext (cmd .Context ())
31
+ secret , ok := contextUtils .GetCurrentHubSecretFromContext (cmd .Context ())
31
32
if ! ok || secret .TokenSecret == nil {
32
33
return fmt .Errorf ("You need to be logged in to push to the hub.\n Use `dirctl hub login` command to login." )
33
34
}
34
35
35
36
// Check if the access token is expired
36
- idpClient , ok := context .GetIdpClientFromContext (cmd .Context ())
37
+ idpClient , ok := contextUtils .GetIdpClientFromContext (cmd .Context ())
37
38
if ! ok {
38
39
return fmt .Errorf ("failed to get IDP client from context" )
39
40
}
40
41
41
- secretStore , ok := context .GetSecretStoreFromContext (cmd .Context ())
42
+ secretStore , ok := contextUtils .GetSecretStoreFromContext (cmd .Context ())
42
43
if ! ok {
43
44
return fmt .Errorf ("failed to get secret store from context" )
44
45
}
45
46
46
- serverAddr , ok := context .GetCurrentServerAddressFromContext (cmd .Context ())
47
+ serverAddr , ok := contextUtils .GetCurrentServerAddressFromContext (cmd .Context ())
47
48
if ! ok {
48
49
return fmt .Errorf ("failed to get current server address" )
49
50
}
@@ -62,7 +63,7 @@ func NewCommand(hubOpts *options.HubOptions) *cobra.Command {
62
63
}
63
64
64
65
cmd .RunE = func (cmd * cobra.Command , args []string ) error {
65
- secret , ok := context .GetCurrentHubSecretFromContext (cmd .Context ())
66
+ secret , ok := contextUtils .GetCurrentHubSecretFromContext (cmd .Context ())
66
67
if ! ok {
67
68
return fmt .Errorf ("You need to be logged in to push to the hub.\n Use `dirctl hub login` command to login." )
68
69
}
@@ -96,7 +97,7 @@ func NewCommand(hubOpts *options.HubOptions) *cobra.Command {
96
97
return err
97
98
}
98
99
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 )))
100
101
resp , err := hc .PushAgent (ctx , agentBytes , repoId , tag )
101
102
if err != nil {
102
103
return fmt .Errorf ("failed to push agent: %w" , err )
0 commit comments