diff --git a/apps/checker/checker/update.go b/apps/checker/checker/update.go index 6a0f3e62..8f530e80 100644 --- a/apps/checker/checker/update.go +++ b/apps/checker/checker/update.go @@ -4,14 +4,12 @@ import ( "bytes" "context" "encoding/json" - "fmt" - "github.com/rs/zerolog/log" - "google.golang.org/api/option" + "net/http" "os" + "time" + + "github.com/rs/zerolog/log" - "cloud.google.com/go/auth" - cloudtasks "cloud.google.com/go/cloudtasks/apiv2" - taskspb "cloud.google.com/go/cloudtasks/apiv2/cloudtaskspb" ) type UpdateData struct { @@ -24,67 +22,24 @@ type UpdateData struct { Latency int64 `json:"latency,omitempty"` } -func UpdateStatus(ctx context.Context, updateData UpdateData) error { - +func UpdateStatus(ctx context.Context, updateData UpdateData) { url := "https://openstatus-workflows.fly.dev/updateStatus" basic := "Basic " + os.Getenv("CRON_SECRET") payloadBuf := new(bytes.Buffer) - opts := &auth.Options2LO{ - Email: os.Getenv("GCP_CLIENT_EMAIL"), - PrivateKey: []byte(os.Getenv("GCP_PRIVATE_KEY")), - PrivateKeyID: os.Getenv("GCP_PRIVATE_KEY_ID"), - Scopes: []string{ - "https://www.googleapis.com/auth/cloud-platform", - }, - TokenURL: "https://oauth2.googleapis.com/token", - } - - tp, err := auth.New2LOTokenProvider(opts) - if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("error while creating token provider") - return err - } - - creds := auth.NewCredentials(&auth.CredentialsOptions{ - TokenProvider: tp, - }) - - client, err := cloudtasks.NewClient(ctx, option.WithAuthCredentials(creds)) - if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("error while creating cloud tasks client") - - } - defer client.Close() - if err := json.NewEncoder(payloadBuf).Encode(updateData); err != nil { log.Ctx(ctx).Error().Err(err).Msg("error while updating status") - return err + return } - projectID := os.Getenv("GCP_PROJECT_ID") - queuePath := fmt.Sprintf("projects/%s/locations/europe-west1/queues/alerting", projectID) - req := &taskspb.CreateTaskRequest{ - Parent: queuePath, - Task: &taskspb.Task{ - // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#HttpRequest - MessageType: &taskspb.Task_HttpRequest{ - HttpRequest: &taskspb.HttpRequest{ - HttpMethod: taskspb.HttpMethod_POST, - Url: url, - Headers: map[string]string{"Authorization": basic, "Content-Type": "application/json"}, - }, - }, - }, - } - - // Add a payload message if one is present. - req.Task.GetHttpRequest().Body = payloadBuf.Bytes() + req, _ := http.NewRequestWithContext(ctx, http.MethodPost, url, payloadBuf) + req.Header.Set("Authorization", basic) + req.Header.Set("Content-Type", "application/json") - _, err = client.CreateTask(ctx, req) - if err != nil { - log.Ctx(ctx).Error().Err(err).Msg("error while creating the cloud task") - return fmt.Errorf("cloudtasks.CreateTask: %w", err) + client := &http.Client{Timeout: time.Second * 10} + if _, err := client.Do(req); err != nil { + log.Ctx(ctx).Error().Err(err).Msg("error while updating status") } - return nil + defer req.Body.Close() + // Should we add a retry mechanism here? }