-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_container.go
75 lines (57 loc) · 1.95 KB
/
provider_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) GetProvider(ida string, provider string) (api.ProviderContainerDTO, error) {
c.logger.Debugf("getProvider. %s [%s]", provider, ida)
var result api.ProviderContainerDTO
sc, err := c.IdbusServerForOperation("DefaultApiService.GetProvider") // 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.GetProvider(ctx)
req = req.GetProviderReq(api.GetProviderReq{IdOrName: &ida, Name: &provider})
res, _, err := c.apiClient.DefaultApi.GetProviderExecute(req)
if err != nil {
c.logger.Errorf("getProvider. Error %v", err)
return result, err
}
if res.Error != nil {
c.logger.Errorf("getProvider. Error %v", err)
return result, errors.New(*res.Error)
}
if res.Provider == nil {
c.logger.Debugf("getProvider. NOT FOUND %s", provider)
return result, nil
}
result = res.GetProvider()
return result, nil
}
func (c *IdbusApiClient) GetProviders(ida string) ([]api.ProviderContainerDTO, error) {
c.logger.Debugf("getProviders: all [%s]", ida)
var result []api.ProviderContainerDTO
sc, err := c.IdbusServerForOperation("DefaultApiService.GetProviders") // 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.GetProviders(ctx)
req = req.GetApplianceReq(api.GetApplianceReq{IdOrName: &ida})
res, _, err := c.apiClient.DefaultApi.GetProvidersExecute(req)
if err != nil {
c.logger.Errorf("getProviders. Error %v", err)
return result, err
}
if res.Error != nil {
return result, errors.New(*res.Error)
}
if res.Providers == nil {
return result, nil
}
result = res.Providers
return result, nil
}