/
resources.go
70 lines (58 loc) · 2.08 KB
/
resources.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
package clients
import (
"context"
"github.com/manifoldco/go-manifold"
mClient "github.com/manifoldco/manifold-cli/generated/marketplace/client"
"github.com/manifoldco/manifold-cli/generated/marketplace/client/resource"
mModels "github.com/manifoldco/manifold-cli/generated/marketplace/models"
pClient "github.com/manifoldco/manifold-cli/generated/provisioning/client"
"github.com/manifoldco/manifold-cli/generated/provisioning/client/operation"
pModels "github.com/manifoldco/manifold-cli/generated/provisioning/models"
)
// FetchOperations returns the resources for the authenticated user
func FetchOperations(ctx context.Context, c *pClient.Provisioning, teamID *manifold.ID) ([]*pModels.Operation, error) {
res, err := c.Operation.GetOperations(
operation.NewGetOperationsParamsWithContext(ctx), nil)
if err != nil {
return nil, err
}
var results []*pModels.Operation
for _, o := range res.Payload {
if (teamID == nil && o.Body.TeamID() == nil) ||
(teamID != nil && o.Body.TeamID() != nil && teamID.String() == o.Body.TeamID().String()) {
results = append(results, o)
}
}
return results, nil
}
// FetchResources returns the resources for the authenticated user
func FetchResources(ctx context.Context, c *mClient.Marketplace, teamID *manifold.ID, projectLabel string) ([]*mModels.Resource, error) {
var project *mModels.Project
if projectLabel != "" {
var err error
project, err = FetchProjectByLabel(ctx, c, teamID, projectLabel)
if err != nil {
return nil, err
}
}
res, err := c.Resource.GetResources(
resource.NewGetResourcesParamsWithContext(ctx), nil)
if err != nil {
return nil, err
}
var results []*mModels.Resource
for _, r := range res.Payload {
if (teamID == nil && r.Body.TeamID == nil) ||
(teamID != nil && r.Body.TeamID != nil && teamID.String() == r.Body.TeamID.String()) {
results = append(results, r)
}
}
var matches []*mModels.Resource
for _, r := range results {
id := r.Body.ProjectID
if project == nil || (id != nil && project != nil && *id == project.ID) {
matches = append(matches, r)
}
}
return matches, nil
}