Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #443 from leoswaldo/leoswaldo/enhacement/getTenant
Browse files Browse the repository at this point in the history
ciao-cli: code refactory of getTenant function
  • Loading branch information
kaccardi authored Aug 26, 2016
2 parents 971433b + e4446d6 commit 2286c30
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions ciao-cli/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,36 +252,27 @@ func getTenant(username string, password string, tenantID string) (string, strin
return "", "", err
}

if len(projects) == 0 {
if len(projects) <= 0 {
return "", tenantID, fmt.Errorf("No tenant name for %s", username)
}

if len(projects) > 1 {
if tenantID == "" {
fmt.Printf("Available projects for %s:\n", *identityUser)
for i, p := range projects {
fmt.Printf("\t Project[%d]: %s (%s)\n", i+1, p.Name, p.ID)
}
return "", "", fmt.Errorf("Please specify a project to use with -tenant-name or -tenant-id")
if tenantID == "" {
if len(projects) == 1 {
tenantName := projects[0].Name
tenantID = projects[0].ID
return tenantName, tenantID, nil
}

for _, p := range projects {
if p.ID != tenantID {
continue
}
return p.Name, tenantID, nil
fmt.Printf("Available projects for %s:\n", *identityUser)
for i, p := range projects {
fmt.Printf("\t Project[%d]: %s (%s)\n", i+1, p.Name, p.ID)
}
return "", tenantID, fmt.Errorf("No tenant name for %s", tenantID)
}

if tenantID != "" && projects[0].ID != tenantID {
return "", tenantID, fmt.Errorf("No tenant name for %s", tenantID)
return "", "", fmt.Errorf("Please specify a project to use with -tenant-name or -tenant-id")
}

tenantName := projects[0].Name
if tenantID == "" {
tenantID = projects[0].ID
for _, p := range projects {
if p.ID == tenantID {
return p.Name, tenantID, nil
}
}

return tenantName, tenantID, nil
return "", tenantID, fmt.Errorf("No tenant name for %s", tenantID)
}

0 comments on commit 2286c30

Please sign in to comment.