forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
24 lines (21 loc) · 903 Bytes
/
util.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
package project
import "fmt"
import "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
// GetRoleIndexByName looks up the index of a role in a project by the name
func GetRoleIndexByName(proj *v1alpha1.AppProject, name string) (int, error) {
for i, role := range proj.Spec.Roles {
if name == role.Name {
return i, nil
}
}
return -1, fmt.Errorf("role '%s' does not exist in project '%s'", name, proj.Name)
}
// GetJWTTokenIndexByIssuedAt looks up the index of a JWTToken in a project by the issue at time
func GetJWTTokenIndexByIssuedAt(proj *v1alpha1.AppProject, roleIndex int, issuedAt int64) (int, error) {
for i, token := range proj.Spec.Roles[roleIndex].JWTTokens {
if issuedAt == token.IssuedAt {
return i, nil
}
}
return -1, fmt.Errorf("JWT token for role '%s' issued at '%d' does not exist in project '%s'", proj.Spec.Roles[roleIndex].Name, issuedAt, proj.Name)
}