-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplan.go
More file actions
32 lines (26 loc) · 807 Bytes
/
plan.go
File metadata and controls
32 lines (26 loc) · 807 Bytes
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
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0
package api
import (
"fmt"
cserrors "github.com/codesphere-cloud/cs-go/api/errors"
)
// Fetches the workspace plan for a given name.
//
// Returns [NotFound] if no plan with the given Id could be found
func (client *Client) PlanByName(name string) (WorkspacePlan, error) {
plans, err := client.ListWorkspacePlans()
if err != nil {
return WorkspacePlan{}, err
}
for _, p := range plans {
if p.Title == name {
return p, nil
}
}
return WorkspacePlan{}, cserrors.NotFound(fmt.Sprintf("no team with name %s found", name))
}
func (c *Client) ListWorkspacePlans() ([]WorkspacePlan, error) {
plans, r, err := c.api.MetadataAPI.MetadataGetWorkspacePlans(c.ctx).Execute()
return plans, cserrors.FormatAPIError(r, err)
}