Skip to content
This repository was archived by the owner on Apr 7, 2024. It is now read-only.

feat: remove dependency of docker-credentials-helper and support context#68

Merged
Wwwsylvia merged 22 commits into
oras-project:mainfrom
wangxiaoxuan273:infra
Jun 8, 2023
Merged

feat: remove dependency of docker-credentials-helper and support context#68
Wwwsylvia merged 22 commits into
oras-project:mainfrom
wangxiaoxuan273:infra

Conversation

@wangxiaoxuan273

@wangxiaoxuan273 wangxiaoxuan273 commented May 24, 2023

Copy link
Copy Markdown
Collaborator

Resolves #67

@wangxiaoxuan273 wangxiaoxuan273 marked this pull request as draft May 29, 2023 05:56
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-commenter

codecov-commenter commented May 31, 2023

Copy link
Copy Markdown

Codecov Report

Merging #68 (ecb34fe) into main (97227b1) will decrease coverage by 0.45%.
The diff coverage is 66.66%.

❗ Current head ecb34fe differs from pull request most recent head 5e36dfc. Consider uploading reports for the commit 5e36dfc to get more accurate results

❗ 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     
Impacted Files Coverage Δ
native_store.go 73.91% <66.66%> (-3.02%) ⬇️

Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Comment thread main/main.go Fixed
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>
@wangxiaoxuan273 wangxiaoxuan273 marked this pull request as ready for review June 5, 2023 13:00
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Comment thread native_store.go Outdated
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
Comment thread native_store.go Outdated
Comment thread native_store.go
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>
Comment thread internal/executer/executer.go
Comment thread internal/executer/executer.go Outdated
}

// NewExecuter returns a new Executer instance.
func NewExecuter(name string) Executer {

Copy link
Copy Markdown
Contributor

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().

Suggested change
func NewExecuter(name string) Executer {
func New(name string) Executer {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the function

Comment thread native_store.go Outdated
Comment on lines +37 to +39
ServerURL string
Username string
Secret string

Copy link
Copy Markdown
Contributor

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"`

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread native_store.go
Comment on lines +34 to +35
// dockerCredentials mimics how docker credential helper binaries store
// credential information.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the reference link.

Comment thread native_store.go Outdated
// credentials secure.
type nativeStore struct {
programFunc client.ProgramFunc
executer.Executer

Copy link
Copy Markdown
Contributor

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

Suggested change
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.

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread native_store.go Outdated
Comment on lines +70 to +72
dockerCred := &dockerCredentials{
ServerURL: serverAddress,
}

Copy link
Copy Markdown
Contributor

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 {

Copy link
Copy Markdown
Collaborator Author

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.

Comment thread native_store.go Outdated
Comment on lines +97 to +101
buffer := new(bytes.Buffer)
if err := json.NewEncoder(buffer).Encode(dockerCred); err != nil {
return err
}
_, err := ns.Execute(ctx, buffer, "store")

Copy link
Copy Markdown
Contributor

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().

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated accordingly.

@shizhMSFT

Copy link
Copy Markdown
Contributor

@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{

@Wwwsylvia Wwwsylvia Jun 7, 2023

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Collaborator Author

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.

Copy link
Copy Markdown
Contributor

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

wangxiaoxuan273 commented Jun 8, 2023

Copy link
Copy Markdown
Collaborator Author

@wangxiaoxuan273 The code coverage drops. You may want to have a net gain on it.

I looked at the CodeDev report, currently all parts of native_store.go are covered, except the error handling parts of json.Marshall/Unmarshall and Execute. I don't think unit tests for these functions are necessary, just to increase the code coverage.

Comment thread internal/executer/executer.go Outdated

// NewExecuter returns a new Executer instance.
func NewExecuter(name string) Executer {
return &executable{

Copy link
Copy Markdown
Contributor

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.

Comment thread native_store.go Outdated
@shizhMSFT

shizhMSFT commented Jun 8, 2023

Copy link
Copy Markdown
Contributor

I don't think unit tests for these functions are necessary, just to increase the code coverage.

@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>

@shizhMSFT shizhMSFT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Wwwsylvia Wwwsylvia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Wwwsylvia Wwwsylvia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Wwwsylvia Wwwsylvia merged commit ab5d0bd into oras-project:main Jun 8, 2023
shizhMSFT pushed a commit that referenced this pull request Jun 8, 2023
Fixing the error of PR #68

---------

Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
@wangxiaoxuan273 wangxiaoxuan273 changed the title feat: add package client, the Program type and its related operations feat: remove dependency of docker-credentials-helper and support context Jun 20, 2023
@wangxiaoxuan273 wangxiaoxuan273 deleted the infra branch June 20, 2023 06:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Context Support for Native Store

6 participants