Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API use env secrets #302

Merged
merged 5 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/api-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ jobs:
--platform=managed
--region=asia-northeast1
--add-cloudsql-instances=library-checker-sql
--update-env-vars=PG_HOST=/cloudsql/library-checker-project:asia-northeast1:library-checker-sql
--update-secrets=PG_PASS=postgre-pass:latest,HMAC_KEY=hmac-key:latest
--args=""
--set-env-vars=PG_HOST=/cloudsql/library-checker-project:asia-northeast1:library-checker-sql
--set-secrets=PG_TABLE=${{ inputs.env }}-pg-table:latest,PG_USER=${{ inputs.env }}-pg-user:latest,PG_PASS=${{ inputs.env }}-pg-pass:latest,HMAC_KEY=${{ inputs.env }}-hmac-key:latest
--service-account=cloud-run-api@library-checker-project.iam.gserviceaccount.com
--max-instances=10

Expand All @@ -75,7 +76,7 @@ jobs:
--region=asia-northeast1
--add-cloudsql-instances=library-checker-sql
--args=-grpcweb
--update-env-vars=PG_HOST=/cloudsql/library-checker-project:asia-northeast1:library-checker-sql
--update-secrets=PG_PASS=postgre-pass:latest,HMAC_KEY=hmac-key:latest
--set-env-vars=PG_HOST=/cloudsql/library-checker-project:asia-northeast1:library-checker-sql
--set-secrets=PG_TABLE=${{ inputs.env }}-pg-table:latest,PG_USER=${{ inputs.env }}-pg-user:latest,PG_PASS=${{ inputs.env }}-pg-pass:latest,HMAC_KEY=${{ inputs.env }}-hmac-key:latest
--service-account=cloud-run-api@library-checker-project.iam.gserviceaccount.com
--max-instances=10
2 changes: 1 addition & 1 deletion api/api.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env sh

./api -hmackey=$HMAC_KEY -pghost=$PG_HOST -pgpass=$PG_PASS $@
./api -hmackey=$HMAC_KEY -pghost=$PG_HOST -pgtable=$PG_TABLE -pguser=$PG_USER -pgpass=$PG_PASS $@
15 changes: 7 additions & 8 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ func main() {
isGRPCWeb := flag.Bool("grpcweb", false, "launch gRPCWeb server")

pgHost := flag.String("pghost", "127.0.0.1", "postgre host")
pgHostSecret := flag.String("pghost-secret", "", "gcloud secret of postgre host")
pgUser := flag.String("pguser", "postgres", "postgre user")
pgPass := flag.String("pgpass", "passwd", "postgre password")
pgPassSecret := flag.String("pgpass-secret", "", "gcloud secret of postgre password")
pgTable := flag.String("pgtable", "librarychecker", "postgre table name")

hmacKey := flag.String("hmackey", "", "hmac key")
hmacKeySecret := flag.String("hmackey-secret", "", "gcloud secret of hmac key")

portArg := flag.Int("port", -1, "port number")
flag.Parse()
Expand All @@ -133,13 +132,13 @@ func main() {

// connect db
db := dbConnect(
getSecureString(*pgHostSecret, *pgHost),
*pgHost,
getEnv("POSTGRE_PORT", "5432"),
"librarychecker",
getEnv("POSTGRE_USER", "postgres"),
getSecureString(*pgPassSecret, *pgPass),
*pgTable,
*pgUser,
*pgPass,
getEnv("API_DB_LOG", "") != "")
authTokenManager := NewAuthTokenManager(getSecureString(*hmacKeySecret, *hmacKey))
authTokenManager := NewAuthTokenManager(*hmacKey)
s := NewGRPCServer(db, authTokenManager, *langsTomlPath)

if *isGRPCWeb {
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ services:
- API_DB_LOG=true
- HMAC_KEY=dummy_secret
- PG_HOST=db
- PG_TABLE=librarychecker
- PG_USER=postgres
- PG_PASS=passwd
healthcheck:
test: grpc_health_probe -addr localhost:50051
Expand All @@ -74,6 +76,8 @@ services:
- API_DB_LOG=true
- HMAC_KEY=dummy_secret
- PG_HOST=db
- PG_TABLE=librarychecker
- PG_USER=postgres
- PG_PASS=passwd
healthcheck:
test: wget -q -O - localhost:50051/health || exit 1
Expand Down