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

Include list of mixins used in porter explain and simplify explain output #1741

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 2 deletions docs/content/archive-bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,4 @@ space_name Name for DO Space
Outputs:
Name Description Type Applies To
service_ip IP Address assigned to the Load Balancer string All Actions

No custom actions defined
```
2 changes: 0 additions & 2 deletions docs/content/examine-bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ space_name Name for DO Space
Outputs:
Name Description Type Applies To
service_ip IP Address assigned to the Load Balancer string install,upgrade

No custom actions defined
```

The `porter explain` command will show what credentials and parameters are required for the bundle, what outputs are generated, and what custom actions have been defined. For `parameters`, this command will also show you the default value, if one has been provided. Additionally, the user can quickly see what actions a `parameter` or `output` apply to.
Expand Down
6 changes: 0 additions & 6 deletions docs/content/plugin-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,6 @@ Version: 0.1.0
Credentials:
Name Description Required
password Password for installing the world. We recommend getting this from a secret store. true

No parameters defined

No outputs defined

No custom actions defined
```

Since the bundle needs a credential we will generate some for it using `porter
Expand Down
12 changes: 0 additions & 12 deletions docs/content/quickstart/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ namespace string false All
wordpress-name string porter-ci-wordpress false All Actions
wordpress-password string <nil> true install,upgrade

No outputs defined

Actions:
Name Description Modifies Installation Stateless
ping ping true false
Expand All @@ -70,16 +68,6 @@ $ porter explain --reference getporter/porter-hello:v0.1.0
Name: HELLO
Description: An example Porter configuration
Version: 0.1.0

No credentials defined

No parameters defined

No outputs defined

No custom actions defined

No dependencies defined
```

## Install a Bundle
Expand Down
8 changes: 0 additions & 8 deletions docs/content/quickstart/credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ Porter Version: v0.38.1
Credentials:
Name Description Required Applies To
github-token A GitHub Personal Access Token. Generate one at https://github.com/settings/tokens. No scopes are required. true install,upgrade

No parameters defined

No outputs defined

No custom actions defined

No dependencies defined
```

In the Credentials section of the output returned by explain, there is a single required credential, github-token, that applies to the install and upgrade actions.
Expand Down
7 changes: 0 additions & 7 deletions docs/content/quickstart/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@ Description: An example Porter bundle with parameters
Version: 0.1.0
Porter Version: v0.38.1-32-gb76f5c1c

No credentials defined

Parameters:
Name Description Type Default Required Applies To
name Name of to whom we should say hello string llama false All Actions

No outputs defined

No custom actions defined

No dependencies defined
```

In the Parameters section of the output returned by explain, there is a single optional string parameter, name, with a default of "llama" that applies to "All Actions".
Expand Down
140 changes: 75 additions & 65 deletions pkg/porter/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type PrintableBundle struct {
Outputs []PrintableOutput `json:"outputs,omitempty" yaml:"outputs,omitempty"`
Actions []PrintableAction `json:"customActions,omitempty" yaml:"customActions,omitempty"`
Dependencies []PrintableDependency `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
Mixins []string `json:"mixins" yaml:"mixins"`
}

type PrintableCredential struct {
Expand Down Expand Up @@ -184,25 +185,35 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
stamp = configadapter.Stamp{}
}

solver := &cnab.DependencySolver{}
deps, err := solver.ResolveDependencies(bun)
if err != nil {
return nil, errors.Wrapf(err, "error resolving bundle dependencies")
}

pb := PrintableBundle{
Name: bun.Name,
Description: bun.Description,
Version: bun.Version,
PorterVersion: stamp.Version,
Actions: make([]PrintableAction, 0, len(bun.Actions)),
Credentials: make([]PrintableCredential, 0, len(bun.Credentials)),
Parameters: make([]PrintableParameter, 0, len(bun.Parameters)),
Outputs: make([]PrintableOutput, 0, len(bun.Outputs)),
Dependencies: make([]PrintableDependency, 0, len(deps)),
Mixins: make([]string, 0, len(stamp.Mixins)),
}

actions := make([]PrintableAction, 0, len(bun.Actions))
for a, v := range bun.Actions {
pa := PrintableAction{}
pa.Name = a
pa.Description = v.Description
pa.Modifies = v.Modifies
pa.Stateless = v.Stateless
actions = append(actions, pa)
pb.Actions = append(pb.Actions, pa)
}
sort.Sort(SortPrintableAction(actions))
sort.Sort(SortPrintableAction(pb.Actions))

creds := make([]PrintableCredential, 0, len(bun.Credentials))
for c, v := range bun.Credentials {
pc := PrintableCredential{}
pc.Name = c
Expand All @@ -211,12 +222,11 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
pc.ApplyTo = generateApplyToString(v.ApplyTo)

if shouldIncludeInExplainOutput(&v, action) {
creds = append(creds, pc)
pb.Credentials = append(pb.Credentials, pc)
}
}
sort.Sort(SortPrintableCredential(creds))
sort.Sort(SortPrintableCredential(pb.Credentials))

params := make([]PrintableParameter, 0, len(bun.Parameters))
for p, v := range bun.Parameters {
if bun.IsInternalParameter(p) {
continue
Expand All @@ -237,12 +247,11 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
pp.Description = v.Description

if shouldIncludeInExplainOutput(&v, action) {
params = append(params, pp)
pb.Parameters = append(pb.Parameters, pp)
}
}
sort.Sort(SortPrintableParameter(params))
sort.Sort(SortPrintableParameter(pb.Parameters))

outputs := make([]PrintableOutput, 0, len(bun.Outputs))
for o, v := range bun.Outputs {
def, ok := bun.Definitions[v.Definition]
if !ok {
Expand All @@ -258,31 +267,25 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
po.Description = v.Description

if shouldIncludeInExplainOutput(&v, action) {
outputs = append(outputs, po)
pb.Outputs = append(pb.Outputs, po)
}
}
sort.Sort(SortPrintableOutput(outputs))

solver := &cnab.DependencySolver{}
deps, err := solver.ResolveDependencies(bun)
if err != nil {
return nil, errors.Wrapf(err, "error executing dependencies")
}
sort.Sort(SortPrintableOutput(pb.Outputs))

dependencies := make([]PrintableDependency, 0, len(deps))
for _, dep := range deps {
pd := PrintableDependency{}
pd.Alias = dep.Alias
pd.Reference = dep.Reference

dependencies = append(dependencies, pd)
pb.Dependencies = append(pb.Dependencies, pd)
}
// dependencies are sorted by their dependency sequence already

for mixin := range stamp.Mixins {
pb.Mixins = append(pb.Mixins, mixin)
}
sort.Strings(pb.Mixins)

pb.Actions = actions
pb.Credentials = creds
pb.Outputs = outputs
pb.Parameters = params
pb.Dependencies = dependencies
return &pb, nil
}

Expand Down Expand Up @@ -318,19 +321,22 @@ func (p *Porter) printBundleExplainTable(bun *PrintableBundle) error {
p.printOutputsExplainBlock(bun)
p.printActionsExplainBlock(bun)
p.printDependenciesExplainBlock(bun)

fmt.Fprintf(p.Out, "This bundle uses the following tools: %s.\n", strings.Join(bun.Mixins, ", "))
return nil
}

func (p *Porter) printCredentialsExplainBlock(bun *PrintableBundle) error {
if len(bun.Credentials) > 0 {
fmt.Fprintln(p.Out, "Credentials:")
err := p.printCredentialsExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print credentials table")
}
} else {
fmt.Fprintln(p.Out, "No credentials defined")
if len(bun.Credentials) == 0 {
return nil
}

fmt.Fprintln(p.Out, "Credentials:")
err := p.printCredentialsExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print credentials table")
}

fmt.Fprintln(p.Out, "") // force a blank line after this block
return nil
}
Expand All @@ -347,15 +353,16 @@ func (p *Porter) printCredentialsExplainTable(bun *PrintableBundle) error {
}

func (p *Porter) printParametersExplainBlock(bun *PrintableBundle) error {
if len(bun.Parameters) > 0 {
fmt.Fprintln(p.Out, "Parameters:")
err := p.printParametersExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print parameters table")
}
} else {
fmt.Fprintln(p.Out, "No parameters defined")
if len(bun.Parameters) == 0 {
return nil
}

fmt.Fprintln(p.Out, "Parameters:")
err := p.printParametersExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print parameters table")
}

fmt.Fprintln(p.Out, "") // force a blank line after this block
return nil
}
Expand All @@ -372,15 +379,16 @@ func (p *Porter) printParametersExplainTable(bun *PrintableBundle) error {
}

func (p *Porter) printOutputsExplainBlock(bun *PrintableBundle) error {
if len(bun.Outputs) > 0 {
fmt.Fprintln(p.Out, "Outputs:")
err := p.printOutputsExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print outputs table")
}
} else {
fmt.Fprintln(p.Out, "No outputs defined")
if len(bun.Outputs) == 0 {
return nil
}

fmt.Fprintln(p.Out, "Outputs:")
err := p.printOutputsExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print outputs table")
}

fmt.Fprintln(p.Out, "") // force a blank line after this block
return nil
}
Expand All @@ -398,15 +406,16 @@ func (p *Porter) printOutputsExplainTable(bun *PrintableBundle) error {
}

func (p *Porter) printActionsExplainBlock(bun *PrintableBundle) error {
if len(bun.Actions) > 0 {
fmt.Fprintln(p.Out, "Actions:")
err := p.printActionsExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print actions block")
}
} else {
fmt.Fprintln(p.Out, "No custom actions defined")
if len(bun.Actions) == 0 {
return nil
}

fmt.Fprintln(p.Out, "Actions:")
err := p.printActionsExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print actions block")
}

fmt.Fprintln(p.Out, "") // force a blank line after this block
return nil
}
Expand All @@ -425,15 +434,16 @@ func (p *Porter) printActionsExplainTable(bun *PrintableBundle) error {

// Dependencies
func (p *Porter) printDependenciesExplainBlock(bun *PrintableBundle) error {
if len(bun.Dependencies) > 0 {
fmt.Fprintln(p.Out, "Dependencies:")
err := p.printDependenciesExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print dependencies table")
}
} else {
fmt.Fprintln(p.Out, "No dependencies defined")
if len(bun.Dependencies) == 0 {
return nil
}

fmt.Fprintln(p.Out, "Dependencies:")
err := p.printDependenciesExplainTable(bun)
if err != nil {
return errors.Wrap(err, "unable to print dependencies table")
}

fmt.Fprintln(p.Out, "") // force a blank line after this block
return nil
}
Expand Down
Loading