From 6bed87ce68901ccf27b109a266ea2ba51989ee5e Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 18 Aug 2016 21:54:53 -0700 Subject: [PATCH] Use project API and not account API to fix non-admins --- cmd/common.go | 38 +++++++------------------------------- cmd/env.go | 3 +-- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index 3ed758fbe..822059f8b 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -153,25 +153,6 @@ func GetOrCreateDefaultStack(c *client.RancherClient, name string) (*client.Envi }) } -func getProjectByName(c *client.RancherClient, name string) (client.ResourceCollection, error) { - var result client.ResourceCollection - err := c.List("account", &client.ListOpts{ - Filters: map[string]interface{}{ - "kind": "project", - "limit": "-2", - "name": name, - }, - }, &result) - for i, resource := range result.Data { - err := c.ById("project", resource.Id, &resource) - if err != nil { - return result, err - } - result.Data[i] = resource - } - return result, err -} - func getHostByHostname(c *client.RancherClient, name string) (client.ResourceCollection, error) { var result client.ResourceCollection allHosts, err := c.Host.List(nil) @@ -225,16 +206,13 @@ func Lookup(c *client.RancherClient, name string, types ...string) (*client.Reso } var collection client.ResourceCollection - // search by name for project doesn't work - if schemaType != "project" { - if err := c.List(schemaType, &client.ListOpts{ - Filters: map[string]interface{}{ - "name": name, - "removed_null": 1, - }, - }, &collection); err != nil { - return nil, err - } + if err := c.List(schemaType, &client.ListOpts{ + Filters: map[string]interface{}{ + "name": name, + "removed_null": 1, + }, + }, &collection); err != nil { + return nil, err } if len(collection.Data) > 1 { @@ -249,8 +227,6 @@ func Lookup(c *client.RancherClient, name string, types ...string) (*client.Reso var err error // Per type specific logic switch schemaType { - case "project": - collection, err = getProjectByName(c, name) case "host": collection, err = getHostByHostname(c, name) case "service": diff --git a/cmd/env.go b/cmd/env.go index 481f91191..06201f943 100644 --- a/cmd/env.go +++ b/cmd/env.go @@ -226,8 +226,7 @@ func envLs(ctx *cli.Context) error { collection := client.ProjectCollection{} listOpts := defaultListOpts(ctx) - listOpts.Filters["kind"] = "project" - if err = c.List("account", listOpts, &collection); err != nil { + if err = c.List("project", listOpts, &collection); err != nil { return err }