-
Notifications
You must be signed in to change notification settings - Fork 7
feat: remove dependency of docker-credentials-helper
and support context
#68
Conversation
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## main #68 +/- ##
==========================================
- Coverage 81.13% 80.68% -0.45%
==========================================
Files 6 6
Lines 371 378 +7
==========================================
+ Hits 301 305 +4
- Misses 48 49 +1
- Partials 22 24 +2
|
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
internal/executer/executer.go
Outdated
} | ||
|
||
// NewExecuter returns a new Executer instance. | ||
func NewExecuter(name string) Executer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to be used as executer.New()
.
func NewExecuter(name string) Executer { | |
func New(name string) Executer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the function
native_store.go
Outdated
ServerURL string | ||
Username string | ||
Secret string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to explicitly declare the json field name. For example:
ServerURL string `json:"ServerURL"`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the json field name.
// dockerCredentials mimics how docker credential helper binaries store | ||
// credential information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to have a reference link like https://docs.docker.com/engine/reference/commandline/login/#credential-helper-protocol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the reference link.
native_store.go
Outdated
// nativeStore implements a credentials store using native keychain to keep | ||
// credentials secure. | ||
type nativeStore struct { | ||
programFunc client.ProgramFunc | ||
executer.Executer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to give this component name like
executer.Executer | |
exec executer.Executer |
Otherwise, all public method of executer.Executer
will be exposed to the nativeStore
. In other words, some one can do
store := NewNativeStore("foobar")
exec := store.(executer.Executer)
exec.Execute(ctx, "hello", "get")
which should not be allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added back the variable name.
native_store.go
Outdated
dockerCred := &dockerCredentials{ | ||
ServerURL: serverAddress, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the meaning to pre-fill the content as Decode
will clean it anyway.
Consider the following code
var dockerCred dockerCredentials
if err := json.Unmarshal(out, &dockerCred); err != nil {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with the code above.
native_store.go
Outdated
buffer := new(bytes.Buffer) | ||
if err := json.NewEncoder(buffer).Encode(dockerCred); err != nil { | ||
return err | ||
} | ||
_, err := ns.Execute(ctx, buffer, "store") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using json.Marshal()
and bytes.NewReader()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated accordingly.
@wangxiaoxuan273 The code coverage drops. You may want to have a net gain on it. |
Signed-off-by: Xiaoxuan Wang <[email protected]>
|
||
// NewExecuter returns a new Executer instance. | ||
func NewExecuter(name string) Executer { | ||
return &executable{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A question: Do weed need to check if the executable can be found? Like using exec.LookPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need more discussion on that? This is worth a future "feat" PR. I'll leave it as it is for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good idea and is necessary for detecting desktop.exe
. However, we can leave it in the next PR.
I looked at the CodeDev report, currently all parts of |
|
||
// NewExecuter returns a new Executer instance. | ||
func NewExecuter(name string) Executer { | ||
return &executable{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a good idea and is necessary for detecting desktop.exe
. However, we can leave it in the next PR.
@wangxiaoxuan273 It is necessary. Unit tests are not just for positive paths. Negative paths are equivalently important. |
Signed-off-by: wangxiaoxuan273 <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
Signed-off-by: Xiaoxuan Wang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixing the error of PR #68 --------- Signed-off-by: wangxiaoxuan273 <[email protected]>
docker-credentials-helper
and support context
Resolves #67