/
claim.go
36 lines (27 loc) · 890 Bytes
/
claim.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
package rest
import (
"fmt"
"github.com/Aptomi/aptomi/pkg/api"
"github.com/Aptomi/aptomi/pkg/client/rest/http"
"strings"
"github.com/Aptomi/aptomi/pkg/config"
"github.com/Aptomi/aptomi/pkg/lang"
)
type claimClient struct {
cfg *config.Client
httpClient http.Client
}
func (client *claimClient) Status(claims []*lang.Claim, queryFlag api.ClaimQueryFlag) (*api.ClaimsStatus, error) {
claimIds := []string{}
for _, claim := range claims {
claimIds = append(claimIds, claim.GetNamespace()+"^"+claim.GetName())
}
response, err := client.httpClient.GET(fmt.Sprintf("/policy/claim/status/%s/%s", queryFlag, strings.Join(claimIds, ",")), api.ClaimsStatusObject)
if err != nil {
return nil, err
}
if serverError, ok := response.(*api.ServerError); ok {
return nil, fmt.Errorf("server error: %s", serverError.Error)
}
return response.(*api.ClaimsStatus), nil
}