diff --git a/go-client/windmill.go b/go-client/windmill.go index fd0446e14b..7fde732aab 100644 --- a/go-client/windmill.go +++ b/go-client/windmill.go @@ -4,9 +4,12 @@ import ( "context" "errors" "fmt" + "math" + "math/rand" "net/http" "os" + "github.com/google/uuid" api "github.com/windmill-labs/windmill-go-client/api" ) @@ -154,3 +157,37 @@ func SetState(state interface{}) error { } return nil } + +type ResumeUrls struct { + ApprovalPage string `json:"approvalPage"` + Cancel string `json:"cancel"` + Resume string `json:"resume"` +} + +func GetResumeUrls(approver string) (ResumeUrls, error) { + var urls ResumeUrls + client, err := GetClient() + if err != nil { + return urls, err + } + jobId, err := uuid.Parse(os.Getenv("WM_JOB_ID")) + if err != nil { + return urls, err + } + params := api.GetResumeUrlsParams{Approver: &approver} + nonce := rand.Intn(int(math.MaxUint32)) + res, err := client.Client.GetResumeUrlsWithResponse(context.Background(), + client.Workspace, + jobId, + nonce, + ¶ms, + ) + if err != nil { + return urls, err + } + if res.StatusCode()/100 != 2 { + return urls, errors.New(string(res.Body)) + } + urls = *res.JSON200 + return urls, nil +}