-
Notifications
You must be signed in to change notification settings - Fork 82
/
data_test.go
71 lines (57 loc) · 1.89 KB
/
data_test.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
package phases
import (
"fmt"
"github.com/microsoftgraph/msgraph-beta-sdk-go/models/microsoft/graph"
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/Azure/azure-workload-identity/pkg/cloud"
"github.com/Azure/azure-workload-identity/pkg/cmd/serviceaccount/util"
)
type mockDeleteData struct {
serviceAccountName string
serviceAccountNamespace string
serviceAccountIssuerURL string
aadApplication *graph.Application // cache
aadApplicationName string
aadApplicationObjectID string
roleAssignmentID string
azureClient cloud.Interface
kubeClient client.Client
}
var _ DeleteData = &mockDeleteData{}
func (d *mockDeleteData) ServiceAccountName() string {
return d.serviceAccountName
}
func (d *mockDeleteData) ServiceAccountNamespace() string {
return d.serviceAccountNamespace
}
func (d *mockDeleteData) ServiceAccountIssuerURL() string {
return d.serviceAccountIssuerURL
}
func (d *mockDeleteData) AADApplication() (*graph.Application, error) {
if d.aadApplication == nil {
return nil, errors.New("not found")
}
return d.aadApplication, nil
}
func (d *mockDeleteData) AADApplicationName() string {
if d.aadApplicationName == "" && d.ServiceAccountNamespace() != "" && d.ServiceAccountName() != "" && d.ServiceAccountIssuerURL() != "" {
return fmt.Sprintf("%s-%s-%s", d.ServiceAccountNamespace(), d.serviceAccountName, util.GetIssuerHash(d.ServiceAccountIssuerURL()))
}
return d.aadApplicationName
}
func (d *mockDeleteData) AADApplicationObjectID() string {
return d.aadApplicationObjectID
}
func (d *mockDeleteData) RoleAssignmentID() string {
return d.roleAssignmentID
}
func (d *mockDeleteData) AzureClient() cloud.Interface {
return d.azureClient
}
func (d *mockDeleteData) KubeClient() (client.Client, error) {
if d.kubeClient == nil {
return nil, errors.New("not found")
}
return d.kubeClient, nil
}