Skip to content

Commit

Permalink
feat(outputs): update schema, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
vdice committed Jul 10, 2019
1 parent 53b63cd commit cbe30f3
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 12 deletions.
6 changes: 1 addition & 5 deletions cmd/porter/bundle.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -344,10 +343,7 @@ func buildBundleShowCommand(p *porter.Porter) *cobra.Command {
Optional output formats include json and yaml.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return errors.New("a claim name must be provided")
}
return opts.Validate(args)
return opts.Validate(args, p.Context)
},
RunE: func(cmd *cobra.Command, args []string) error {
cp := cnab.NewDuffle(p.Config)
Expand Down
35 changes: 31 additions & 4 deletions docs/content/authoring-bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Porter generates a bundle from its manifest, porter.yaml. The manifest is made u
* [Bundle Metadata](#bundle-metadata)
* [Mixins](#mixins)
* [Parameters](#parameters)
* [Outputs](#outputs)
* [Credentials](#credentials)
* [Bundle Actions](#bundle-actions)
* [Dependencies](#dependencies)
Expand Down Expand Up @@ -87,11 +88,37 @@ parameters:
* `path`: The path for the file. Required for file paths, there is no default.
* `sensitive`: Optional. Designate this parameter's value as sensitive, for masking in console output.

### Parameter Schema
## Outputs

The [CNAB Spec for parameter definitions](https://github.com/deislabs/cnab-spec/blob/master/101-bundle-json.md#definitions)
has full support for [json schema](https://json-schema.org). We aren't quite there yet but
are working towards it. Here is what Porter supports for defining schema for parameters currently:
Outputs are part of the [CNAB Spec](https://github.com/deislabs/cnab-spec/blob/master/101-bundle-json.md#outputs) and
allow outputs generated during the course of executing a bundle to be accessed. These are global/bundle-wide outputs,
as opposed to step outputs described in [Parameters, Credentials and Outputs](/wiring/). However, as of writing, each
bundle output is only valid if it references a step output declared under one or more [bundle actions](#bundle-actions).

```yaml
outputs:
- name: mysql_user
type: string
description: "MySQL user name"
- name: mysql_password
type: string
applyTo:
- "install"
- "upgrade"
```

* `name`: The name of the output.
* `type`: The data type of the output: string, integer, number, boolean.
* `applyTo`: (Optional) Restrict this output to a given list of actions. If empty or missing, applies to all actions.
* `description`: (Optional) A brief description of the given output.
* `sensitive`: (Optional) Designate an output as sensitive. Defaults to false.

### Definition Schema for Parameters and Outputs

The [CNAB Spec for definitions](https://github.com/deislabs/cnab-spec/blob/master/101-bundle-json.md#definitions)
applies to both parameters and outputs. It has full support for [json schema](https://json-schema.org). We aren't
quite there yet but are working towards it. Here is what Porter supports for defining schema for parameters and outputs
currently:

* `default`: The default value for the parameter. When a default is not provided, the `required` is defaulted to true.
* `required`: Specify if the parameter must be specified when the bundle is executed.
Expand Down
27 changes: 26 additions & 1 deletion docs/content/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ Global Flags:
This command is available both as `porter bundle list` and `porter bundles list`.

```console
$ porter bundle list --help
$ porter bundle list --help
List all bundles installed by Porter.

A listing of bundles currently installed by Porter will be provided, along with
Expand All @@ -226,6 +226,31 @@ Global Flags:
--debug Enable debug logging
```

### Bundle Show

This command is available both as `porter bundle show` and `porter bundles show`.

```console
$ porter bundle show --help
Displays info relating to a bundle claim, including status and a listing of outputs.

Usage:
porter bundles show [CLAIM] [flags]

Examples:
porter bundle show [CLAIM]

Optional output formats include json and yaml.


Flags:
-h, --help help for show
-o, --output string Specify an output format. Allowed values: table, json, yaml (default "table")

Global Flags:
--debug Enable debug logging
```

## Mixin Commands

### Mixins List
Expand Down
31 changes: 29 additions & 2 deletions pkg/porter/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package porter

import (
"fmt"
"os"
"path/filepath"
"time"

Expand All @@ -10,6 +11,8 @@ import (
"github.com/pkg/errors"

cnab "github.com/deislabs/porter/pkg/cnab/provider"
"github.com/deislabs/porter/pkg/config"
context "github.com/deislabs/porter/pkg/context"
"github.com/deislabs/porter/pkg/printer"
)

Expand All @@ -29,13 +32,32 @@ type ClaimListing struct {
Outputs
}

// Validate prepares for a show bundle action and validates the options.
func (so *ShowOptions) Validate(args []string) error {
// Validate prepares for a show bundle action and validates the args/options.
func (so *ShowOptions) Validate(args []string, cxt *context.Context) error {
err := so.sharedOptions.validateClaimName(args)
if err != nil {
return err
}

// If claim name not supplied, try to determine from manifest in current working directory
if so.sharedOptions.Name == "" {
pwd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "could not get current working directory")
}

manifestExists, err := cxt.FileSystem.Exists(filepath.Join(pwd, config.Name))
if err != nil {
return errors.Wrap(err, "could not check if porter manifest exists in current directory")
}

if manifestExists {
so.sharedOptions.File = config.Name
} else {
return errors.New("claim name must be provided")
}
}

parsedFormat, err := printer.ParseFormat(so.RawFormat)
if err != nil {
return err
Expand All @@ -48,7 +70,12 @@ func (so *ShowOptions) Validate(args []string) error {
// ShowBundle shows a bundle, or more properly a bundle claim, along with any
// associated outputs
func (p *Porter) ShowBundle(opts ShowOptions, cp cnab.Provider) error {
err := p.applyDefaultOptions(&opts.sharedOptions)
if err != nil {
return err
}
name := opts.sharedOptions.Name

claim, err := cp.FetchClaim(name)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions pkg/porter/templates/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
"items": {
"anyOf": []
}
},
"outputs": {
"type": "array",
"items": {
"anyOf": []
}
}
},
"additionalProperties": false,
Expand Down
6 changes: 6 additions & 0 deletions pkg/porter/testdata/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
"name": {
"type": "string"
},
"outputs": {
"items": {
"anyOf": []
},
"type": "array"
},
"uninstall": {
"items": {
"anyOf": [
Expand Down

0 comments on commit cbe30f3

Please sign in to comment.