New Upstream Release - golang-github-apptainer-container-key-client
Ready changes
Summary
Merged new upstream version: 0.8.0 (was: 0.7.2).
Resulting package
Built on 2023-05-16T20:39 (took 4m30s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases golang-github-apptainer-container-key-client-dev
Lintian Result
Diff
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 0e4c43e..54f4d7f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -22,7 +22,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
- go-version: '1.17.x'
+ go-version: '1.18.x'
- name: Check go.mod and go.sum are tidy
run: |
@@ -35,7 +35,7 @@ jobs:
- name: Install Lint
uses: golangci/golangci-lint-action@v2
with:
- version: v1.43
+ version: v1.45
- name: Run Lint
run: |
diff --git a/.golangci.yml b/.golangci.yml
index 560a9f1..57d252d 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -3,12 +3,15 @@ linters:
enable:
- bidichk
- bodyclose
+ - containedctx
- contextcheck
- deadcode
+ - decorder
- depguard
- dogsled
- dupl
- errcheck
+ - errchkjson
- gochecknoinits
- goconst
- gocritic
@@ -20,8 +23,10 @@ linters:
- gosec
- gosimple
- govet
+ - grouper
- ineffassign
- ireturn
+ - maintidx
- misspell
- nakedret
- nilnil
diff --git a/LICENSE.md b/LICENSE.md
index 36c403f..c5285b8 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,5 +1,7 @@
# LICENSE
+Copyright (c) 2019-2022, Sylabs Inc. All rights reserved.
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
diff --git a/README.md b/README.md
index 6de3dae..fd72e4d 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/apptainer/container-key-client)](https://pkg.go.dev/github.com/apptainer/container-key-client/client)
[![Build Status](https://github.com/apptainer/container-key-client/actions/workflows/ci.yml/badge.svg)](https://github.com/apptainer/container-key-client/actions/workflows/ci.yml)
-[![Code Coverage](https://codecov.io/gh/apptainer/container-key-client/branch/master/graph/badge.svg)](https://codecov.io/gh/apptainer/container-key-client)
+[![Code Coverage](https://codecov.io/gh/apptainer/container-key-client/branch/main/graph/badge.svg)](https://codecov.io/gh/apptainer/container-key-client)
[![Go Report Card](https://goreportcard.com/badge/github.com/apptainer/container-key-client)](https://goreportcard.com/report/github.com/apptainer/container-key-client)
This project provides a Go client to Apptainer for key storage and
diff --git a/client/pks.go b/client/pks.go
index 0260671..5c6e4c3 100644
--- a/client/pks.go
+++ b/client/pks.go
@@ -36,8 +36,18 @@ var ErrInvalidOperation = errors.New("invalid operation")
//
// If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.
func (c *Client) PKSAdd(ctx context.Context, keyText string) error {
+ _, err := c.PKSAddWithResponse(ctx, keyText)
+ return err
+}
+
+// PKSAdd submits an ASCII armored keyring to the Key Service, as specified in section 4 of the
+// OpenPGP HTTP Keyserver Protocol (HKP) specification and returns the server response upon
+// successful submission. The context controls the lifetime of the request.
+//
+// If an non-200 HTTP status code is received, an error wrapping an HTTPError is returned.
+func (c *Client) PKSAddWithResponse(ctx context.Context, keyText string) (string, error) {
if keyText == "" {
- return fmt.Errorf("%w", ErrInvalidKeyText)
+ return "", fmt.Errorf("%w", ErrInvalidKeyText)
}
ref := &url.URL{Path: pathPKSAdd}
@@ -47,20 +57,26 @@ func (c *Client) PKSAdd(ctx context.Context, keyText string) error {
req, err := c.NewRequest(ctx, http.MethodPost, ref, strings.NewReader(v.Encode()))
if err != nil {
- return fmt.Errorf("%w", err)
+ return "", fmt.Errorf("%w", err)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, err := c.Do(req)
if err != nil {
- return fmt.Errorf("%w", err)
+ return "", fmt.Errorf("%w", err)
}
defer res.Body.Close()
if res.StatusCode/100 != 2 { // non-2xx status code
- return fmt.Errorf("%w", errorFromResponse(res))
+ return "", fmt.Errorf("%w", errorFromResponse(res))
}
- return nil
+
+ body, err := io.ReadAll(res.Body)
+ if err != nil {
+ return "", fmt.Errorf("%w", err)
+ }
+
+ return string(body), nil
}
// PageDetails includes pagination details.
diff --git a/client/pks_test.go b/client/pks_test.go
index 0082682..2fb05b3 100644
--- a/client/pks_test.go
+++ b/client/pks_test.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, Sylabs Inc. All rights reserved.
+// Copyright (c) 2019-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
@@ -20,10 +20,11 @@ import (
)
type MockPKSAdd struct {
- t *testing.T
- code int
- message string
- keyText string
+ t *testing.T
+ code int
+ message string
+ keyText string
+ response string
}
func (m *MockPKSAdd) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -52,6 +53,9 @@ func (m *MockPKSAdd) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if got, want := r.Form.Get("keytext"), m.keyText; got != want {
m.t.Errorf("got key text %v, want %v", got, want)
}
+ if _, err := io.Copy(w, strings.NewReader(m.response)); err != nil {
+ m.t.Fatalf("failed to copy: %v", err)
+ }
}
func TestPKSAdd(t *testing.T) {
@@ -60,7 +64,7 @@ func TestPKSAdd(t *testing.T) {
tests := []struct {
name string
- ctx context.Context
+ ctx context.Context //nolint:containedctx
keyText string
code int
message string
@@ -135,6 +139,122 @@ func TestPKSAdd(t *testing.T) {
}
}
+func TestPKSAdd2(t *testing.T) {
+ cancelled, cancel := context.WithCancel(context.Background())
+ cancel()
+
+ tests := []struct {
+ name string
+ ctx context.Context //nolint:containedctx
+ keyText string
+ code int
+ message string
+ response string
+ wantErr error
+ }{
+ {
+ name: "OK",
+ ctx: context.Background(),
+ keyText: "key",
+ code: http.StatusOK,
+ },
+ {
+ name: "Accepted",
+ ctx: context.Background(),
+ keyText: "key",
+ response: "some verification instructions",
+ code: http.StatusAccepted,
+ },
+ {
+ name: "HTTPError",
+ ctx: context.Background(),
+ keyText: "key",
+ code: http.StatusBadRequest,
+ wantErr: &HTTPError{code: http.StatusBadRequest},
+ },
+ {
+ name: "HTTPErrorMessage",
+ ctx: context.Background(),
+ keyText: "key",
+ code: http.StatusBadRequest,
+ message: "blah",
+ wantErr: &HTTPError{code: http.StatusBadRequest},
+ },
+ {
+ name: "ContextCanceled",
+ ctx: cancelled,
+ keyText: "key",
+ code: http.StatusOK,
+ wantErr: context.Canceled,
+ },
+ {
+ name: "InvalidKeyText",
+ ctx: context.Background(),
+ keyText: "",
+ wantErr: ErrInvalidKeyText,
+ },
+ }
+
+ for _, tt := range tests {
+ tt := tt
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+
+ s := httptest.NewServer(&MockPKSAdd{
+ t: t,
+ code: tt.code,
+ message: tt.message,
+ keyText: tt.keyText,
+ })
+ defer s.Close()
+
+ c, err := NewClient(OptBaseURL(s.URL))
+ if err != nil {
+ t.Fatalf("failed to create client: %v", err)
+ }
+
+ err = c.PKSAdd(tt.ctx, tt.keyText)
+
+ if got, want := err, tt.wantErr; !errors.Is(got, want) {
+ t.Fatalf("got error %v, want %v", got, want)
+ }
+ })
+ }
+
+ for _, tt := range tests {
+ tt := tt
+ t.Run(tt.name, func(t *testing.T) {
+ t.Parallel()
+
+ s := httptest.NewServer(&MockPKSAdd{
+ t: t,
+ code: tt.code,
+ message: tt.message,
+ keyText: tt.keyText,
+ response: tt.response,
+ })
+ defer s.Close()
+
+ c, err := NewClient(OptBaseURL(s.URL))
+ if err != nil {
+ t.Fatalf("failed to create client: %v", err)
+ }
+
+ r, err := c.PKSAddWithResponse(tt.ctx, tt.keyText)
+
+ if got, want := err, tt.wantErr; !errors.Is(got, want) {
+ t.Fatalf("got error %v, want %v", got, want)
+ }
+
+ if err == nil {
+ if got, want := r, tt.response; got != want {
+ t.Errorf("got response %q, want %q", got, want)
+ }
+ }
+ })
+ }
+}
+
type MockPKSLookup struct {
t *testing.T
code int
@@ -246,13 +366,14 @@ func (m *MockPKSLookup) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
+//nolint:maintidx
func TestPKSLookup(t *testing.T) {
cancelled, cancel := context.WithCancel(context.Background())
cancel()
tests := []struct {
name string
- ctx context.Context
+ ctx context.Context //nolint:containedctx
code int
message string
search string
@@ -548,7 +669,7 @@ func TestGetKey(t *testing.T) {
tests := []struct {
name string
- ctx context.Context
+ ctx context.Context //nolint:containedctx
code int
message string
search []byte
diff --git a/client/version_test.go b/client/version_test.go
index 9fde48d..12c99f7 100644
--- a/client/version_test.go
+++ b/client/version_test.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2019-2020, Sylabs Inc. All rights reserved.
+// Copyright (c) 2019-2022, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the LICENSE.md file
// distributed with the sources of this project regarding your rights to use or distribute this
// software.
@@ -56,7 +56,7 @@ func TestGetVersion(t *testing.T) {
tests := []struct {
name string
path string
- ctx context.Context
+ ctx context.Context //nolint:containedctx
code int
message string
wantPath string
diff --git a/debian/changelog b/debian/changelog
index 8a83e7a..4711cc4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-apptainer-container-key-client (0.8.0-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Tue, 16 May 2023 20:35:39 -0000
+
golang-github-apptainer-container-key-client (0.7.2-2) unstable; urgency=medium
* Source-only upload
diff --git a/go.mod b/go.mod
index 7816d59..16790e9 100644
--- a/go.mod
+++ b/go.mod
@@ -2,4 +2,4 @@ module github.com/apptainer/container-key-client
go 1.17
-require github.com/sylabs/json-resp v0.8.0
+require github.com/sylabs/json-resp v0.8.1
diff --git a/go.sum b/go.sum
index f27680f..f9d7088 100644
--- a/go.sum
+++ b/go.sum
@@ -1,2 +1,2 @@
-github.com/sylabs/json-resp v0.8.0 h1:bZ932uaF220aPqT0+x/vakoaGCGNbpLCjUFm1f+JKlY=
-github.com/sylabs/json-resp v0.8.0/go.mod h1:bUGV9cqShOyxz7RxBq03Yt9raKGfELKrfN6Yac3lfiw=
+github.com/sylabs/json-resp v0.8.1 h1:3KF04WzGizDVlROeI4DK4B0f9p7XKb0BRTFzI7wPTG8=
+github.com/sylabs/json-resp v0.8.1/go.mod h1:bUGV9cqShOyxz7RxBq03Yt9raKGfELKrfN6Yac3lfiw=
Debdiff
File lists identical (after any substitutions)
No differences were encountered in the control files