Skip to content

Commit 07e6987

Browse files
authored
First commit with source code (#1)
First commit with source code
1 parent 4e244eb commit 07e6987

19 files changed

+1980
-0
lines changed

Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
BASE_DIR := $(dir $(realpath -s $(firstword $(MAKEFILE_LIST))))
2+
3+
.PHONY: build
4+
build: | generate-mocks
5+
go build -o $(BASE_DIR)/build/bin/notation-com.amazonaws.signer.notation.plugin $(BASE_DIR)/cmd
6+
7+
.PHONY: generate-mocks
8+
generate-mocks:
9+
@if ! command -v mockgen &> /dev/null; then \
10+
echo "Installing mockgen as it is not present in the system..."; \
11+
go install github.com/golang/mock/[email protected]; \
12+
fi
13+
@echo "Generating Mocks..."
14+
$(GOPATH)/bin/mockgen -package client -destination=./internal/client/mock_client.go "github.com/aws/aws-signer-notation-plugin/internal/client" Interface
15+
@echo "Mocks generated successfully."
16+
17+
.PHONY: clean-mocks
18+
clean-mocks:
19+
rm -rf ./internal/client/mock_client.go
20+
21+
.PHONY: test
22+
test: check-line-endings
23+
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
24+
25+
.PHONY: check-line-endings
26+
check-line-endings:
27+
! find . -name "*.go" -type f -exec file "{}" ";" | grep CRLF
28+
29+
.PHONY: fix-line-endings
30+
fix-line-endings:
31+
find . -type f -name "*.go" -exec sed -i -e "s/\r//g" {} +

cmd/main.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/aws/aws-signer-notation-plugin/internal/logger"
9+
"github.com/aws/aws-signer-notation-plugin/plugin"
10+
11+
"github.com/notaryproject/notation-plugin-framework-go/cli"
12+
)
13+
14+
const debugFlag = "AWS_SIGNER_NOTATION_PLUGIN_DEBUG"
15+
16+
func main() {
17+
awsPlugin := plugin.NewAWSSignerForCLI()
18+
ctx := context.Background()
19+
20+
var pluginCli *cli.CLI
21+
var err error
22+
if os.Getenv(debugFlag) == "true" {
23+
log, logErr := logger.New()
24+
if logErr != nil {
25+
os.Exit(100)
26+
}
27+
defer log.Close()
28+
ctx = log.UpdateContext(ctx)
29+
pluginCli, err = cli.NewWithLogger(awsPlugin, log)
30+
} else {
31+
pluginCli, err = cli.New(awsPlugin)
32+
}
33+
if err != nil {
34+
_, _ = fmt.Fprintf(os.Stderr, "failed to create executable: %v\n", err)
35+
os.Exit(101)
36+
}
37+
pluginCli.Execute(ctx, os.Args)
38+
}

go.mod

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
go 1.21
2+
3+
module github.com/aws/aws-signer-notation-plugin
4+
5+
require (
6+
github.com/aws/aws-sdk-go-v2 v1.25.3
7+
github.com/aws/aws-sdk-go-v2/config v1.26.2
8+
github.com/aws/aws-sdk-go-v2/service/signer v1.19.6
9+
github.com/aws/smithy-go v1.20.1
10+
github.com/golang/mock v1.6.0
11+
github.com/notaryproject/notation-plugin-framework-go v1.0.0
12+
github.com/stretchr/testify v1.8.4
13+
)
14+
15+
require (
16+
github.com/aws/aws-sdk-go-v2/credentials v1.16.13 // indirect
17+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 // indirect
18+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3 // indirect
19+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3 // indirect
20+
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect
21+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
22+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 // indirect
23+
github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 // indirect
24+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect
25+
github.com/aws/aws-sdk-go-v2/service/sts v1.26.6 // indirect
26+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
27+
github.com/google/go-cmp v0.6.0 // indirect
28+
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24 // indirect
29+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
30+
gopkg.in/yaml.v3 v3.0.1 // indirect
31+
)

go.sum

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
github.com/aws/aws-sdk-go-v2 v1.25.3 h1:xYiLpZTQs1mzvz5PaI6uR0Wh57ippuEthxS4iK5v0n0=
2+
github.com/aws/aws-sdk-go-v2 v1.25.3/go.mod h1:35hUlJVYd+M++iLI3ALmVwMOyRYMmRqUXpTtRGW+K9I=
3+
github.com/aws/aws-sdk-go-v2/config v1.26.2 h1:+RWLEIWQIGgrz2pBPAUoGgNGs1TOyF4Hml7hCnYj2jc=
4+
github.com/aws/aws-sdk-go-v2/config v1.26.2/go.mod h1:l6xqvUxt0Oj7PI/SUXYLNyZ9T/yBPn3YTQcJLLOdtR8=
5+
github.com/aws/aws-sdk-go-v2/credentials v1.16.13 h1:WLABQ4Cp4vXtXfOWOS3MEZKr6AAYUpMczLhgKtAjQ/8=
6+
github.com/aws/aws-sdk-go-v2/credentials v1.16.13/go.mod h1:Qg6x82FXwW0sJHzYruxGiuApNo31UEtJvXVSZAXeWiw=
7+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 h1:w98BT5w+ao1/r5sUuiH6JkVzjowOKeOJRHERyy1vh58=
8+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10/go.mod h1:K2WGI7vUvkIv1HoNbfBA1bvIZ+9kL3YVmWxeKuLQsiw=
9+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3 h1:ifbIbHZyGl1alsAhPIYsHOg5MuApgqOvVeI8wIugXfs=
10+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.3/go.mod h1:oQZXg3c6SNeY6OZrDY+xHcF4VGIEoNotX2B4PrDeoJI=
11+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3 h1:Qvodo9gHG9F3E8SfYOspPeBt0bjSbsevK8WhRAUHcoY=
12+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.3/go.mod h1:vCKrdLXtybdf/uQd/YfVR2r5pcbNuEYKzMQpcxmeSJw=
13+
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 h1:GrSw8s0Gs/5zZ0SX+gX4zQjRnRsMJDJ2sLur1gRBhEM=
14+
github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY=
15+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 h1:/b31bi3YVNlkzkBrm9LfpaKoaYZUxIAj4sHfOTmLfqw=
16+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4/go.mod h1:2aGXHFmbInwgP9ZfpmdIfOELL79zhdNYNmReK8qDfdQ=
17+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 h1:Nf2sHxjMJR8CSImIVCONRi4g0Su3J+TSTbS7G0pUeMU=
18+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9/go.mod h1:idky4TER38YIjr2cADF1/ugFMKvZV7p//pVeV5LZbF0=
19+
github.com/aws/aws-sdk-go-v2/service/signer v1.19.6 h1:Y4Rikb/krOWTfdy6dzQ2/WbBGRTTPcM6qAB+Mt0QKVo=
20+
github.com/aws/aws-sdk-go-v2/service/signer v1.19.6/go.mod h1:Y3u+41K5TVVkKhSlzZ+mtUI9z1k13TxpLtbJNHhV3fA=
21+
github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 h1:ldSFWz9tEHAwHNmjx2Cvy1MjP5/L9kNoR0skc6wyOOM=
22+
github.com/aws/aws-sdk-go-v2/service/sso v1.18.5/go.mod h1:CaFfXLYL376jgbP7VKC96uFcU8Rlavak0UlAwk1Dlhc=
23+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 h1:2k9KmFawS63euAkY4/ixVNsYYwrwnd5fIvgEKkfZFNM=
24+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5/go.mod h1:W+nd4wWDVkSUIox9bacmkBP5NMFQeTJ/xqNabpzSR38=
25+
github.com/aws/aws-sdk-go-v2/service/sts v1.26.6 h1:HJeiuZ2fldpd0WqngyMR6KW7ofkXNLyOaHwEIGm39Cs=
26+
github.com/aws/aws-sdk-go-v2/service/sts v1.26.6/go.mod h1:XX5gh4CB7wAs4KhcF46G6C8a2i7eupU19dcAAE+EydU=
27+
github.com/aws/smithy-go v1.20.1 h1:4SZlSlMr36UEqC7XOyRVb27XMeZubNcBNN+9IgEPIQw=
28+
github.com/aws/smithy-go v1.20.1/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
29+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
30+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
31+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
32+
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
33+
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
34+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
35+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
36+
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24 h1:liMMTbpW34dhU4az1GN0pTPADwNmvoRSeoZ6PItiqnY=
37+
github.com/jmespath/go-jmespath v0.4.1-0.20220621161143-b0104c826a24/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
38+
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
39+
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
40+
github.com/notaryproject/notation-plugin-framework-go v1.0.0 h1:6Qzr7DGXoCgXEQN+1gTZWuJAZvxh3p8Lryjn5FaLzi4=
41+
github.com/notaryproject/notation-plugin-framework-go v1.0.0/go.mod h1:RqWSrTOtEASCrGOEffq0n8pSg2KOgKYiWqFWczRSics=
42+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
43+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
44+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
45+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
46+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
47+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
48+
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
49+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
50+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
51+
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
52+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
53+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
54+
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
55+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
56+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
57+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
58+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
59+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
60+
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
61+
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
62+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
63+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
64+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
65+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
66+
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
67+
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
68+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
69+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
70+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
71+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
72+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
73+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
74+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
75+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
76+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/client/client.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Package client creates AWS service like AWS Signer client required by plugin.
2+
package client
3+
4+
import (
5+
"context"
6+
"fmt"
7+
8+
"github.com/aws/aws-signer-notation-plugin/internal/logger"
9+
"github.com/aws/aws-signer-notation-plugin/internal/version"
10+
11+
"github.com/aws/aws-sdk-go-v2/aws"
12+
"github.com/aws/aws-sdk-go-v2/config"
13+
"github.com/aws/aws-sdk-go-v2/service/signer"
14+
"github.com/aws/smithy-go/logging"
15+
"github.com/aws/smithy-go/middleware"
16+
"github.com/notaryproject/notation-plugin-framework-go/plugin"
17+
18+
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
19+
)
20+
21+
const (
22+
configKeyAwsProfile = "aws-profile"
23+
configKeyAwsRegion = "aws-region"
24+
configKeySignerEndpoint = "aws-signer-endpoint-url"
25+
)
26+
27+
// NewAWSSigner creates new AWS Signer client from given pluginConfig
28+
func NewAWSSigner(ctx context.Context, pluginConfig map[string]string) (*signer.Client, error) {
29+
log := logger.GetLogger(ctx)
30+
log.Debugln("Initializing Signer Client")
31+
loadOptions := getLoadOptions(ctx, pluginConfig)
32+
33+
// Use default config for aws credentials
34+
defaultConfig, err := config.LoadDefaultConfig(ctx, loadOptions...)
35+
if err != nil {
36+
return nil, plugin.NewGenericError(err.Error())
37+
}
38+
s, err := signer.NewFromConfig(defaultConfig), nil
39+
40+
log.Debugln("Initialized Signer Client")
41+
return s, err
42+
}
43+
44+
func getLoadOptions(ctx context.Context, pluginConfig map[string]string) []func(*config.LoadOptions) error {
45+
log := logger.GetLogger(ctx)
46+
var loadOptions []func(*config.LoadOptions) error
47+
if customEndpoint, ok := pluginConfig[configKeySignerEndpoint]; ok {
48+
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
49+
if service == signer.ServiceID && customEndpoint != "" {
50+
log.Debug("AWS Signer endpoint override: " + customEndpoint)
51+
return aws.Endpoint{
52+
PartitionID: "aws",
53+
URL: customEndpoint,
54+
SigningRegion: region,
55+
}, nil
56+
}
57+
// returning EndpointNotFoundError will allow the service to fall back to its default resolution
58+
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
59+
})
60+
loadOptions = append(loadOptions, config.WithEndpointResolverWithOptions(customResolver))
61+
}
62+
63+
if region, ok := pluginConfig[configKeyAwsRegion]; ok {
64+
loadOptions = append(loadOptions, config.WithRegion(region))
65+
log.Debugf("AWS Signer region override: %s\n", region)
66+
}
67+
68+
if credentialProfile, ok := pluginConfig[configKeyAwsProfile]; ok {
69+
loadOptions = append(loadOptions, config.WithSharedConfigProfile(credentialProfile))
70+
log.Debugf("AWS Signer credential profile: %s\n", credentialProfile)
71+
}
72+
73+
loadOptions = append(loadOptions, config.WithAPIOptions([]func(*middleware.Stack) error{
74+
awsmiddleware.AddUserAgentKeyValue("aws-signer-caller", "NotationPlugin/"+version.Version),
75+
}))
76+
77+
if log.IsDebug() {
78+
loadOptions = append(loadOptions, config.WithClientLogMode(aws.LogRequestWithBody|aws.LogResponseWithBody))
79+
loadOptions = append(loadOptions, config.WithLogConfigurationWarnings(true))
80+
loadOptions = append(loadOptions, config.WithLogger(logging.LoggerFunc(func(_ logging.Classification, format string, v ...interface{}) {
81+
log.Debugf("AWS call %s\n", fmt.Sprintf(format, v))
82+
})))
83+
}
84+
85+
return loadOptions
86+
}

internal/client/client_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"os"
6+
"testing"
7+
8+
"github.com/aws/aws-signer-notation-plugin/internal/logger"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestNewAWSSigner(t *testing.T) {
13+
tests := map[string]map[string]string{
14+
"emptyConfig": {},
15+
configKeySignerEndpoint: {configKeySignerEndpoint: "https://127.0.0.1:80/some-endpoint"},
16+
configKeyAwsRegion: {configKeyAwsRegion: "us-east-1"},
17+
}
18+
for name, config := range tests {
19+
t.Run(name, func(t *testing.T) {
20+
_, err := NewAWSSigner(context.TODO(), config)
21+
assert.Nil(t, err, "NewAWSSigner returned error")
22+
})
23+
}
24+
}
25+
26+
func TestNewAWSSigner_Debug(t *testing.T) {
27+
// we need this because build fleet might not have XDG_CONFIG_HOME set
28+
tempDir, _ := os.MkdirTemp("", "tempDir")
29+
defer os.RemoveAll(tempDir)
30+
t.Setenv("XDG_CONFIG_HOME", os.TempDir())
31+
32+
ctx := context.TODO()
33+
dl, _ := logger.New()
34+
ctx = dl.UpdateContext(ctx)
35+
_, err := NewAWSSigner(ctx, map[string]string{})
36+
assert.Nil(t, err, "NewAWSSigner returned error")
37+
}
38+
39+
func TestNewAWSSigner_InvalidProfile(t *testing.T) {
40+
// we need this because build fleet might not have XDG_CONFIG_HOME set
41+
tempDir, _ := os.MkdirTemp("", "tempDir")
42+
defer os.RemoveAll(tempDir)
43+
t.Setenv("XDG_CONFIG_HOME", os.TempDir())
44+
45+
ctx := context.TODO()
46+
dl, _ := logger.New()
47+
ctx = dl.UpdateContext(ctx)
48+
_, err := NewAWSSigner(ctx, map[string]string{configKeyAwsProfile: "someProfile"})
49+
assert.Error(t, err, "NewAWSSigner returned error")
50+
}

internal/client/interface.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package client
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/signer"
7+
)
8+
9+
// Interface facilitates unit testing
10+
type Interface interface {
11+
SignPayload(ctx context.Context, params *signer.SignPayloadInput, optFns ...func(*signer.Options)) (*signer.SignPayloadOutput, error)
12+
GetRevocationStatus(ctx context.Context, params *signer.GetRevocationStatusInput, optFns ...func(*signer.Options)) (*signer.GetRevocationStatusOutput, error)
13+
}

0 commit comments

Comments
 (0)