mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-19 05:55:19 +00:00
set function identity in deployments
This commit is contained in:
@@ -25,7 +25,10 @@ type GoogleFunction struct {
|
|||||||
project string
|
project string
|
||||||
// eg. https://us-central1-m3o-apis.cloudfunctions.net/
|
// eg. https://us-central1-m3o-apis.cloudfunctions.net/
|
||||||
address string
|
address string
|
||||||
|
// max functions deployed
|
||||||
limit int
|
limit int
|
||||||
|
// function identity
|
||||||
|
identity string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -90,6 +93,11 @@ func NewFunction() *GoogleFunction {
|
|||||||
log.Fatalf("function.service_account: %v", err)
|
log.Fatalf("function.service_account: %v", err)
|
||||||
}
|
}
|
||||||
accName := v.String("")
|
accName := v.String("")
|
||||||
|
v, err = config.Get("function.service_identity")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("function.service_identity: %v", err)
|
||||||
|
}
|
||||||
|
identity := v.String("")
|
||||||
|
|
||||||
m := map[string]interface{}{}
|
m := map[string]interface{}{}
|
||||||
err = json.Unmarshal(keyfile, &m)
|
err = json.Unmarshal(keyfile, &m)
|
||||||
@@ -117,7 +125,12 @@ func NewFunction() *GoogleFunction {
|
|||||||
log.Fatalf(string(outp))
|
log.Fatalf(string(outp))
|
||||||
}
|
}
|
||||||
log.Info(string(outp))
|
log.Info(string(outp))
|
||||||
return &GoogleFunction{project: project, address: address, limit: limit}
|
return &GoogleFunction{
|
||||||
|
project: project,
|
||||||
|
address: address,
|
||||||
|
limit: limit,
|
||||||
|
identity: identity,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *GoogleFunction) Deploy(ctx context.Context, req *function.DeployRequest, rsp *function.DeployResponse) error {
|
func (e *GoogleFunction) Deploy(ctx context.Context, req *function.DeployRequest, rsp *function.DeployResponse) error {
|
||||||
@@ -210,7 +223,7 @@ func (e *GoogleFunction) Deploy(ctx context.Context, req *function.DeployRequest
|
|||||||
go func() {
|
go func() {
|
||||||
// https://jsoverson.medium.com/how-to-deploy-node-js-functions-to-google-cloud-8bba05e9c10a
|
// https://jsoverson.medium.com/how-to-deploy-node-js-functions-to-google-cloud-8bba05e9c10a
|
||||||
cmd := exec.Command("gcloud", "functions", "deploy",
|
cmd := exec.Command("gcloud", "functions", "deploy",
|
||||||
multitenantPrefix+"-"+req.Name, "--region", "europe-west1",
|
multitenantPrefix+"-"+req.Name, "--region", "europe-west1", "--service-account", e.identity,
|
||||||
"--allow-unauthenticated", "--entry-point", req.Entrypoint,
|
"--allow-unauthenticated", "--entry-point", req.Entrypoint,
|
||||||
"--trigger-http", "--project", e.project, "--runtime", req.Runtime)
|
"--trigger-http", "--project", e.project, "--runtime", req.Runtime)
|
||||||
|
|
||||||
@@ -306,7 +319,7 @@ func (e *GoogleFunction) Update(ctx context.Context, req *function.UpdateRequest
|
|||||||
go func() {
|
go func() {
|
||||||
// https://jsoverson.medium.com/how-to-deploy-node-js-functions-to-google-cloud-8bba05e9c10a
|
// https://jsoverson.medium.com/how-to-deploy-node-js-functions-to-google-cloud-8bba05e9c10a
|
||||||
cmd := exec.Command("gcloud", "functions", "deploy",
|
cmd := exec.Command("gcloud", "functions", "deploy",
|
||||||
multitenantPrefix+"-"+req.Name, "--region", "europe-west1",
|
multitenantPrefix+"-"+req.Name, "--region", "europe-west1", "--service-account", e.identity,
|
||||||
"--allow-unauthenticated", "--entry-point", req.Entrypoint,
|
"--allow-unauthenticated", "--entry-point", req.Entrypoint,
|
||||||
"--trigger-http", "--project", e.project, "--runtime", req.Runtime)
|
"--trigger-http", "--project", e.project, "--runtime", req.Runtime)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user