Skip to content
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: 2 additions & 0 deletions cmd/porter/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ The lint command is run automatically when you build a bundle. The command is av
"Path to the porter manifest file. Defaults to the bundle in the current directory.")
f.StringVarP(&opts.RawFormat, "output", "o", string(porter.LintDefaultFormats),
"Specify an output format. Allowed values: "+porter.LintAllowFormats.String())
f.BoolVar(&opts.InsecureRegistry, "insecure-registry", false,
"Don't require TLS for registries")

return cmd
}
Expand Down
7 changes: 4 additions & 3 deletions docs/content/docs/references/cli/bundles_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ porter bundles lint [flags]
### Options

```
-f, --file string Path to the porter manifest file. Defaults to the bundle in the current directory.
-h, --help help for lint
-o, --output string Specify an output format. Allowed values: plaintext, json (default "plaintext")
-f, --file string Path to the porter manifest file. Defaults to the bundle in the current directory.
-h, --help help for lint
--insecure-registry Don't require TLS for registries
-o, --output string Specify an output format. Allowed values: plaintext, json (default "plaintext")
```

### Options inherited from parent commands
Expand Down
7 changes: 4 additions & 3 deletions docs/content/docs/references/cli/lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ porter lint [flags]
### Options

```
-f, --file string Path to the porter manifest file. Defaults to the bundle in the current directory.
-h, --help help for lint
-o, --output string Specify an output format. Allowed values: plaintext, json (default "plaintext")
-f, --file string Path to the porter manifest file. Defaults to the bundle in the current directory.
-h, --help help for lint
--insecure-registry Don't require TLS for registries
-o, --output string Specify an output format. Allowed values: plaintext, json (default "plaintext")
```

### Options inherited from parent commands
Expand Down
49 changes: 49 additions & 0 deletions docs/content/docs/references/linter.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ weight: 9
- [porter-100](#porter-100)
- [porter-101](#porter-101)
- [porter-102](#porter-102)
- [porter-103](#porter-103)
- [porter-104](#porter-104)
- [porter-105](#porter-105)

## exec-100

Expand Down Expand Up @@ -71,3 +74,49 @@ To fix the problem, you should name ensure all dependencies have different names

You can find more information about dependencies in [Dependencies](/docs/development/authoring-a-bundle/working-with-dependencies/).

## porter-103

The porter-103 error is a message generated by the porter lint command when it detects that a dependency maps a parameter that is not defined on the dependency bundle.

```yaml
dependencies:
requires:
- name: mysql
bundle:
reference: "getporter/mysql:v0.1.0"
parameters:
NOT_A_REAL_PARAM: "some value" # This parameter isn't defined on the mysql bundle
```

Mapping a value to a parameter that doesn't exist on the dependency bundle results in a failure when the dependency is installed.

To fix the problem, check the dependency bundle for the parameters it actually defines, and correct the name in your `parameters` mapping.

You can find more information about dependencies in [Dependencies](/docs/development/authoring-a-bundle/working-with-dependencies/).

## porter-104

The porter-104 error is the same check as [porter-103](#porter-103), but for the `credentials` mapping of a dependency: it is generated when a dependency maps a credential that is not defined on the dependency bundle.

```yaml
dependencies:
requires:
- name: mysql
bundle:
reference: "getporter/mysql:v0.1.0"
credentials:
NOT_A_REAL_CRED: "some value" # This credential isn't defined on the mysql bundle
```

To fix the problem, check the dependency bundle for the credentials it actually defines, and correct the name in your `credentials` mapping.

You can find more information about dependencies in [Dependencies](/docs/development/authoring-a-bundle/working-with-dependencies/).

## porter-105

The porter-105 warning is generated by the porter lint command when it cannot resolve a dependency's bundle reference, either because the reference is invalid or because it could not be pulled from its cache or registry.

Because the bundle could not be resolved, porter cannot check that its `parameters` and `credentials` mappings ([porter-103](#porter-103), [porter-104](#porter-104)) are valid, so that check is skipped for this dependency.

To fix the problem, check that the dependency's `bundle.reference` is correct and reachable, for example by running `porter pull <reference>`.

34 changes: 33 additions & 1 deletion pkg/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"

"get.porter.sh/porter/pkg/cnab"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/manifest"
"get.porter.sh/porter/pkg/mixin/query"
Expand Down Expand Up @@ -162,7 +163,7 @@ type action struct {
steps manifest.Steps
}

func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest, config *config.Config) (Results, error) {
func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest, config *config.Config, depBundles map[string]cnab.ExtendedBundle) (Results, error) {
// Check for reserved porter prefix on parameter names
reservedPrefixes := []string{"porter-", "porter_"}
params := m.Parameters
Expand Down Expand Up @@ -234,6 +235,37 @@ func (l *Linter) Lint(ctx context.Context, m *manifest.Manifest, config *config.
} else {
deps[dep.Name] = nil
}

depBundle, ok := depBundles[dep.Name]
if !ok {
// Either the dependency has no bundle resolved for it, or resolution
// failed and was already reported by the caller.
continue
}

for paramName := range dep.Parameters {
if _, ok := depBundle.Parameters[paramName]; !ok {
results = append(results, Result{
Level: LevelError,
Code: "porter-103",
Title: "Dependency error",
Message: fmt.Sprintf("dependencies.%s.parameters.%s is not defined as a parameter on the dependency bundle", dep.Name, paramName),
URL: "https://porter.sh/reference/linter/#porter-103",
})
}
}

for credName := range dep.Credentials {
if _, ok := depBundle.Credentials[credName]; !ok {
results = append(results, Result{
Level: LevelError,
Code: "porter-104",
Title: "Dependency error",
Message: fmt.Sprintf("dependencies.%s.credentials.%s is not defined as a credential on the dependency bundle", dep.Name, credName),
URL: "https://porter.sh/reference/linter/#porter-104",
})
}
}
}

span.Debug("Running linters for each mixin used in the manifest...")
Expand Down
Loading