Skip to content

Commit

Permalink
Merge pull request #15 from ibuildthecloud/project-fix
Browse files Browse the repository at this point in the history
Use project API and not account API to fix non-admins
  • Loading branch information
ibuildthecloud authored Aug 19, 2016
2 parents 875664a + 6bed87c commit 2c63fe6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
38 changes: 7 additions & 31 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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":
Expand Down
3 changes: 1 addition & 2 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 2c63fe6

Please sign in to comment.