Skip to content

Commit

Permalink
Hide porter internal from explain command
Browse files Browse the repository at this point in the history
Some outputs and parameters are really porter "plumbing". They are used
by porter to implement things, like state or persistent parameters, but
aren't intended to be set or used by the end-user.

When we print out how to use a bundle with porter explain, those
shoudn't be displayed.

* Parameters with sources - these will be set by Porter internally.
* Outputs and Parameters that support bundle state.

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
carolynvs committed Aug 31, 2021
1 parent daad9f8 commit f92025b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
19 changes: 15 additions & 4 deletions pkg/cnab/extended_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,28 @@ func (b ExtendedBundle) IsPorterBundle() bool {
return madeByPorter
}

// IsInternalParameter determines if the provided param is an internal parameter
// to Porter after analyzing the provided bundle
func (b ExtendedBundle) IsInternalParameter(param string) bool {
if param, exists := b.Parameters[param]; exists {
// IsInternalParameter determines if the provided parameter is internal
// to Porter after analyzing the provided bundle.
func (b ExtendedBundle) IsInternalParameter(name string) bool {
if param, exists := b.Parameters[name]; exists {
if def, exists := b.Definitions[param.Definition]; exists {
return def.Comment == PorterInternal
}
}
return false
}

// IsInternalOutput determines if the provided output is internal
// to Porter after analyzing the provided bundle.
func (b ExtendedBundle) IsInternalOutput(name string) bool {
if output, exists := b.Outputs[name]; exists {
if def, exists := b.Definitions[output.Definition]; exists {
return def.Comment == PorterInternal
}
}
return false
}

// GetParameterType determines the type of parameter accounting for
// Porter-specific parameter types like file.
func (b ExtendedBundle) GetParameterType(def *definition.Schema) string {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cnab/parameter_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,14 @@ func (b ExtendedBundle) HasParameterSources() bool {
_, ok := b.Custom[ParameterSourcesExtensionKey]
return ok
}

// ParameterHasSource determines if the specified parameter has a parameter
// source defined.
func (b ExtendedBundle) ParameterHasSource(paramName string) bool {
sources, err := b.ReadParameterSources()
if err != nil {
return false
}
_, hasSource := sources[paramName]
return hasSource
}
9 changes: 7 additions & 2 deletions pkg/porter/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
sort.Sort(SortPrintableCredential(pb.Credentials))

for p, v := range bun.Parameters {
if bun.IsInternalParameter(p) {
if bun.IsInternalParameter(p) || bun.ParameterHasSource(p) {
continue
}

def, ok := bun.Definitions[v.Definition]
if !ok {
return nil, fmt.Errorf("unable to find definition %s", v.Definition)
Expand All @@ -253,6 +254,10 @@ func generatePrintable(bun cnab.ExtendedBundle, action string) (*PrintableBundle
sort.Sort(SortPrintableParameter(pb.Parameters))

for o, v := range bun.Outputs {
if bun.IsInternalOutput(o) {
continue
}

def, ok := bun.Definitions[v.Definition]
if !ok {
return nil, fmt.Errorf("unable to find definition %s", v.Definition)
Expand Down Expand Up @@ -330,7 +335,7 @@ func (p *Porter) printCredentialsExplainBlock(bun *PrintableBundle) error {
if len(bun.Credentials) == 0 {
return nil
}

fmt.Fprintln(p.Out, "Credentials:")
err := p.printCredentialsExplainTable(bun)
if err != nil {
Expand Down

0 comments on commit f92025b

Please sign in to comment.