feat: remove dependency of docker-credentials-helper and support context#68
Conversation
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
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 <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
| } | ||
|
|
||
| // NewExecuter returns a new Executer instance. | ||
| func NewExecuter(name string) Executer { |
There was a problem hiding this comment.
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.
Renamed the function
| ServerURL string | ||
| Username string | ||
| Secret string |
There was a problem hiding this comment.
It is better to explicitly declare the json field name. For example:
ServerURL string `json:"ServerURL"`There was a problem hiding this comment.
Added the json field name.
| // dockerCredentials mimics how docker credential helper binaries store | ||
| // credential information. |
There was a problem hiding this comment.
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.
Added the reference link.
| // credentials secure. | ||
| type nativeStore struct { | ||
| programFunc client.ProgramFunc | ||
| executer.Executer |
There was a problem hiding this comment.
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.
Added back the variable name.
| dockerCred := &dockerCredentials{ | ||
| ServerURL: serverAddress, | ||
| } |
There was a problem hiding this comment.
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.
Replaced with the code above.
| 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.
Consider using json.Marshal() and bytes.NewReader().
There was a problem hiding this comment.
Updated accordingly.
|
@wangxiaoxuan273 The code coverage drops. You may want to have a net gain on it. |
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
|
|
||
| // NewExecuter returns a new Executer instance. | ||
| func NewExecuter(name string) Executer { | ||
| return &executable{ |
There was a problem hiding this comment.
A question: Do weed need to check if the executable can be found? Like using exec.LookPath?
There was a problem hiding this comment.
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.
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.
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 <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Fixing the error of PR #68 --------- Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
docker-credentials-helper and support context
Resolves #67