diff --git a/.gitignore b/.gitignore index 4bb993a..b7c2c85 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +app-*.yaml # Test binary, build with `go test -c` *.test diff --git a/src/commenting/app/app.yaml.template b/src/commenting/app/app.yaml.template new file mode 100644 index 0000000..dd5c639 --- /dev/null +++ b/src/commenting/app/app.yaml.template @@ -0,0 +1,21 @@ +application: +runtime: +api_version: go1.8 +version: 1 +module: commenting + +threadsafe: true + +handlers: + - url: /_ah/push-handlers/.* + script: main.APPLICATION + login: admin + - url: /.* + script: _go_app + secure: always + +env_variables: + APP_ID: + SERVICE_ACCOUNT_PATH: + IS_PRODUCTION: + GOOGLE_APPLICATION_CREDENTIALS: diff --git a/src/notification/app/app-dev.yaml b/src/notification/app/app-dev.yaml index 195581a..057e29a 100644 --- a/src/notification/app/app-dev.yaml +++ b/src/notification/app/app-dev.yaml @@ -19,3 +19,5 @@ env_variables: SERVICE_ACCOUNT_PATH: ./secrets/comment-api-dev-9162d86d5ce8.json IS_PRODUCTION: false GOOGLE_APPLICATION_CREDENTIALS: ./secrets/comment-api-dev-9162d86d5ce8.json + ADMIN_EMAIL: ikenox@gmail.com + SENDER_EMAIL: ikenox@gmail.com diff --git a/src/notification/app/app-prod.yaml b/src/notification/app/app-prod.yaml index 3da03d2..39ab897 100644 --- a/src/notification/app/app-prod.yaml +++ b/src/notification/app/app-prod.yaml @@ -19,3 +19,5 @@ env_variables: SERVICE_ACCOUNT_PATH: ./secrets/ikenox-info-comment-api-75b6f4b1fb2f.json IS_PRODUCTION: true GOOGLE_APPLICATION_CREDENTIALS: ./secrets/ikenox-info-comment-api-75b6f4b1fb2f.json + ADMIN_EMAIL: ikenox@gmail.com + SENDER_EMAIL: ikenox@gmail.com diff --git a/src/notification/app/app.yaml.template b/src/notification/app/app.yaml.template new file mode 100644 index 0000000..d06d932 --- /dev/null +++ b/src/notification/app/app.yaml.template @@ -0,0 +1,23 @@ +application: +runtime: go +api_version: go1.8 +version: 1 +module: notification + +threadsafe: true + +handlers: + - url: /_ah/push-handlers/.* + script: main.APPLICATION + login: admin + - url: /.* + script: _go_app + secure: always + +env_variables: + APP_ID: + SERVICE_ACCOUNT_PATH: + IS_PRODUCTION: + GOOGLE_APPLICATION_CREDENTIALS: + ADMIN_EMAIL: + SENDER_EMAIL: diff --git a/src/notification/env/env.go b/src/notification/env/env.go index 19ab59e..5ab05e4 100644 --- a/src/notification/env/env.go +++ b/src/notification/env/env.go @@ -1,28 +1,25 @@ package env import ( - "google.golang.org/api/option" "os" - "path/filepath" - "time" ) // application globals // アプリにとって普遍とみなせる値や関数、環境変数など? // どこからでも使われるような値や概念はRepositoryにするよりグローバル変数にしてしまったほうが楽そう var Namespace string -var CurrentTime func() time.Time var IsProduction bool -var GCPCredentialOption option.ClientOption var ProjectID string +var AdminEmail string +var SenderEmail string func init() { ProjectID = os.Getenv("APP_ID") IsProduction = os.Getenv("IS_PRODUCTION") == "True" - // time - CurrentTime = time.Now + AdminEmail = os.Getenv("ADMIN_EMAIL") + SenderEmail = os.Getenv("SENDER_EMAIL") // namespace if ns := os.Getenv("NAMESPACE"); ns != "" { @@ -30,10 +27,4 @@ func init() { } else { Namespace = "" } - - path, err := filepath.Abs(os.Getenv("SERVICE_ACCOUNT_PATH")) - if err != nil { - panic(err.Error()) - } - GCPCredentialOption = option.WithCredentialsFile(path) } diff --git a/src/notification/usecase/admin.go b/src/notification/usecase/admin.go index 6833296..6d86f3b 100644 --- a/src/notification/usecase/admin.go +++ b/src/notification/usecase/admin.go @@ -8,14 +8,12 @@ import ( "notification/env" ) -var systemAdmin = fmt.Sprintf("ikenox+%s@gmail.com", env.ProjectID) - // TODO CleanArchitectureで書き直し // 現状だとtoo muchだけど、メールとかの送信部分はラップして共通化しておくべき func NotifyCommentPosted(ctx context.Context, commentId int64, pageId, name, text string) { msg := &mail.Message{ - Sender: systemAdmin, - To: []string{systemAdmin}, + Sender: env.SenderEmail, + To: []string{env.AdminEmail}, Subject: "コメントが投稿されました", Body: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text), HTMLBody: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text), @@ -28,8 +26,8 @@ func NotifyCommentPosted(ctx context.Context, commentId int64, pageId, name, tex func NotifyCommentDeleted(ctx context.Context, commentId int64, pageId, name, text string) { msg := &mail.Message{ - Sender: systemAdmin, - To: []string{systemAdmin}, + Sender: env.SenderEmail, + To: []string{env.AdminEmail}, Subject: "コメントが削除されました", Body: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text), HTMLBody: fmt.Sprintf("commentId:%dpageId:%s\nname:%s\ntext:%s\n", commentId, pageId, name, text),