Skip to content

Commit

Permalink
Bump black from 22.3.0 to 24.3.0 in /cdk (sktan#15)
Browse files Browse the repository at this point in the history
Bumps [black](https://github.com/psf/black) from 22.3.0 to 24.3.0.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](psf/black@22.3.0...24.3.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and tomertcherniakhelloheart committed Jul 9, 2024
1 parent 29fac06 commit 458f5ed
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18-alpine as app-builder
FROM golang:1.20-alpine as app-builder
WORKDIR /go/src/app

COPY src .
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,42 @@ Use the following permissions to grant the proxy ReadOnly access to the CodeArti
]
}
```
## Metrics

Supporting prometheus counters :
```
proxy_request_counter
proxy_response_counter
aws_auth_error_counter
aws_url_error_counter
aws_config_error_counter
```
Prometheus endpoint is 8080 on /metrics

## Multiple path support

It is dynamic url creation based on the request , supporting multiple paths.

CodeArtifactAuthInfo.Url = fmt.Sprintf("%s/%s", extractBaseURL(CodeArtifactAuthInfo.Url), strings.TrimPrefix(r.URL.Path, "/"))

## Kubernetes deployments

svc.yaml and deployment.yaml which are found in deploy/kubernetes can be used to deploy.

The below env var should be set
```
- name: CODEARTIFACT_DOMAIN
value: ""
- name: CODEARTIFACT_REPO
value: ""
- name: CODEARTIFACT_OWNER
value: ""
- name: CODEARTIFACT_TYPE
value: ""
- name: AWS_REGION
value: ""
```


## Contributing

Expand Down
94 changes: 52 additions & 42 deletions cdk/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions deploy/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: artifactory-proxy
name: artifactory-proxy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: artifactory-proxy
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: artifactory-proxy
spec:
containers:
- env:
- name: CODEARTIFACT_DOMAIN
value: ""
- name: CODEARTIFACT_REPO
value: ""
- name: CODEARTIFACT_OWNER
value: ""
- name: CODEARTIFACT_TYPE
value: ""
- name: AWS_REGION
value: ""
image: image
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /metrics
port: 8080
initialDelaySeconds: 5
name: artifactory-proxy
ports:
- containerPort: 8080
protocol: TCP
readinessProbe:
httpGet:
path: /metrics
port: 8080
resources:
limits:
memory: 20Mi
requests:
cpu: 5m
memory: 10Mi
terminationGracePeriodSeconds: 30
16 changes: 16 additions & 0 deletions deploy/kubernetes/svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
piVersion: v1
kind: Service
metadata:
labels:
app: artifactory-proxy
name: artifactory-proxy
namespace: default
spec:
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: artifactory-proxy
type: ClusterIP
10 changes: 9 additions & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sktan/aws-codeartifact-proxy

go 1.18
go 1.20

require (
github.com/aws/aws-sdk-go-v2 v1.16.2
Expand All @@ -18,4 +18,12 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.11.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 // indirect
github.com/aws/smithy-go v1.11.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
golang.org/x/sys v0.16.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
)
16 changes: 16 additions & 0 deletions src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,30 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.16.3 h1:cJGRyzCSVwZC7zZZ1xbx9m32UnrK
github.com/aws/aws-sdk-go-v2/service/sts v1.16.3/go.mod h1:bfBj0iVmsUyUg4weDB4NxktD9rDGeKSVWnjTnwbx9b8=
github.com/aws/smithy-go v1.11.2 h1:eG/N+CcUMAvsdffgMvjMKwfyDzIkjM6pfxMJ8Mzc6mE=
github.com/aws/smithy-go v1.11.2/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU=
github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
31 changes: 30 additions & 1 deletion src/tools/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,34 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/codeartifact"
"github.com/aws/aws-sdk-go-v2/service/codeartifact/types"
"github.com/prometheus/client_golang/prometheus"
)

var awsAuthErrCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "aws_auth_error_counter",
},
)

var awsUrlErrCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "aws_url_error_counter",
},
)

var awsConfigErrCounter = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "aws_config_error_counter",
},
)

func init() {
// Register Prometheus metrics collectors
prometheus.MustRegister(awsAuthErrCounter)
prometheus.MustRegister(awsUrlErrCounter)
prometheus.MustRegister(awsConfigErrCounter)
}

type CodeArtifactAuthInfoStruct struct {
Url string
AuthorizationToken string
Expand All @@ -27,6 +53,7 @@ func Authenticate() {
// Authenticate against CodeArtifact
cfg, cfgErr := config.LoadDefaultConfig(context.TODO())
if cfgErr != nil {
awsConfigErrCounter.Inc()
log.Fatalf("unable to load SDK config, %v", cfgErr)
}
svc := codeartifact.NewFromConfig(cfg)
Expand Down Expand Up @@ -61,6 +88,7 @@ func Authenticate() {
}
authResp, authErr := svc.GetAuthorizationToken(context.TODO(), authInput)
if authErr != nil {
awsAuthErrCounter.Inc()
log.Fatalf("unable to get authorization token, %v", authErr)
}
log.Printf("Authorization successful")
Expand All @@ -81,7 +109,8 @@ func Authenticate() {

urlResp, urlErr := svc.GetRepositoryEndpoint(context.TODO(), urlInput)
if urlErr != nil {
log.Fatalf("unable to get repository endpoint, %v", urlErr)
awsUrlErrCounter.Inc()
log.Fatalf("unable to get repository endpoint, %v", urlErr)
}
CodeArtifactAuthInfo.Url = *urlResp.RepositoryEndpoint
mutex.Unlock()
Expand Down
Loading

0 comments on commit 458f5ed

Please sign in to comment.