Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors #349

Merged
merged 6 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _2017-12-22_

- Redesigned the output of `view` and removed the `--format` flag.
- Updated formatting and flags of `envs list`, `services list`, `invites list`,
`machines list`, and `machines view`.
`machines list`, `machines view`, `policies list` and `policies view`.
- Added styling, color and org/project prompts throughout commands. Colors can
be disable by running `torus prefs set core.colors false`.

Expand Down
74 changes: 15 additions & 59 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,61 +59,14 @@ func listCmd(ctx *cli.Context) error {

tree := make(credentialTree)

// Retrieve org and project flag values
orgName := ctx.String("org")
var org *envelope.Org
if orgName == "" {
// Retrieve list of available orgs
orgs, err := client.Orgs.List(c)
if err != nil {
return errs.NewExitError("Failed to retrieve orgs list.")
}

// Prompt user to select from list of existing orgs
idx, _, err := SelectExistingOrgPrompt(orgs)
if err != nil {
return errs.NewExitError("Failed to select org.")
}

org = &orgs[idx]
orgName = org.Body.Name

} else {
// If org flag was used, identify the org supplied.
org, err = client.Orgs.GetByName(c, orgName)
if err != nil {
return errs.NewErrorExitError("Failed to retrieve org " + orgName, err)
}
if org == nil {
return errs.NewExitError("org " + orgName + " not found.")
}
org, err := getOrgWithPrompt(client, c, ctx.String("org"))
if err != nil {
return err
}

projectName := ctx.String("project")
var project *envelope.Project
if projectName == "" {
// Retrieve list of available projects
projects, err := client.Projects.List(c, org.ID)
if err != nil {
return errs.NewErrorExitError("Failed to retrieve projects list.", err)
}

// Prompt user to select from list of existing orgs
idx, _, err := SelectExistingProjectPrompt(projects)
if err != nil {
return errs.NewErrorExitError("Failed to select project.", err)
}

project = &projects[idx]
projectName = project.Body.Name

} else {
// Get Project for project name, confirm project exists
project, err = getProject(c, client, org.ID, projectName)
if err != nil {
return errs.NewErrorExitError("Failed to get project info for "+
orgName+"/"+projectName, err)
}
project, err := getProjectWithPrompt(client, c, org, ctx.String("project"))
if err != nil {
return err
}

// Retrieve environment flag values
Expand All @@ -138,8 +91,8 @@ func listCmd(ctx *cli.Context) error {
// Create a PathExp based on flags. This is the search space that
// will be used to retrieve credentials.
filterPathExp, err := pathexp.New(
orgName,
projectName,
org.Body.Name,
project.Body.Name,
envFilters,
serviceFilters,
instanceFilters,
Expand Down Expand Up @@ -226,7 +179,8 @@ func listCmd(ctx *cli.Context) error {
// Check for each env and service in the filtered list, add
// any credentials along that path to that env/service branch
// of the credentialsTree
projectPath := "/" + orgName + "/" + projectName + "/"
credCount := 0
projectPath := "/" + org.Body.Name + "/" + project.Body.Name + "/"
for _, e := range filteredEnvNames {
for _, s := range filteredServiceNames {
builtPathExp, err := pathexp.Parse(projectPath + e + "/" + s + "/*/*")
Expand Down Expand Up @@ -262,8 +216,8 @@ func listCmd(ctx *cli.Context) error {
if(verbose){
fmt.Println("")
projW := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
fmt.Fprintf(projW, "Org:\t" + ui.Faint(orgName) + "\t\n")
fmt.Fprintf(projW, "Project:\t" + ui.Faint(projectName) + "\t\n")
fmt.Fprintf(projW, "Org:\t" + ui.Faint(org.Body.Name) + "\t\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably bold org and project?

fmt.Fprintf(projW, "Project:\t" + ui.Faint(project.Body.Name) + "\t\n")
projW.Flush()
}

Expand All @@ -280,6 +234,7 @@ func listCmd(ctx *cli.Context) error {
continue
}
for c, cred := range tree[e][s] {
credCount += 1
if verbose {
credPath := (*cred.Body).GetPathExp().String() + "/"
fmt.Fprintf(w, "\t\t%s\t(%s)\t\n", c, ui.Faint(credPath+c))
Expand All @@ -290,7 +245,8 @@ func listCmd(ctx *cli.Context) error {
}
}
w.Flush()
fmt.Println("")

fmt.Printf("\n(%d) secrets found\n.", credCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add some color to the number (light gray?)


return nil
}
Expand Down
29 changes: 11 additions & 18 deletions cmd/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"text/tabwriter"

"github.com/urfave/cli"
"github.com/juju/ansiterm"

"github.com/manifoldco/torus-cli/api"
"github.com/manifoldco/torus-cli/apitypes"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/manifoldco/torus-cli/identity"
"github.com/manifoldco/torus-cli/pathexp"
"github.com/manifoldco/torus-cli/primitive"
"github.com/manifoldco/torus-cli/ui"
"github.com/manifoldco/torus-cli/validate"
)

Expand All @@ -33,7 +35,7 @@ func init() {
Name: "list",
Usage: "List all policies for an organization",
Flags: []cli.Flag{
orgFlag("The org to show policies for", true),
orgFlag("The org to show policies for", false),
},
Action: chain(
ensureDaemon, ensureSession, loadDirPrefs, loadPrefDefaults,
Expand Down Expand Up @@ -332,14 +334,9 @@ func listPoliciesCmd(ctx *cli.Context) error {
client := api.NewClient(cfg)
c := context.Background()

// Look up the target org
var org *envelope.Org
org, err = client.Orgs.GetByName(c, ctx.String("org"))
org, err := getOrgWithPrompt(client, c, ctx.String("org"))
if err != nil {
return errs.NewErrorExitError(policyListFailed, err)
}
if org == nil {
return errs.NewExitError("Org not found.")
return err
}

var getAttachments, display sync.WaitGroup
Expand Down Expand Up @@ -400,9 +397,8 @@ func listPoliciesCmd(ctx *cli.Context) error {

display.Wait()
fmt.Println("")
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
fmt.Fprintln(w, "POLICY NAME\tTYPE\tATTACHED TO")
fmt.Fprintln(w, " \t \t ")
w := ansiterm.NewTabWriter(os.Stdout, 0, 0, 4, ' ', 0)
fmt.Fprintf(w, "%s\t%s\t%s\n", ui.Bold("Policy Name"), ui.Bold("Type"), ui.Bold("Attached To"))
for _, name := range sortedNames {
teamNames := ""
policy := policiesByName[name]
Expand Down Expand Up @@ -441,12 +437,9 @@ func viewPolicyCmd(ctx *cli.Context) error {
client := api.NewClient(cfg)
c := context.Background()

org, err := client.Orgs.GetByName(c, ctx.String("org"))
org, err := getOrgWithPrompt(client, c, ctx.String("org"))
if err != nil {
return errs.NewErrorExitError("Unable to lookup org.", err)
}
if org == nil {
return errs.NewExitError("Org not found.")
return err
}

policies, err := client.Policies.List(c, org.ID, policyName)
Expand All @@ -463,8 +456,8 @@ func viewPolicyCmd(ctx *cli.Context) error {

w := tabwriter.NewWriter(os.Stdout, 2, 0, 1, ' ', 0)

fmt.Fprintf(w, "Name:\t%s\n", p.Name)
fmt.Fprintf(w, "Description:\t%s\n", p.Description)
fmt.Fprintf(w, "%s\t%s\n", ui.Bold("Name:"), p.Name)
fmt.Fprintf(w, "%s\t%s\n", ui.Bold("Description:"), p.Description)
fmt.Fprintln(w, "")
w.Flush()

Expand Down
3 changes: 3 additions & 0 deletions cmd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ func getProjectWithPrompt(client *api.Client, c context.Context, org *envelope.O
if err != nil {
return nil, err
}
if len(projects) < 1 {
return nil, errs.NewExitError("No projects found in org " + org.Body.Name)
}

// Prompt user to select from list of existing projects
idx, _, err := SelectExistingProjectPrompt(projects)
Expand Down
11 changes: 5 additions & 6 deletions internal/qa.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ If you have `torus` installed, start fresh `npm uninstall -g torus-cli`
- [ ] `npm install -g torus-cli` installs `torus`
- [ ] `torus help` displays the help prompt after an
`npm install -g torus-cli`
- [ ] `torus prefs list` displays the path to your `public_key_file`
- [ ] `torus prefs list` displays your preferences
- [ ] `torus signup` prompts you for an verification code username, name and
email, before verifying and authenticating you
- [ ] A user cannot perform any writes without verifying their account
- [ ] `torus status` displays your current working context
- [ ] `torus logout` logs you out
- [ ] `torus login` prompts you for an email and password, before
authenticating you
- [ ] You can login using environment variables (`TORUS_EMAIL` and
`TORUS_PASSWORD`)
`TORUS_PASSWORD`) through `torus status`

### Account

Expand All @@ -37,7 +36,7 @@ If you have `torus` installed, start fresh `npm uninstall -g torus-cli`

- [ ] `torus teams list --org [username]` displays `owner` `admin` and
`member` teams, and you are a member of each
- [ ] `torus teams create [name] --org [org-name]` creates an org.
- [ ] `torus teams create [name] --org [org-name]` creates a team.
- [ ] `torus invites send [email] —org [org-name]` generates an access code
and sends it to the user
- [ ] `torus invites accept —org [org] [email] [code]` prompts a user to
Expand All @@ -46,9 +45,9 @@ If you have `torus` installed, start fresh `npm uninstall -g torus-cli`
- [ ] `torus invites list —org [org]` lists the outstanding invite
- [ ] `torus invites approve [email] —org [org]` approves the users invite
- [ ] The user is now a member of the members team
- [ ] `torus teams add [name] [username] —org [org-name]` adds the user to a
- [ ] `torus teams add [username] [name] —org [org-name]` adds the user to a
team
- [ ] `torus teams remove [name] [username] —org [org-name]` removes the user
- [ ] `torus teams remove [username] [name] —org [org-name]` removes the user
from a team
- [ ] Users cannot remove themselves from system-teams

Expand Down