Skip to content

Commit

Permalink
chore: use ID in public types instead of name (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams authored Oct 3, 2024
1 parent 4191e9e commit 6ae1971
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions apiclient/types/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type CronJob struct {
}

type CronJobManifest struct {
Description string `json:"description,omitempty"`
Schedule string `json:"schedule,omitempty"`
WorkflowName string `json:"workflowName,omitempty"`
Input string `json:"input,omitempty"`
Description string `json:"description,omitempty"`
Schedule string `json:"schedule,omitempty"`
WorkflowID string `json:"workflowID,omitempty"`
Input string `json:"input,omitempty"`
}

type CronJobList List[CronJob]
2 changes: 1 addition & 1 deletion apiclient/types/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Webhook struct {
type WebhookManifest struct {
Description string `json:"description,omitempty"`
RefName string `json:"refName,omitempty"`
WorkflowName string `json:"workflowName,omitempty"`
WorkflowID string `json:"workflowID,omitempty"`
AfterWorkflowStepName string `json:"afterWorkflowStepName,omitempty"`
Headers []string `json:"headers,omitempty"`
Secret string `json:"secret,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/handlers/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (a *CronJobHandler) Execute(req api.Context) error {
return err
}

workflowID := cronJob.Spec.WorkflowName
workflowID := cronJob.Spec.WorkflowID
if !system.IsWorkflowID(workflowID) {
var ref v1.Reference
if err := req.Get(&ref, workflowID); err != nil || ref.Spec.WorkflowName == "" {
Expand Down Expand Up @@ -162,10 +162,10 @@ func parseAndValidateCronManifest(req api.Context) (*types.CronJobManifest, erro
}

var workflow v1.Workflow
if err := req.Get(&workflow, manifest.WorkflowName); types.IsNotFound(err) {
if err := req.Get(&workflow, manifest.WorkflowID); types.IsNotFound(err) {
var ref v1.Reference
if err = req.Get(&ref, manifest.WorkflowName); err != nil || ref.Spec.WorkflowName == "" {
return nil, apierrors.NewBadRequest(fmt.Sprintf("workflow %s does not exist", manifest.WorkflowName))
if err = req.Get(&ref, manifest.WorkflowID); err != nil || ref.Spec.WorkflowName == "" {
return nil, apierrors.NewBadRequest(fmt.Sprintf("workflow %s does not exist", manifest.WorkflowID))
}
} else if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/handlers/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (a *WebhookHandler) Execute(req api.Context) error {
input.WriteString(req.Request.Header.Get(k))
}

workflowID := webhook.Spec.WebhookManifest.WorkflowName
workflowID := webhook.Spec.WebhookManifest.WorkflowID
if !system.IsWorkflowID(workflowID) {
var ref v1.Reference
if err = req.Get(&ref, workflowID); err != nil || ref.Spec.WorkflowName == "" {
Expand Down Expand Up @@ -238,16 +238,16 @@ func validateSecretHeader(secret string, body []byte, values []string) error {
}

func validateManifest(req api.Context, manifest types.WebhookManifest) error {
// Ensure that the WorkflowName is set and the workflow exists
if manifest.WorkflowName == "" {
// Ensure that the WorkflowID is set and the workflow exists
if manifest.WorkflowID == "" {
return apierrors.NewBadRequest(fmt.Sprintf("webhook manifest must have a workflow name"))
}

var workflow v1.Workflow
if err := req.Get(&workflow, manifest.WorkflowName); types.IsNotFound(err) {
if err := req.Get(&workflow, manifest.WorkflowID); types.IsNotFound(err) {
var ref v1.Reference
if err = req.Get(&ref, manifest.WorkflowName); err != nil || ref.Spec.WorkflowName == "" {
return apierrors.NewBadRequest(fmt.Sprintf("workflow %s does not exist", manifest.WorkflowName))
if err = req.Get(&ref, manifest.WorkflowID); err != nil || ref.Spec.WorkflowName == "" {
return apierrors.NewBadRequest(fmt.Sprintf("workflow %s does not exist", manifest.WorkflowID))
}
} else if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/handlers/cronjob/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (h *Handler) Run(req router.Request, resp router.Response) error {
return nil
}

workflowID := cj.Spec.WorkflowName
workflowID := cj.Spec.WorkflowID
if !system.IsWorkflowID(workflowID) {
var ref v1.Reference
if err = req.Get(&ref, cj.Namespace, workflowID); err != nil || ref.Spec.WorkflowName == "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.gptscript.ai/v1/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type CronJob struct {
func (*CronJob) GetColumns() [][]string {
return [][]string{
{"Name", "Name"},
{"Workflow", "Spec.WorkflowName"},
{"Workflow", "Spec.WorkflowID"},
{"Schedule", "Spec.Schedule"},
{"Last Success", "{{agoptr .Status.LastSuccessfulRunCompleted}}"},
{"Last Run", "{{agoptr .Status.LastRunStartedAt}}"},
Expand All @@ -33,7 +33,7 @@ func (*CronJob) GetColumns() [][]string {

func (c *CronJob) DeleteRefs() []Ref {
return []Ref{
{ObjType: new(Workflow), Name: c.Spec.WorkflowName},
{ObjType: new(Workflow), Name: c.Spec.WorkflowID},
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/apis/otto.gptscript.ai/v1/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (*Webhook) GetColumns() [][]string {
return [][]string{
{"Name", "Name"},
{"RefName", "Spec.RefName"},
{"Workflow", "Spec.WorkflowName"},
{"Workflow", "Spec.WorkflowID"},
{"Created", "{{ago .CreationTimestamp}}"},
{"Last Success", "{{agoptr .Status.LastSuccessfulRunCompleted}}"},
{"Description", "Spec.Description"},
Expand All @@ -33,7 +33,7 @@ func (*Webhook) GetColumns() [][]string {

func (w *Webhook) DeleteRefs() []Ref {
return []Ref{
{ObjType: new(Workflow), Name: w.Spec.WorkflowName},
{ObjType: new(Workflow), Name: w.Spec.WorkflowID},
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/openapi/generated/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ae1971

Please sign in to comment.