Skip to content

Commit

Permalink
Merge branch 'master' into karina/bcda-7415-ctx-logger
Browse files Browse the repository at this point in the history
  • Loading branch information
karinamzalez authored Jan 25, 2024
2 parents bb25b60 + c3c780f commit a771e2c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Dockerfiles/Dockerfile.ssas
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ RUN go build -ldflags "-X github.com/CMSgov/bcda-ssas-app/ssas/constants.Version
FROM golang:1.19-alpine3.15
RUN apk update upgrade
RUN apk --no-cache add ca-certificates aws-cli curl
WORKDIR /go/src/github.com/CMSgov/bcda-ssas-app
COPY --from=builder /go/src/github.com/CMSgov/bcda-ssas-app/ssas/cfg/configs ssas/cfg/configs
WORKDIR /usr/local/bin
COPY --from=builder /go/src/github.com/CMSgov/bcda-ssas-app/ssas/ssas .
COPY --from=documentation /go/src/github.com/CMSgov/bcda-ssas-app/ssas/swaggerui ./swaggerui
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ services:
dockerfile: Dockerfiles/Dockerfile.tests
args:
VERSION: latest
env_file:
- ./ssas/cfg/configs/local.env
environment:
- DB=postgresql://postgres:toor@db:5432
- DATABASE_URL=postgresql://postgres:toor@db:5432/bcda?sslmode=disable
- BCDA_SSAS_CLIENT_ID=fake-client-id
- BCDA_SSAS_SECRET=fake-secret
- DEPLOYMENT_TARGET=local
- SSAS_ADMIN_SIGNING_KEY_PATH=../../../shared_files/ssas/admin_test_signing_key.pem
- SSAS_PUBLIC_SIGNING_KEY_PATH=../../../shared_files/ssas/public_test_signing_key.pem
- SSAS_PUBLIC_PORT=:3003
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ services:
args:
VERSION: latest
image: bcda-ssas:latest
env_file:
- ./ssas/cfg/configs/local.env
environment:
- DATABASE_URL=postgresql://postgres:toor@db:5432/bcda?sslmode=disable
- ATO_PUBLIC_KEY_FILE=../shared_files/ATO_public.pem
Expand All @@ -34,7 +32,6 @@ services:
- BCDA_AUTH_PROVIDER=${BCDA_AUTH_PROVIDER}
- BCDA_SSAS_CLIENT_ID=${BCDA_SSAS_CLIENT_ID}
- BCDA_SSAS_SECRET=${BCDA_SSAS_SECRET}
- DEBUG=true
- DEPLOYMENT_TARGET=local
- SSAS_ADMIN_SIGNING_KEY_PATH=../shared_files/ssas/admin_test_signing_key.pem
- SSAS_PUBLIC_SIGNING_KEY_PATH=../shared_files/ssas/public_test_signing_key.pem
Expand All @@ -50,6 +47,7 @@ services:
- SSAS_CLIENT_ASSERTION_AUD=http://local.testing.cms.gov/api/v2/Token/auth
volumes:
- ./shared_files:/usr/local/shared_files
- .:/go/src/github.com/CMSgov/bcda-ssas-app
ports:
- "3103:3003"
- "3104:3004"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/magiconair/properties v1.8.6 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
Expand Down
2 changes: 1 addition & 1 deletion ops/build_and_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ go clean
echo "Building ssas..."
go build -ldflags "-X github.com/CMSgov/bcda-ssas-app/ssas/constants.Version=$VERSION" -o ssas ./service/main
echo "Packaging ssas binary into RPM..."
fpm -v $VERSION -s dir -t rpm -n ssas ssas=/usr/local/bin/ssas swaggerui=/etc/sv/ssas
fpm -v $VERSION -s dir -t rpm -n ssas ssas=/usr/local/bin/ssas swaggerui=/etc/sv/ssas cfg/configs/=/go/src/github.com/CMSgov/bcda-ssas-app/ssas/cfg/configs/


#Sign RPMs
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/dev.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=TRUE
DEPLOYMENT_TARGET=dev
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/local.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=TRUE
DEPLOYMENT_TARGET=local
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/opensbx.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=FALSE
DEPLOYMENT_TARGET=opensbx
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/prod.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=FALSE
DEPLOYMENT_TARGET=prod
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/test.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=FALSE
DEPLOYMENT_TARGET=test
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
4 changes: 3 additions & 1 deletion ssas/service/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Until you click logout your token will be presented with every request made. To
swagger:meta
*/
//nolint: lll

//nolint: lll // Ignore long line linting

package main

Expand Down Expand Up @@ -80,6 +81,7 @@ func init() {
if nil != err {
logger.Warnf("New Relic integration is disabled: %s", err)
}

}

// We provide some simple commands for bootstrapping the system into place. Commands cannot be combined.
Expand Down
29 changes: 22 additions & 7 deletions ssas/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"go/build"
"io"
"net"
"os"
Expand All @@ -18,6 +19,7 @@ import (

"github.com/CMSgov/bcda-ssas-app/log"
"github.com/CMSgov/bcda-ssas-app/ssas/cfg"
"github.com/joho/godotenv"
"github.com/pborman/uuid"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
Expand All @@ -33,15 +35,28 @@ func init() {
}

func getEnvVars() {
DefaultScope = os.Getenv("SSAS_DEFAULT_SYSTEM_SCOPE")
env := os.Getenv("DEPLOYMENT_TARGET")
gopath := os.Getenv("GOPATH")

if gopath == "" {
gopath = build.Default.GOPATH
//when GOROOT==gopath, it'll still be empty. Thus, we specify what's in our Dockerfile.
if gopath == "" {
gopath = "/go"
}

}

envPath := fmt.Sprintf(gopath+"/src/github.com/CMSgov/bcda-ssas-app/ssas/cfg/configs/%s.env", env)
err := godotenv.Load(envPath)

if err != nil {
ServiceHalted(Event{Help: fmt.Sprintf("Unable to load environment variables in env %s; message: %s", env, err.Error())})
panic("Unable to start application without loading environment variables.")
}
DefaultScope = os.Getenv("SSAS_DEFAULT_SYSTEM_SCOPE")
if DefaultScope == "" {
if os.Getenv("DEBUG") == "true" {
DefaultScope = "bcda-api"
return
}
log.GetCtxLogger(context.Background()).Info(logrus.Fields{"Event": "ServiceHalted", "Help": "SSAS_DEFAULT_SYSTEM_SCOPE environment value must be set"})
panic("SSAS_DEFAULT_SYSTEM_SCOPE environment value must be set")
panic("Unable to source default system scope; check env files")
}

expirationDays := cfg.GetEnvInt("SSAS_CRED_EXPIRATION_DAYS", 90)
Expand Down
9 changes: 9 additions & 0 deletions ssas/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ func (s *SystemsTestSuite) TestScopeEnvSuccess() {
assert.Nil(s.T(), err)
}

func (s *SystemsTestSuite) TestEmptyGoPath() {
err := os.Setenv("GOPATH", "")
if err != nil {
s.FailNow(err.Error())
}
getEnvVars()
assert.Equal(s.T(), "bcda-api", DefaultScope)
}

func (s *SystemsTestSuite) TestScopeEnvDebug() {
getEnvVars()
assert.Equal(s.T(), "bcda-api", DefaultScope)
Expand Down

0 comments on commit a771e2c

Please sign in to comment.