diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..7b4fd64 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +golang 1.24.1 \ No newline at end of file diff --git a/cmds/main.go b/cmds/main.go new file mode 100644 index 0000000..c69caa2 --- /dev/null +++ b/cmds/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "os" + "pass-coding-interview/internal/outbound/argocd" + "pass-coding-interview/internal/outbound/datadog" +) + +func main() { + applicationFlag := "test" + // check if the file + scheduleId, err := datadog.CreateSchedule(applicationFlag) + if err != nil { + os.Exit(1) + } + // check if there is an application currently sync + err = argocd.SyncArgoCDApp(applicationFlag) + if err != nil { + os.Exit(2) + } + err = datadog.CancelSchedule(scheduleId) + if err != nil { + os.Exit(3) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f7ef8e3 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module pass-coding-interview + +go 1.24.1 diff --git a/internal/outbound/argocd/argocd.go b/internal/outbound/argocd/argocd.go new file mode 100644 index 0000000..77adadb --- /dev/null +++ b/internal/outbound/argocd/argocd.go @@ -0,0 +1,16 @@ +package argocd + +import ( + "fmt" + "log" +) + +func SyncArgoCDApp(applicationName string) error { + requestURL := fmt.Sprintf("https://cd.apps.argoproj.io/api/v1/applications/%s/sync", applicationName) + //req, err := http.NewRequest(http.MethodPost, requestURL, bodyReader) + if err != nil { + log.Printf("an error occured in the SyncArgoCDApp method: %s", err) + return "", err + } + return nil +} diff --git a/internal/outbound/datadog/datadog.go b/internal/outbound/datadog/datadog.go new file mode 100644 index 0000000..7b94e77 --- /dev/null +++ b/internal/outbound/datadog/datadog.go @@ -0,0 +1,77 @@ +package datadog + +import ( + "encoding/json" + "fmt" + "log" + "time" +) + +type ScheduleDowntime struct { + Attributes *ScheduleDowntimeAttributes `json:"attributes"` + Type string `json:"type"` +} + +type ScheduleDowntimeAttributes struct { + Schedule *ScheduleDowntimeSchedule `json:"schedule"` + Scope string `json:"scope"` +} + +type ScheduleDowntimeSchedule struct { + Start string `json:"start"` +} + +func CreateSchedule(applicationName string) (string, error) { + + jsonBody, err := json.Marshal(ScheduleDowntime{ + Attributes: &ScheduleDowntimeAttributes{ + Schedule: &ScheduleDowntimeSchedule{ + Start: time.Now().UTC().String(), + }, + Scope: applicationName, + }, + }) + // bodyReader := bytes.NewReader(jsonBody) + + //requestUrl := "https://api.datadoghq.com/api/v2/downtime" + //req, err := http.NewRequest(http.MethodPost, requestURL, bodyReader) + if err != nil { + log.Printf("an error occured in the CreateSchedule method: %s", err) + return "", err + } + return "hardcoded-id", nil +} + +func CreateSchedule(applicationName string) (string, error) { + jsonBody, err := json.Marshal(ScheduleDowntime{ + Attributes: &ScheduleDowntimeAttributes{ + Schedule: &ScheduleDowntimeSchedule{ + Start: time.Now().UTC().String(), + }, + Scope: applicationName, + }, + }) + if err != nil { + log.Printf("an error occured in the CreateSchedule method: %s", err) + return "", err + } + // bodyReader := bytes.NewReader(jsonBody) + + //requestUrl := "https://api.datadoghq.com/api/v2/downtime" + //req, err := http.NewRequest(http.MethodPost, requestURL, bodyReader) + if err != nil { + log.Printf("an error occured in the CreateSchedule method: %s", err) + return "", err + } + return "hardcoded-id", nil +} + +func CancelSchedule(id string) error { + requestURL := fmt.Sprintf("https://api.datadoghq.com/api/v2/downtime/%s", id) + //req, err := http.NewRequest(http.MethodDelete, requestURL, bodyReader)" + if err != nil { + log.Printf("an error occured in the CreateSchedule method: %s", err) + return "", err + } + return nil +}