forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.go
75 lines (62 loc) · 2.3 KB
/
index.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package utils
import (
"fmt"
"github.com/rancher/rancher/pkg/ref"
"github.com/rancher/types/apis/project.cattle.io/v3"
)
const (
PipelineByProjectIndex = "pipeline.project.cattle.io/pipeline-by-project"
PipelineExecutionByClusterIndex = "pipeline.project.cattle.io/execution-by-cluster"
PipelineExecutionByProjectIndex = "pipeline.project.cattle.io/execution-by-project"
SourceCodeCredentialByProjectAndTypeIndex = "pipeline.project.cattle.io/credential-by-project-and-type"
SourceCodeRepositoryByCredentialIndex = "pipeline.project.cattle.io/repository-by-credential"
SourceCodeRepositoryByProjectAndTypeIndex = "pipeline.project.cattle.io/repository-by-project-and-type"
)
func PipelineByProjectName(obj interface{}) ([]string, error) {
pipeline, ok := obj.(*v3.Pipeline)
if !ok {
return []string{}, nil
}
return []string{pipeline.Spec.ProjectName}, nil
}
func PipelineExecutionByProjectName(obj interface{}) ([]string, error) {
execution, ok := obj.(*v3.PipelineExecution)
if !ok {
return []string{}, nil
}
return []string{execution.Spec.ProjectName}, nil
}
func PipelineExecutionByClusterName(obj interface{}) ([]string, error) {
execution, ok := obj.(*v3.PipelineExecution)
if !ok {
return []string{}, nil
}
cluster, _ := ref.Parse(execution.Spec.ProjectName)
return []string{cluster}, nil
}
func SourceCodeCredentialByProjectNameAndType(obj interface{}) ([]string, error) {
credential, ok := obj.(*v3.SourceCodeCredential)
if !ok {
return []string{}, nil
}
key := ProjectNameAndSourceCodeTypeKey(credential.Spec.ProjectName, credential.Spec.SourceCodeType)
return []string{key}, nil
}
func SourceCodeRepositoryByProjectNameAndType(obj interface{}) ([]string, error) {
repository, ok := obj.(*v3.SourceCodeRepository)
if !ok {
return []string{}, nil
}
key := ProjectNameAndSourceCodeTypeKey(repository.Spec.ProjectName, repository.Spec.SourceCodeType)
return []string{key}, nil
}
func SourceCodeRepositoryByCredentialName(obj interface{}) ([]string, error) {
repository, ok := obj.(*v3.SourceCodeRepository)
if !ok {
return []string{}, nil
}
return []string{repository.Spec.SourceCodeCredentialName}, nil
}
func ProjectNameAndSourceCodeTypeKey(projectName, souceCodeType string) string {
return fmt.Sprintf("%s.%s", projectName, souceCodeType)
}