1
+ /*
2
+ Copyright NetFoundry Inc.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ package mgmt
17
+
18
+ import (
19
+ "context"
20
+ "github.com/openziti/edge-api/rest_management_api_client"
21
+ "github.com/openziti/edge-api/rest_management_api_client/identity"
22
+ "github.com/openziti/edge-api/rest_management_api_client/service"
23
+ "github.com/openziti/edge-api/rest_management_api_client/service_policy"
24
+ "github.com/openziti/edge-api/rest_model"
25
+ log "github.com/sirupsen/logrus"
26
+ "time"
27
+ )
28
+
29
+ func IdentityFromFilter (client * rest_management_api_client.ZitiEdgeManagement , filter string ) * rest_model.IdentityDetail {
30
+ params := & identity.ListIdentitiesParams {
31
+ Filter : & filter ,
32
+ Context : context .Background (),
33
+ }
34
+ params .SetTimeout (5 * time .Second )
35
+ resp , err := client .Identity .ListIdentities (params , nil )
36
+ if err != nil {
37
+ log .Debugf ("Could not obtain an ID for the identity with filter %s: %v" , filter , err )
38
+ return nil
39
+ }
40
+
41
+ if resp == nil || resp .Payload == nil || resp .Payload .Data == nil || len (resp .Payload .Data ) == 0 {
42
+ return nil
43
+ }
44
+ return resp .Payload .Data [0 ]
45
+ }
46
+
47
+ func ServiceFromFilter (client * rest_management_api_client.ZitiEdgeManagement , filter string ) * rest_model.ServiceDetail {
48
+ params := & service.ListServicesParams {
49
+ Filter : & filter ,
50
+ Context : context .Background (),
51
+ }
52
+ params .SetTimeout (5 * time .Second )
53
+ resp , err := client .Service .ListServices (params , nil )
54
+ if err != nil {
55
+ log .Debugf ("Could not obtain an ID for the service with filter %s: %v" , filter , err )
56
+ return nil
57
+ }
58
+ if resp == nil || resp .Payload == nil || resp .Payload .Data == nil || len (resp .Payload .Data ) == 0 {
59
+ return nil
60
+ }
61
+ return resp .Payload .Data [0 ]
62
+ }
63
+
64
+ func ServicePolicyFromFilter (client * rest_management_api_client.ZitiEdgeManagement , filter string ) * rest_model.ServicePolicyDetail {
65
+ params := & service_policy.ListServicePoliciesParams {
66
+ Filter : & filter ,
67
+ Context : context .Background (),
68
+ }
69
+ params .SetTimeout (5 * time .Second )
70
+ resp , err := client .ServicePolicy .ListServicePolicies (params , nil )
71
+ if err != nil {
72
+ log .Errorf ("Could not obtain an ID for the service with filter %s: %v" , filter , err )
73
+ return nil
74
+ }
75
+ if resp == nil || resp .Payload == nil || resp .Payload .Data == nil || len (resp .Payload .Data ) == 0 {
76
+ return nil
77
+ }
78
+ return resp .Payload .Data [0 ]
79
+ }
80
+
81
+ func NameFilter (name string ) string {
82
+ return `name="` + name + `"`
83
+ }
0 commit comments