diff --git a/internal/functions/wakeup/wake-up.go b/internal/functions/wakeup/wake-up.go index 5d71e444..f2d68ed3 100644 --- a/internal/functions/wakeup/wake-up.go +++ b/internal/functions/wakeup/wake-up.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/covid19cz/erouska-backend/internal/logging" "github.com/covid19cz/erouska-backend/internal/messaging" - "github.com/covid19cz/erouska-backend/internal/secrets" "net/http" "time" ) @@ -16,40 +15,18 @@ const topicName = "budicek" //SendWakeUpSignal Sends wake-up signal to devices func SendWakeUpSignal(w http.ResponseWriter, r *http.Request) { ctx := r.Context() + logger := logging.FromContext(ctx).Named("wake-up.SendWakeUpSignal") - secretClient := secrets.Client{} pushSender := messaging.Client{} - httpStatus, httpBody := sendWakeUpSignalAuthenticated(ctx, r, secretClient, pushSender) - - http.Error(w, httpBody, httpStatus) -} - -func sendWakeUpSignalAuthenticated(ctx context.Context, r *http.Request, secretClient secrets.Client, pushSender messaging.Client) (int, string) { - logger := logging.FromContext(ctx).Named("wake-up.sendWakeUpSignalAuthenticated") - - // authentication - - apikey, err := secretClient.Get("manual-wakeup-apikey") - if err != nil { - logger.Warnf("Could not obtain api key: %v", err) - return 500, "Could not obtain api key" - } - - providedAPIKeys := r.URL.Query()["apikey"] - if len(providedAPIKeys) != 1 || providedAPIKeys[0] != string(apikey) { - return 401, "Bad api key" - } - - // authenticated, go ahead - if err := sendWakeUpSignal(ctx, pushSender); err != nil { msg := fmt.Sprintf("Could not send wake-up signal: %v", err) logger.Error(msg) - return 500, msg + http.Error(w, msg, 500) + return } - return 200, "ok" + http.Error(w, "ok", 200) } func sendWakeUpSignal(ctx context.Context, msgClient messaging.PushSender) error { diff --git a/terraform/modules/erouska/coviddata.tf b/terraform/modules/erouska/coviddata.tf index ebe6062c..99ab49bb 100644 --- a/terraform/modules/erouska/coviddata.tf +++ b/terraform/modules/erouska/coviddata.tf @@ -376,27 +376,27 @@ resource "google_project_iam_member" "sendwakeupsignal-invoker" { member = "serviceAccount:${google_service_account.sendwakeupsignal-invoker.email}" } -//resource "google_cloud_scheduler_job" "sendwakeupsignal-worker" { -// name = "sendwakeupsignal-worker" -// region = var.cloudscheduler_location -// schedule = "0 */4 * * *" -// time_zone = "Europe/Prague" -// attempt_deadline = "600s" -// -// retry_config { -// retry_count = 1 -// } -// -// http_target { -// http_method = "GET" -// uri = data.google_cloudfunctions_function.sendwakeupsignal.https_trigger_url -// oidc_token { -// audience = data.google_cloudfunctions_function.sendwakeupsignal.https_trigger_url -// service_account_email = google_service_account.sendwakeupsignal-invoker.email -// } -// } -// -// depends_on = [ -// google_project_service.services["cloudscheduler.googleapis.com"], -// ] -//} +resource "google_cloud_scheduler_job" "sendwakeupsignal-worker" { + name = "sendwakeupsignal-worker" + region = var.cloudscheduler_location + schedule = "0 9 * * *" + time_zone = "Europe/Prague" + attempt_deadline = "600s" + + retry_config { + retry_count = 1 + } + + http_target { + http_method = "GET" + uri = data.google_cloudfunctions_function.sendwakeupsignal.https_trigger_url + oidc_token { + audience = data.google_cloudfunctions_function.sendwakeupsignal.https_trigger_url + service_account_email = google_service_account.sendwakeupsignal-invoker.email + } + } + + depends_on = [ + google_project_service.services["cloudscheduler.googleapis.com"], + ] +}