Skip to content
Closed
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ ensure that its UX is good. Remember that this is an experiment with the goal of
incorporating the learnings into the Docker CLI so it has some rough edges and
it's not meant to be a final product.

To get started wtih contributing, run `make help`. The commands that standout as
helpful for new contributors are

```
make lint => make sure all files are formatted with 'go fmt'
make test-unit => run unit tests
make e2e => run end-to-end tests
make => build it all for the local OS
```

For rapid iteration on running the project, use `go run main.go <args>`.
Additional logging can be enabled by using the `--debug` or `--trace` flags.


### Feedback

Please leave your feedback in the
Expand Down
9 changes: 2 additions & 7 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func NewRootCmd(streams command.Streams, hubClient *hub.Client, store credential
DisableFlagsInUseLine: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if flags.trace {
log.Warn("Sensitive data can be logged when using the `--trace` flag")
log.SetLevel(log.TraceLevel)
} else if flags.verbose {
log.SetLevel(log.DebugLevel)
Expand All @@ -80,14 +81,8 @@ func NewRootCmd(streams command.Streams, hubClient *hub.Client, store credential
Please login to Docker Hub using the "hub-tool login" command.`))
}

if cmd.Annotations["sudo"] == "true" {
if err := tryLogin(cmd.Context(), streams, hubClient, ac, store); err != nil {
return err
}
return nil
}

if ac.TokenExpired() {
log.Debugln("Token is expired, renewing")
return tryLogin(cmd.Context(), streams, hubClient, ac, store)
}
return nil
Expand Down
10 changes: 10 additions & 0 deletions internal/hub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func (c *Client) Login(username string, password string, twoFactorCodeProvider f
return "", "", err
}

log.Debugf("Login response %d on: %s", resp.StatusCode, resp.Request.URL)

// Login is OK, return the token
if resp.StatusCode == http.StatusOK {
creds := tokenResponse{}
Expand Down Expand Up @@ -264,6 +266,7 @@ func (c *Client) getTwoFactorToken(token string, twoFactorCodeProvider func() (s
if err != nil {
return "", "", err
}

resp, err := c.doRawRequest(req)
if err != nil {
return "", "", err
Expand All @@ -275,6 +278,10 @@ func (c *Client) getTwoFactorToken(token string, twoFactorCodeProvider func() (s
return "", "", err
}

log.Debugf("Login response %d on: %s", resp.StatusCode, req.URL)
log.Tracef("HTTP response: %+v", resp)
log.Tracef("HTTP response body: %s", string(buf))

// Login is OK, return the token
if resp.StatusCode == http.StatusOK {
creds := tokenResponse{}
Expand Down Expand Up @@ -336,6 +343,9 @@ func (c *Client) doRawRequest(req *http.Request, reqOps ...RequestOp) (*http.Res
if c.Ctx != nil {
req = req.WithContext(c.Ctx)
}

log.Debugf("HTTP %s on: %s", req.Method, req.URL)
log.Tracef("HTTP request: %+v", req)
return http.DefaultClient.Do(req)
}

Expand Down