Skip to content

Commit

Permalink
remove warning reference
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia committed Aug 2, 2023
1 parent 9d2d6e5 commit 93a19d3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion registry/remote/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func Example_handleWarning() {
}
// 1. specify HandleWarning
repo.HandleWarning = func(warning remote.Warning) {
fmt.Printf("Warning from %s: %s\n", warning.Reference.Repository, warning.Value.Text)
fmt.Printf("Warning from %s: %s\n", repo.Reference.Repository, warning.Value.Text)
}

ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion registry/remote/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (r *Registry) do(req *http.Request) (*http.Response, error) {
if err != nil {
return nil, err
}
handleWarningHeaders(resp.Header.Values(headerWarning), r.Reference, r.HandleWarning)
handleWarningHeaders(resp.Header.Values(headerWarning), r.HandleWarning)
return resp, nil
}

Expand Down
3 changes: 0 additions & 3 deletions registry/remote/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,23 +359,20 @@ func TestRegistry_do(t *testing.T) {
Agent: "-",
Text: "Test 1: Good warning.",
},
Reference: reg.Reference,
},
{
Value: WarningValue{
Code: 299,
Agent: "-",
Text: "Test 3: Good warning.",
},
Reference: reg.Reference,
},
{
Value: WarningValue{
Code: 299,
Agent: "-",
Text: "Test 6: Good warning.",
},
Reference: reg.Reference,
},
}
if !reflect.DeepEqual(gotWarnings, wantWarnings) {
Expand Down
2 changes: 1 addition & 1 deletion registry/remote/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (r *Repository) do(req *http.Request) (*http.Response, error) {
if err != nil {
return nil, err
}
handleWarningHeaders(resp.Header.Values(headerWarning), r.Reference, r.HandleWarning)
handleWarningHeaders(resp.Header.Values(headerWarning), r.HandleWarning)
return resp, nil
}

Expand Down
3 changes: 0 additions & 3 deletions registry/remote/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6924,23 +6924,20 @@ func TestRepository_do(t *testing.T) {
Agent: "-",
Text: "Test 1: Good warning.",
},
Reference: repo.Reference,
},
{
Value: WarningValue{
Code: 299,
Agent: "-",
Text: "Test 3: Good warning.",
},
Reference: repo.Reference,
},
{
Value: WarningValue{
Code: 299,
Agent: "-",
Text: "Test 6: Good warning.",
},
Reference: repo.Reference,
},
}
if !reflect.DeepEqual(gotWarnings, wantWarnings) {
Expand Down
14 changes: 4 additions & 10 deletions registry/remote/warning.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"fmt"
"strconv"
"strings"

"oras.land/oras-go/v2/registry"
)

const (
Expand Down Expand Up @@ -56,18 +54,15 @@ type WarningValue struct {
Text string
}

// Warning contains the value of the warning header and other information
// related to the warning.
// Warning contains the value of the warning header and may contain
// other information related to the warning.
//
// References:
// - https://github.com/opencontainers/distribution-spec/blob/v1.1.0-rc3/spec.md#warnings
// - https://www.rfc-editor.org/rfc/rfc7234#section-5.5
type Warning struct {
// Value is the value of the warning header.
Value WarningValue
// Reference is the registry reference for which the warning is being
// reported.
Reference registry.Reference
}

// parseWarningHeader parses the warning header into WarningValue.
Expand All @@ -93,13 +88,12 @@ func parseWarningHeader(header string) (WarningValue, error) {

// handleWarningHeaders parses the warning headers and handles the parsed
// warnings using handleWarning.
func handleWarningHeaders(headers []string, reference registry.Reference, handleWarning func(Warning)) {
func handleWarningHeaders(headers []string, handleWarning func(Warning)) {
for _, h := range headers {
if wh, err := parseWarningHeader(h); err == nil {
// ignore warnings in unexpected formats
warning := Warning{
Value: wh,
Reference: reference,
Value: wh,
}
handleWarning(warning)
}
Expand Down

0 comments on commit 93a19d3

Please sign in to comment.