GetProjectIDPlanIDStageIDTaskID returns the project ID, plan ID, stage ID, and task ID from a resource name.
(name string)
| 372 | |
| 373 | // GetProjectIDPlanIDStageIDTaskID returns the project ID, plan ID, stage ID, and task ID from a resource name. |
| 374 | func GetProjectIDPlanIDStageIDTaskID(name string) (string, int64, string, int64, error) { |
| 375 | parts := strings.Split(name, "/rollout") |
| 376 | if len(parts) != 2 { |
| 377 | return "", 0, "", 0, errors.Errorf("invalid rollout task name %q", name) |
| 378 | } |
| 379 | |
| 380 | projectID, planID, err := GetProjectIDPlanID(parts[0]) |
| 381 | if err != nil { |
| 382 | return "", 0, "", 0, err |
| 383 | } |
| 384 | |
| 385 | // suffix should be /stages/{stage}/tasks/{task} |
| 386 | suffixParts := strings.Split(strings.TrimPrefix(parts[1], "/"), "/") |
| 387 | if len(suffixParts) != 4 || suffixParts[0]+"/" != StagePrefix || suffixParts[2]+"/" != TaskPrefix { |
| 388 | return "", 0, "", 0, errors.Errorf("invalid task suffix %q", parts[1]) |
| 389 | } |
| 390 | |
| 391 | stageID := suffixParts[1] |
| 392 | taskID, err := strconv.ParseInt(suffixParts[3], 10, 64) |
| 393 | if err != nil { |
| 394 | return "", 0, "", 0, errors.Errorf("invalid task ID %q", suffixParts[3]) |
| 395 | } |
| 396 | return projectID, planID, stageID, taskID, nil |
| 397 | } |
| 398 | |
| 399 | // GetProjectIDPlanIDStageIDTaskIDTaskRunID returns the project ID, plan ID, stage ID, task ID and task run ID from a resource name. |
| 400 | func GetProjectIDPlanIDStageIDTaskIDTaskRunID(name string) (string, int64, string, int64, int64, error) { |
no test coverage detected