Skip to content

Commit

Permalink
chore: update dependencies & set cors allowed origins
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsOveTen committed Jan 7, 2025
1 parent 2bfaf22 commit 90d726f
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 174 deletions.
9 changes: 8 additions & 1 deletion config/env/env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package env

import "os"
import (
"os"
"strings"
)

func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
Expand All @@ -9,6 +12,10 @@ func getEnv(key, fallback string) string {
return fallback
}

func CorsOriginPatterns() []string {
return strings.Split(getEnv("CORS_ORIGIN_PATTERNS", "*"), ",")
}

func MongoHost() string {
return getEnv("MONGO_HOST", "localhost:27017")
}
Expand Down
9 changes: 6 additions & 3 deletions config/setupRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ func SetupRouter() *gin.Engine {

func corsMiddleware() gin.HandlerFunc {
corsConfig := cors.Config{
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"},
AllowOrigins: env.CorsOriginPatterns(),
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type", "Accept", "Authorization"},
AllowCredentials: true,
AllowWildcard: true,
AllowAllOrigins: false,
AllowCredentials: false,
AllowFiles: false,
MaxAge: 1 * time.Hour,
}
corsConfig.AllowAllOrigins = true
return cors.New(corsConfig)
}
2 changes: 2 additions & 0 deletions deploy/demo/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
secretKeyRef:
name: fdk-harvest-admin
key: API_KEY
- name: CORS_ORIGIN_PATTERNS
value: https://*.demo.fellesdatakatalog.digdir.no
volumes:
- name: error-reporting-sa
secret:
Expand Down
2 changes: 2 additions & 0 deletions deploy/prod/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
secretKeyRef:
name: fdk-harvest-admin
key: API_KEY
- name: CORS_ORIGIN_PATTERNS
value: https://*.fellesdatakatalog.digdir.no
volumes:
- name: error-reporting-sa
secret:
Expand Down
2 changes: 2 additions & 0 deletions deploy/staging/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ spec:
secretKeyRef:
name: fdk-harvest-admin
key: API_KEY
- name: CORS_ORIGIN_PATTERNS
value: https://*.staging.fellesdatakatalog.digdir.no,http://localhost:*
volumes:
- name: error-reporting-sa
secret:
Expand Down
65 changes: 32 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ go 1.22.7
toolchain go1.23.1

require (
cloud.google.com/go/errorreporting v0.3.1
cloud.google.com/go/errorreporting v0.3.2
github.com/Nerzal/gocloak/v13 v13.9.0
github.com/gin-contrib/cors v1.7.2
github.com/gin-contrib/cors v1.7.3
github.com/gin-gonic/gin v1.10.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
github.com/lestrrat-go/jwx v1.2.29
github.com/ory/dockertest/v3 v3.10.0
github.com/sirupsen/logrus v1.9.3
github.com/streadway/amqp v1.1.0
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
go.mongodb.org/mongo-driver v1.17.1
)

require (
cloud.google.com/go/auth v0.10.2 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
cloud.google.com/go/compute/metadata v0.5.2 // indirect
cloud.google.com/go/auth v0.13.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
cloud.google.com/go/compute/metadata v0.6.0 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/bytedance/sonic v1.12.4 // indirect
github.com/bytedance/sonic v1.12.6 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
Expand All @@ -40,26 +40,25 @@ require (
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.7 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/gin-contrib/sse v1.0.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.23.0 // indirect
github.com/go-resty/resty/v2 v2.16.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/go-resty/resty/v2 v2.16.2 // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
Expand Down Expand Up @@ -90,25 +89,25 @@ require (
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
golang.org/x/arch v0.12.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/api v0.207.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/grpc v1.68.0 // indirect
google.golang.org/protobuf v1.35.2 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.58.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.58.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.33.0 // indirect
golang.org/x/arch v0.13.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.9.0 // indirect
google.golang.org/api v0.214.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250102185135-69823020774d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250102185135-69823020774d // indirect
google.golang.org/grpc v1.69.2 // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 90d726f

Please sign in to comment.