-
Notifications
You must be signed in to change notification settings - Fork 0
/
intsaml2sp.go
191 lines (148 loc) · 5.76 KB
/
intsaml2sp.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package cli
import (
"context"
"errors"
api "github.com/atricore/josso-api-go"
)
// Creates a new IntSaml2Sp in the provided identity appliance. It receives the appliance name or id and the SP dto to use as template
func (c *IdbusApiClient) CreateIntSaml2Sp(ida string, intsp api.InternalSaml2ServiceProviderDTO) (api.InternalSaml2ServiceProviderDTO, error) {
var result api.InternalSaml2ServiceProviderDTO
l := c.Logger()
l.Debugf("createIntSaml2Sp : %s [%s]", *intsp.Name, ida)
sc, err := c.IdbusServerForOperation("DefaultApiService.CreateIntSaml2Sp") // Also hard-coded in generated client
if err != nil {
return result, err
}
initIntSaml2Sp(&intsp)
ctx := context.WithValue(context.Background(), api.ContextAccessToken, sc.Authn.AccessToken)
req := c.apiClient.DefaultApi.CreateIntSaml2Sp(ctx)
req = req.StoreIntSaml2SpReq(api.StoreIntSaml2SpReq{IdOrName: &ida, Sp: &intsp})
res, _, err := c.apiClient.DefaultApi.CreateIntSaml2SpExecute(req)
if err != nil {
c.logger.Errorf("CreateIntSaml2Sp. Error %v", err)
return result, err
}
if res.Error != nil {
msg := buildErrorMsg(*res.Error, res.ValidationErrors)
c.logger.Errorf("CreateIntSaml2Sp. Error %s", msg)
return result, errors.New(msg)
}
if res.Sp == nil {
return result, errors.New("no IntSaml2Sp received after creation")
}
result = *res.Sp
return result, nil
}
func (c *IdbusApiClient) UpdateIntSaml2Sp(ida string, sp api.InternalSaml2ServiceProviderDTO) (api.InternalSaml2ServiceProviderDTO, error) {
var result api.InternalSaml2ServiceProviderDTO
l := c.Logger()
l.Debugf("UpdateIntSaml2Sp. : %s [%s]", *sp.Name, ida)
sc, err := c.IdbusServerForOperation("DefaultApiService.UpdateIntSaml2Sp") // Also hard-coded in generated client
if err != nil {
return result, err
}
initIntSaml2Sp(&sp)
ctx := context.WithValue(context.Background(), api.ContextAccessToken, sc.Authn.AccessToken)
req := c.apiClient.DefaultApi.UpdateIntSaml2Sp(ctx)
req = req.StoreIntSaml2SpReq(api.StoreIntSaml2SpReq{IdOrName: &ida, Sp: &sp})
res, _, err := c.apiClient.DefaultApi.UpdateIntSaml2SpExecute(req)
if err != nil {
c.logger.Errorf("UpdateIntSaml2Sp. Error %v", err)
return result, err
}
if res.Error != nil {
msg := buildErrorMsg(*res.Error, res.ValidationErrors)
c.logger.Errorf("UpdateIntSaml2Sp. Error %s", msg)
return result, errors.New(msg)
}
if res.Sp == nil {
return result, errors.New("no IntSaml2Sp received after update")
}
result = *res.Sp
return result, nil
}
func (c *IdbusApiClient) DeleteIntSaml2Sp(ida string, sp string) (bool, error) {
c.logger.Debugf("deleteIntSaml2Sp. %s [%s]", sp, ida)
sc, err := c.IdbusServerForOperation("DefaultApiService.deleteIntSaml2Sp") // Also hard-coded in generated client
if err != nil {
c.logger.Errorf("deleteIntSaml2Sp. Error %v", err)
return false, err
}
ctx := context.WithValue(context.Background(), api.ContextAccessToken, sc.Authn.AccessToken)
req := c.apiClient.DefaultApi.DeleteIntSaml2Sp(ctx)
req = req.DeleteReq(api.DeleteReq{IdOrName: &ida, Name: &sp})
res, _, err := c.apiClient.DefaultApi.DeleteIntSaml2SpExecute(req)
if err != nil {
c.logger.Errorf("deleteIntSaml2Ss. Error %v", err)
return false, err
}
if res.Error != nil {
c.logger.Errorf("deleteIntSaml2Ss. Error %v", *res.Error)
return false, errors.New(*res.Error)
}
c.logger.Debugf("deleteIntSaml2Ss. Deleted %s : %t", sp, *res.Removed)
return *res.Removed, err
}
// Gets an Sp based on the appliance name and sp name
func (c *IdbusApiClient) GetIntSaml2Sp(ida string, sp string) (api.InternalSaml2ServiceProviderDTO, error) {
c.logger.Debugf("GetIntSaml2Sp. %s [%s]", sp, ida)
var result api.InternalSaml2ServiceProviderDTO
sc, err := c.IdbusServerForOperation("DefaultApiService.GetIntSaml2Sp") // Also hard-coded in generated client
if err != nil {
return result, err
}
ctx := context.WithValue(context.Background(), api.ContextAccessToken, sc.Authn.AccessToken)
req := c.apiClient.DefaultApi.GetIntSaml2Sp(ctx)
req = req.GetIntSaml2SpReq(api.GetIntSaml2SpReq{IdOrName: &ida, Name: &sp})
res, _, err := c.apiClient.DefaultApi.GetIntSaml2SpExecute(req)
if err != nil {
c.logger.Errorf("GetIntSaml2Sp. Error %v", err)
return result, err
}
if res.Error != nil {
c.logger.Errorf("GetIntSaml2Sp. Error %v", err)
return result, errors.New(*res.Error)
}
if res.Sp == nil {
c.logger.Debugf("GetIntSaml2Sp. NOT FOUND %s", sp)
return result, nil
}
if res.Sp != nil {
result = *res.Sp
if res.Sp.Name == nil {
return result, errors.New("no name received for IntSaml2Sp (unmarshalling error?)")
}
c.logger.Debugf("GetIntSaml2Sp. %s found for ID/name %s", *result.Name, sp)
} else {
c.logger.Debugf("GetIntSaml2Sp. not found for ID/name %s", sp)
}
return result, nil
}
func (c *IdbusApiClient) GetIntSaml2Sps(ida string) ([]api.InternalSaml2ServiceProviderDTO, error) {
c.logger.Debugf("get IntSaml2Sps: all [%s]", ida)
var result []api.InternalSaml2ServiceProviderDTO
sc, err := c.IdbusServerForOperation("DefaultApiService.GetIntSaml2Sps") // Also hard-coded in generated client
if err != nil {
return result, err
}
ctx := context.WithValue(context.Background(), api.ContextAccessToken, sc.Authn.AccessToken)
req := c.apiClient.DefaultApi.GetIntSaml2Sps(ctx)
req = req.GetIntSaml2SpReq(api.GetIntSaml2SpReq{IdOrName: &ida})
res, _, err := c.apiClient.DefaultApi.GetIntSaml2SpsExecute(req)
if err != nil {
c.logger.Errorf("getIntSaml2Sps. Error %v", err)
return result, err
}
if res.Error != nil {
return result, errors.New(*res.Error)
}
if res.Sps == nil {
return result, nil
}
result = res.Sps
return result, nil
}
func initIntSaml2Sp(IntSaml2Sp *api.InternalSaml2ServiceProviderDTO) {
IntSaml2Sp.AdditionalProperties = make(map[string]interface{})
IntSaml2Sp.AdditionalProperties["@c"] = ".InternalSaml2ServiceProviderDTO"
}