github.com/gophercloud/gophercloud@v1.11.0/openstack/workflow/v2/workflows/results.go (about) 1 package workflows 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/gophercloud/gophercloud" 8 "github.com/gophercloud/gophercloud/pagination" 9 ) 10 11 // CreateResult is the response of a Post operations. Call its Extract method to interpret it as a list of Workflows. 12 type CreateResult struct { 13 gophercloud.Result 14 } 15 16 // DeleteResult is the result from a Delete operation. Call its ExtractErr method to determine the success of the call. 17 type DeleteResult struct { 18 gophercloud.ErrResult 19 } 20 21 // Extract helps to get created Workflow struct from a Create function. 22 func (r CreateResult) Extract() ([]Workflow, error) { 23 var s struct { 24 Workflows []Workflow `json:"workflows"` 25 } 26 err := r.ExtractInto(&s) 27 return s.Workflows, err 28 } 29 30 // GetResult is the response of Get operations. Call its Extract method to interpret it as a Workflow. 31 type GetResult struct { 32 gophercloud.Result 33 } 34 35 // Extract helps to get a Workflow struct from a Get function. 36 func (r GetResult) Extract() (*Workflow, error) { 37 var s Workflow 38 err := r.ExtractInto(&s) 39 return &s, err 40 } 41 42 // Workflow represents a workflow execution on OpenStack mistral API. 43 type Workflow struct { 44 // ID is the workflow's unique ID. 45 ID string `json:"id"` 46 47 // Definition is the workflow definition in Mistral v2 DSL. 48 Definition string `json:"definition"` 49 50 // Name is the name of the workflow. 51 Name string `json:"name"` 52 53 // Namespace is the namespace of the workflow. 54 Namespace string `json:"namespace"` 55 56 // Input represents the needed input to execute the workflow. 57 // This parameter is a list of each input, comma separated. 58 Input string `json:"input"` 59 60 // ProjectID is the project id owner of the workflow. 61 ProjectID string `json:"project_id"` 62 63 // Scope is the scope of the workflow. 64 // Values can be "private" or "public". 65 Scope string `json:"scope"` 66 67 // Tags is a list of tags associated to the workflow. 68 Tags []string `json:"tags"` 69 70 // CreatedAt is the creation date of the workflow. 71 CreatedAt time.Time `json:"-"` 72 73 // UpdatedAt is the last update date of the workflow. 74 UpdatedAt *time.Time `json:"-"` 75 } 76 77 // UnmarshalJSON implements unmarshalling custom types 78 func (r *Workflow) UnmarshalJSON(b []byte) error { 79 type tmp Workflow 80 var s struct { 81 tmp 82 CreatedAt gophercloud.JSONRFC3339ZNoTNoZ `json:"created_at"` 83 UpdatedAt *gophercloud.JSONRFC3339ZNoTNoZ `json:"updated_at"` 84 } 85 86 err := json.Unmarshal(b, &s) 87 if err != nil { 88 return err 89 } 90 91 *r = Workflow(s.tmp) 92 93 r.CreatedAt = time.Time(s.CreatedAt) 94 if s.UpdatedAt != nil { 95 t := time.Time(*s.UpdatedAt) 96 r.UpdatedAt = &t 97 } 98 99 return nil 100 } 101 102 // WorkflowPage contains a single page of all workflows from a List call. 103 type WorkflowPage struct { 104 pagination.LinkedPageBase 105 } 106 107 // IsEmpty checks if an WorkflowPage contains any results. 108 func (r WorkflowPage) IsEmpty() (bool, error) { 109 if r.StatusCode == 204 { 110 return true, nil 111 } 112 113 exec, err := ExtractWorkflows(r) 114 return len(exec) == 0, err 115 } 116 117 // NextPageURL finds the next page URL in a page in order to navigate to the next page of results. 118 func (r WorkflowPage) NextPageURL() (string, error) { 119 var s struct { 120 Next string `json:"next"` 121 } 122 err := r.ExtractInto(&s) 123 if err != nil { 124 return "", err 125 } 126 return s.Next, nil 127 } 128 129 // ExtractWorkflows get the list of cron triggers from a page acquired from the List call. 130 func ExtractWorkflows(r pagination.Page) ([]Workflow, error) { 131 var s struct { 132 Workflows []Workflow `json:"workflows"` 133 } 134 err := (r.(WorkflowPage)).ExtractInto(&s) 135 return s.Workflows, err 136 }