Skip to content

Commit

Permalink
Merge pull request #31 from manifoldco/no-teams-yet
Browse files Browse the repository at this point in the history
Hide team-owned resources from the CLI until proper support is added
  • Loading branch information
jeffandersen authored Aug 11, 2017
2 parents 2fa3ecb + a2fdf67 commit 4f43a7b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 43 deletions.
50 changes: 50 additions & 0 deletions clients/resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package clients

import (
"context"

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) ([]*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 {
// TODO: remove this once CLI has first-class Teams support
if !o.Body.TeamID().IsEmpty() {
continue
}
results = append(results, o)
}
return results, nil
}

// FetchResources returns the resources for the authenticated user
func FetchResources(ctx context.Context, c *mClient.Marketplace) ([]*mModels.Resource, error) {
res, err := c.Resource.GetResources(
resource.NewGetResourcesParamsWithContext(ctx), nil)
if err != nil {
return nil, err
}

var results []*mModels.Resource
for _, r := range res.Payload {
// TODO: remove this once CLI has first-class Teams support
if !r.Body.TeamID.IsEmpty() {
continue
}
results = append(results, r)
}
return results, nil
}
6 changes: 2 additions & 4 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/manifoldco/manifold-cli/session"

cModels "github.com/manifoldco/manifold-cli/generated/catalog/models"
"github.com/manifoldco/manifold-cli/generated/marketplace/client/resource"
mModels "github.com/manifoldco/manifold-cli/generated/marketplace/models"
provisioning "github.com/manifoldco/manifold-cli/generated/provisioning/client"
"github.com/manifoldco/manifold-cli/generated/provisioning/client/operation"
Expand Down Expand Up @@ -143,13 +142,12 @@ func create(cliCtx *cli.Context) error {
}

// Get resources, so we can fetch the list of valid appnames
res, err := mClient.Resource.GetResources(
resource.NewGetResourcesParamsWithContext(ctx), nil)
res, err := clients.FetchResources(ctx, mClient)
if err != nil {
return cli.NewExitError("Failed to fetch resource list: "+err.Error(), -1)
}

appNames := fetchUniqueAppNames(res.Payload)
appNames := fetchUniqueAppNames(res)
newA, appName, err := prompts.SelectCreateAppName(appNames, appName, false)
if err != nil {
return prompts.HandleSelectError(err, "Could not select app.")
Expand Down
6 changes: 2 additions & 4 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

mClient "github.com/manifoldco/manifold-cli/generated/marketplace/client"
"github.com/manifoldco/manifold-cli/generated/marketplace/client/credential"
"github.com/manifoldco/manifold-cli/generated/marketplace/client/resource"
"github.com/manifoldco/manifold-cli/generated/marketplace/models"
)

Expand Down Expand Up @@ -80,13 +79,12 @@ func export(cliCtx *cli.Context) error {
return cli.NewExitError("Could not create marketplace client: "+err.Error(), -1)
}

p := resource.NewGetResourcesParamsWithContext(ctx)
r, err := marketplace.Resource.GetResources(p, nil)
r, err := clients.FetchResources(ctx, marketplace)
if err != nil {
return cli.NewExitError("Could not retrieve resources: "+err.Error(), -1)
}

resources := filterResourcesByAppName(r.Payload, appName)
resources := filterResourcesByAppName(r, appName)
sort.Sort(resourcesSortByName(resources))
cMap, err := fetchCredentials(ctx, marketplace, resources)
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"github.com/manifoldco/manifold-cli/errs"
"github.com/manifoldco/manifold-cli/prompts"
"github.com/manifoldco/manifold-cli/session"

"github.com/manifoldco/manifold-cli/generated/marketplace/client/resource"
)

func init() {
Expand Down Expand Up @@ -68,13 +66,12 @@ func initDir(cliCtx *cli.Context) error {
err.Error(), -1)
}

res, err := mClient.Resource.GetResources(
resource.NewGetResourcesParamsWithContext(ctx), nil)
res, err := clients.FetchResources(ctx, mClient)
if err != nil {
return cli.NewExitError("Failed to fetch resource list: "+err.Error(), -1)
}

appNames := fetchUniqueAppNames(res.Payload)
appNames := fetchUniqueAppNames(res)
newA, appName, err := prompts.SelectCreateAppName(appNames, appName, true)
if err != nil {
return prompts.HandleSelectError(err, "Could not select app.")
Expand Down
10 changes: 3 additions & 7 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import (
"github.com/manifoldco/manifold-cli/errs"
"github.com/manifoldco/manifold-cli/session"

"github.com/manifoldco/manifold-cli/generated/marketplace/client/resource"
"github.com/manifoldco/manifold-cli/generated/marketplace/models"
"github.com/manifoldco/manifold-cli/generated/provisioning/client/operation"
pModels "github.com/manifoldco/manifold-cli/generated/provisioning/models"
)

Expand Down Expand Up @@ -99,21 +97,19 @@ func list(cliCtx *cli.Context) error {
}

// Get resources
res, err := marketplaceClient.Resource.GetResources(
resource.NewGetResourcesParamsWithContext(ctx), nil)
res, err := clients.FetchResources(ctx, marketplaceClient)
if err != nil {
return cli.NewExitError("Failed to fetch the list of provisioned "+
"resources: "+err.Error(), -1)
}

// Get operations
oRes, err := pClient.Operation.GetOperations(
operation.NewGetOperationsParamsWithContext(ctx), nil)
oRes, err := clients.FetchOperations(ctx, pClient)
if err != nil {
return cli.NewExitError("Failed to fetch the list of operations: "+err.Error(), -1)
}

resources, statuses := buildResourceList(res.Payload, oRes.Payload)
resources, statuses := buildResourceList(res, oRes)

// Sort resources by name and filter by given app name
resources = filterResourcesByAppName(resources, appName)
Expand Down
7 changes: 2 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/manifoldco/manifold-cli/config"
"github.com/manifoldco/manifold-cli/errs"
"github.com/manifoldco/manifold-cli/session"

"github.com/manifoldco/manifold-cli/generated/marketplace/client/resource"
)

func init() {
Expand Down Expand Up @@ -71,13 +69,12 @@ func run(cliCtx *cli.Context) error {
return cli.NewExitError("Could not create marketplace client: "+err.Error(), -1)
}

p := resource.NewGetResourcesParamsWithContext(ctx)
r, err := marketplace.Resource.GetResources(p, nil)
r, err := clients.FetchResources(ctx, marketplace)
if err != nil {
return cli.NewExitError("Could not retrieve resources: "+err.Error(), -1)
}

resources := filterResourcesByAppName(r.Payload, appName)
resources := filterResourcesByAppName(r, appName)
cMap, err := fetchCredentials(ctx, marketplace, resources)
if err != nil {
return cli.NewExitError("Could not retrieve credentials: "+err.Error(), -1)
Expand Down
13 changes: 6 additions & 7 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,30 +91,29 @@ func updateResourceCmd(cliCtx *cli.Context) error {
return cli.NewExitError(fmt.Sprintf("Failed to create Provisioning Client: %s", err), -1)
}

res, err := marketplaceClient.Resource.GetResources(
resClient.NewGetResourcesParamsWithContext(ctx), nil)
res, err := clients.FetchResources(ctx, marketplaceClient)
if err != nil {
return cli.NewExitError(
fmt.Sprintf("Failed to fetch the list of provisioned resources: %s", err), -1)
}

if len(res.Payload) == 0 {
if len(res) == 0 {
return cli.NewExitError("No resources found for updating", -1)
}

var resource *mModels.Resource
if resourceLabel != "" {
var err error
resource, err = pickResourcesByLabel(res.Payload, resourceLabel)
resource, err = pickResourcesByLabel(res, resourceLabel)
if err != nil {
return cli.NewExitError(fmt.Sprintf("Failed to fetch resource: %s", err), -1)
}
} else {
resourceIdx, _, err := prompts.SelectResource(res.Payload, resourceLabel)
resourceIdx, _, err := prompts.SelectResource(res, resourceLabel)
if err != nil {
return prompts.HandleSelectError(err, "Could not select Resource")
}
resource = res.Payload[resourceIdx]
resource = res[resourceIdx]
}

newResourceName := cliCtx.String("name")
Expand Down Expand Up @@ -166,7 +165,7 @@ func updateResourceCmd(cliCtx *cli.Context) error {
appName = string(resource.Body.AppName)
}

apps := fetchUniqueAppNames(res.Payload)
apps := fetchUniqueAppNames(res)
// TODO: This auto-selects the app and doesn't let the user change it without the -a flag
_, appName, err = prompts.SelectCreateAppName(apps, appName, true)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions specs/billing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ definitions:
type: string
additionalProperties: false
required:
- user_id
- provider_id
- account_id
additionalProperties: false
required:
Expand Down Expand Up @@ -464,6 +464,8 @@ definitions:
body:
type: object
properties:
team_id:
$ref: '#/definitions/ID'
user_id:
$ref: '#/definitions/ID'
sources:
Expand All @@ -482,6 +484,8 @@ definitions:
ProfileCreateRequest:
type: object
properties:
team_id:
$ref: '#/definitions/ID'
user_id:
$ref: '#/definitions/ID'
token:
Expand All @@ -491,7 +495,6 @@ definitions:
description: |
Tokenized source of funds
required:
- user_id
- token
additionalProperties: false
ProfileUpdateRequest:
Expand Down Expand Up @@ -599,6 +602,8 @@ definitions:
occurred_at:
type: string
format: date-time
team_id:
$ref: '#/definitions/ID'
user_id:
$ref: '#/definitions/ID'
provider_id:
Expand All @@ -611,7 +616,6 @@ definitions:
required:
- event_type
- event_number
- user_id
- operation_id
- occurred_at
credit:
Expand Down
11 changes: 4 additions & 7 deletions specs/marketplace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ definitions:
$ref: '#/definitions/Label'
app_name:
$ref: '#/definitions/Name'
team_id:
$ref: '#/definitions/ID'
user_id:
$ref: '#/definitions/ID'
product_id:
Expand Down Expand Up @@ -292,6 +294,8 @@ definitions:
$ref: '#/definitions/Label'
app_name:
$ref: '#/definitions/Name'
team_id:
$ref: '#/definitions/ID'
user_id:
$ref: '#/definitions/ID'
product_id:
Expand All @@ -310,7 +314,6 @@ definitions:
required:
- name
- label
- user_id
- product_id
- plan_id
- region_id
Expand Down Expand Up @@ -372,8 +375,6 @@ definitions:
body:
type: object
properties:
user_id:
$ref: '#/definitions/ID'
resource_id:
$ref: '#/definitions/ID'
values:
Expand All @@ -383,7 +384,6 @@ definitions:
must IEEE 1003.1 - 2001 Standard (checked in code).
additionalProperties: false
required:
- user_id
- resource_id
- values
additionalProperties: false
Expand All @@ -408,8 +408,6 @@ definitions:
body:
type: object
properties:
user_id:
$ref: '#/definitions/ID'
resource_id:
$ref: '#/definitions/ID'
values:
Expand All @@ -425,7 +423,6 @@ definitions:
format: datetime
additionalProperties: false
required:
- user_id
- resource_id
- values
- created_at
Expand Down
3 changes: 2 additions & 1 deletion specs/provisioning.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ definitions:
description: Type of operation this object represents
resource_id:
$ref: '#/definitions/ID'
team_id:
$ref: '#/definitions/ID'
user_id:
$ref: '#/definitions/ID'
message:
Expand All @@ -240,7 +242,6 @@ definitions:
required:
- type
- resource_id
- user_id
- message
- created_at
- updated_at
Expand Down

0 comments on commit 4f43a7b

Please sign in to comment.