Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.24.1
25 changes: 25 additions & 0 deletions cmds/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module pass-coding-interview

go 1.24.1

Check warning on line 3 in go.mod

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

go.mod#L3

Insecure dependency golang/stdlib@v1.24.1 (CVE-2025-0913: Inconsistent handling of O_CREATE|O_EXCL on Unix and Windows in os in syscall) (update to 1.24.4)

Check warning on line 3 in go.mod

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

go.mod#L3

Insecure dependency golang/stdlib@v1.24.1 (CVE-2025-22871: net/http: Request smuggling due to acceptance of invalid chunked data in net/http) (update to 1.24.2)

Check warning on line 3 in go.mod

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

go.mod#L3

Insecure dependency golang/stdlib@v1.24.1 (CVE-2025-22874: crypto/x509: Usage of ExtKeyUsageAny disables policy validation in crypto/x509) (update to 1.24.4)

Check warning on line 3 in go.mod

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

go.mod#L3

Insecure dependency golang/stdlib@v1.24.1 (CVE-2025-4673: net/http: Sensitive headers not cleared on cross-origin redirect in net/http) (update to 1.24.4)

Check warning on line 3 in go.mod

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

go.mod#L3

Insecure dependency golang/stdlib@v1.24.1 (CVE-2025-47906: os/exec: Unexpected paths returned from LookPath in os/exec) (update to 1.24.6)

Check warning on line 3 in go.mod

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

go.mod#L3

Insecure dependency golang/stdlib@v1.24.1 (CVE-2025-47907: database/sql: Postgres Scan Race Condition) (update to 1.24.6)
16 changes: 16 additions & 0 deletions internal/outbound/argocd/argocd.go
Original file line number Diff line number Diff line change
@@ -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
}
77 changes: 77 additions & 0 deletions internal/outbound/datadog/datadog.go
Original file line number Diff line number Diff line change
@@ -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
}