GetProjectIDPlanIDMaybeStageID returns the project ID, plan ID, and maybe stage ID from a resource name.
(name string)
| 284 | |
| 285 | // GetProjectIDPlanIDMaybeStageID returns the project ID, plan ID, and maybe stage ID from a resource name. |
| 286 | func GetProjectIDPlanIDMaybeStageID(name string) (string, int64, *string, error) { |
| 287 | parts := strings.Split(name, "/rollout") |
| 288 | if len(parts) != 2 { |
| 289 | return "", 0, nil, errors.Errorf("invalid rollout stage name %q", name) |
| 290 | } |
| 291 | |
| 292 | projectID, planID, err := GetProjectIDPlanID(parts[0]) |
| 293 | if err != nil { |
| 294 | return "", 0, nil, err |
| 295 | } |
| 296 | |
| 297 | // suffix should be /stages/{stage} |
| 298 | suffixParts := strings.Split(strings.TrimPrefix(parts[1], "/"), "/") |
| 299 | if len(suffixParts) != 2 || suffixParts[0]+"/" != StagePrefix { |
| 300 | return "", 0, nil, errors.Errorf("invalid stage suffix %q", parts[1]) |
| 301 | } |
| 302 | |
| 303 | var maybeStageID *string |
| 304 | if suffixParts[1] != "-" { |
| 305 | maybeStageID = &suffixParts[1] |
| 306 | } |
| 307 | return projectID, planID, maybeStageID, nil |
| 308 | } |
| 309 | |
| 310 | // GetProjectIDPlanIDStageIDMaybeTaskID returns the project ID, plan ID, and maybe stage ID and maybe task ID from a resource name. |
| 311 | func GetProjectIDPlanIDStageIDMaybeTaskID(name string) (string, int64, string, *int64, error) { |
no test coverage detected