-
Notifications
You must be signed in to change notification settings - Fork 0
/
idsource_container.go
75 lines (57 loc) · 1.95 KB
/
idsource_container.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 cli
import (
"context"
"errors"
api "github.com/atricore/josso-api-go"
)
// Gets an IdP based on the appliance name and idp name
func (c *IdbusApiClient) GetIdSource(ida string, idsource string) (api.IdSourceContainerDTO, error) {
c.logger.Debugf("getIdSource. %s [%s]", idsource, ida)
var result api.IdSourceContainerDTO
sc, err := c.IdbusServerForOperation("DefaultApiService.GetIdSource") // 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.GetIdSource(ctx)
req = req.GetIdSourceReq(api.GetIdSourceReq{IdOrName: &ida, Name: &idsource})
res, _, err := c.apiClient.DefaultApi.GetIdSourceExecute(req)
if err != nil {
c.logger.Errorf("getIdSource. Error %v", err)
return result, err
}
if res.Error != nil {
c.logger.Errorf("getIdSource. Error %v", err)
return result, errors.New(*res.Error)
}
if res.IdSource == nil {
c.logger.Debugf("getIdSource. NOT FOUND %s", idsource)
return result, nil
}
result = res.GetIdSource()
return result, nil
}
func (c *IdbusApiClient) GetIdSources(ida string) ([]api.IdSourceContainerDTO, error) {
c.logger.Debugf("getIdSources: all [%s]", ida)
var result []api.IdSourceContainerDTO
sc, err := c.IdbusServerForOperation("DefaultApiService.GetIdSources") // 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.GetIdSources(ctx)
req = req.GetIdSourcesReq(api.GetIdSourcesReq{IdOrName: &ida})
res, _, err := c.apiClient.DefaultApi.GetIdSourcesExecute(req)
if err != nil {
c.logger.Errorf("getIdSources. Error %v", err)
return result, err
}
if res.Error != nil {
return result, errors.New(*res.Error)
}
if res.IdSources == nil {
return result, nil
}
result = res.IdSources
return result, nil
}