-
Notifications
You must be signed in to change notification settings - Fork 11
/
url.go
65 lines (54 loc) · 2.13 KB
/
url.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
package cedarcore
import (
"context"
"fmt"
"github.com/guregu/null/zero"
"github.com/cmsgov/easi-app/pkg/appcontext"
apiurl "github.com/cmsgov/easi-app/pkg/cedar/core/gen/client/url"
"github.com/cmsgov/easi-app/pkg/local/cedarcoremock"
"github.com/cmsgov/easi-app/pkg/models"
)
// GetURLsForSystem queries CEDAR for URLs associated with a particular system, taking the version-independent ID of a system
//
// Note: CEDAR's /url/{id} endpoint theoretically supports querying for URLs associated with any sort of CEDAR object;
// however, this method assumes that the parameter is a version-independent system ID.
// If we need to look up URLs based on something other than systems, we will need to create another method.
func (c *Client) GetURLsForSystem(ctx context.Context, cedarSystemID string) ([]*models.CedarURL, error) {
if c.mockEnabled {
appcontext.ZLogger(ctx).Info("CEDAR Core is disabled")
if cedarcoremock.IsMockSystem(cedarSystemID) {
return cedarcoremock.GetURLs(), nil
}
return nil, cedarcoremock.NoSystemFoundError()
}
cedarSystem, err := c.GetSystem(ctx, cedarSystemID)
if err != nil {
return nil, err
}
// Construct the parameters
params := apiurl.NewURLFindListParams()
params.SetID(cedarSystem.VersionID.String)
params.HTTPClient = c.hc
// Make the API call
resp, err := c.sdk.URL.URLFindList(params, c.auth)
if err != nil {
return []*models.CedarURL{}, err
}
if resp.Payload == nil {
return []*models.CedarURL{}, fmt.Errorf("no body received")
}
// Convert the auto-generated struct to our own pkg/models struct
retVal := []*models.CedarURL{}
// convert items in response payload to our models
for _, url := range resp.Payload.URLList {
retVal = append(retVal, &models.CedarURL{
ID: zero.StringFromPtr(url.URLID),
Address: zero.StringFrom(url.Address),
IsBehindWebApplicationFirewall: url.IsBehindWebApplicationFirewall,
IsAPIEndpoint: url.IsAPIEndpoint,
IsVersionCodeRepository: url.IsVersionCodeRepository,
URLHostingEnv: zero.StringFrom(url.URLHostingEnv),
})
}
return retVal, nil
}