2017-05-18 23:51:52 +02:00
|
|
|
// Licensed to Pulumi Corporation ("Pulumi") under one or more
|
|
|
|
// contributor license agreements. See the NOTICE file distributed with
|
|
|
|
// this work for additional information regarding copyright ownership.
|
|
|
|
// Pulumi licenses this file to You under the Apache License, Version 2.0
|
|
|
|
// (the "License"); you may not use this file except in compliance with
|
|
|
|
// the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
Add basic analyzer support
This change introduces the basic requirements for analyzers, as per
pulumi/coconut#119. In particular, an analyzer can implement either,
or both, of the RPC methods, Analyze and AnalyzeResource. The former
is meant to check an overall deployment (e.g., to ensure it has been
signed off on) and the latter is to check individual resources (e.g.,
to ensure properties of them are correct, such as checking style,
security, etc. rules). These run simultaneous to overall checking.
Analyzers are loaded as plugins just like providers are. The difference
is mainly in their naming ("analyzer-" prefix, rather than "resource-"),
and the RPC methods that they support.
This isn't 100% functional since we need a way to specify at the CLI
that a particular analyzer should be run, in addition to a way of
recording which analyzers certain projects should use in their manifests.
2017-03-11 08:49:17 +01:00
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2017-05-18 20:38:28 +02:00
|
|
|
"github.com/pulumi/lumi/pkg/pack"
|
|
|
|
"github.com/pulumi/lumi/pkg/tokens"
|
Add basic analyzer support
This change introduces the basic requirements for analyzers, as per
pulumi/coconut#119. In particular, an analyzer can implement either,
or both, of the RPC methods, Analyze and AnalyzeResource. The former
is meant to check an overall deployment (e.g., to ensure it has been
signed off on) and the latter is to check individual resources (e.g.,
to ensure properties of them are correct, such as checking style,
security, etc. rules). These run simultaneous to overall checking.
Analyzers are loaded as plugins just like providers are. The difference
is mainly in their naming ("analyzer-" prefix, rather than "resource-"),
and the RPC methods that they support.
This isn't 100% functional since we need a way to specify at the CLI
that a particular analyzer should be run, in addition to a way of
recording which analyzers certain projects should use in their manifests.
2017-03-11 08:49:17 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Analyzer provides a pluggable interface for performing arbitrary analysis of entire projects/stacks/snapshots, and/or
|
|
|
|
// individual resources, for arbitrary issues. These might be style, policy, correctness, security, or performance
|
|
|
|
// related. This interface hides the messiness of the underlying machinery, since providers are behind an RPC boundary.
|
|
|
|
type Analyzer interface {
|
|
|
|
// Closer closes any underlying OS resources associated with this provider (like processes, RPC channels, etc).
|
|
|
|
io.Closer
|
|
|
|
// Analyze analyzes an entire project/stack/snapshot, and returns any errors that it finds.
|
|
|
|
Analyze(url pack.PackageURL) ([]AnalyzeFailure, error)
|
|
|
|
// AnalyzeResource analyzes a single resource object, and returns any errors that it finds.
|
|
|
|
AnalyzeResource(t tokens.Type, props PropertyMap) ([]AnalyzeResourceFailure, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnalyzeFailure indicates that overall analysis failed; it contains the property and reason for the failure.
|
|
|
|
type AnalyzeFailure struct {
|
|
|
|
Reason string // the reason the analysis failed.
|
|
|
|
}
|
|
|
|
|
|
|
|
// AnalyzeResourceFailure indicates that resource analysis failed; it contains the property and reason for the failure.
|
|
|
|
type AnalyzeResourceFailure struct {
|
|
|
|
Property PropertyKey // the property that failed the analysis.
|
|
|
|
Reason string // the reason the property failed the analysis.
|
|
|
|
}
|