github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/resource/deploy/deploytest/analyzer.go (about)

     1  // Copyright 2016-2018, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package deploytest
    16  
    17  import (
    18  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
    19  	"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
    20  	"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
    21  )
    22  
    23  type Analyzer struct {
    24  	Info plugin.AnalyzerInfo
    25  
    26  	AnalyzeF      func(r plugin.AnalyzerResource) ([]plugin.AnalyzeDiagnostic, error)
    27  	AnalyzeStackF func(resources []plugin.AnalyzerStackResource) ([]plugin.AnalyzeDiagnostic, error)
    28  
    29  	ConfigureF func(policyConfig map[string]plugin.AnalyzerPolicyConfig) error
    30  }
    31  
    32  var _ = plugin.Analyzer((*Analyzer)(nil))
    33  
    34  func (a *Analyzer) Close() error {
    35  	return nil
    36  }
    37  
    38  func (a *Analyzer) Name() tokens.QName {
    39  	return tokens.QName(a.Info.Name)
    40  }
    41  
    42  func (a *Analyzer) Analyze(r plugin.AnalyzerResource) ([]plugin.AnalyzeDiagnostic, error) {
    43  	if a.AnalyzeF != nil {
    44  		return a.AnalyzeF(r)
    45  	}
    46  	return nil, nil
    47  }
    48  
    49  func (a *Analyzer) AnalyzeStack(resources []plugin.AnalyzerStackResource) ([]plugin.AnalyzeDiagnostic, error) {
    50  	if a.AnalyzeStackF != nil {
    51  		return a.AnalyzeStackF(resources)
    52  	}
    53  	return nil, nil
    54  }
    55  
    56  func (a *Analyzer) GetAnalyzerInfo() (plugin.AnalyzerInfo, error) {
    57  	return a.Info, nil
    58  }
    59  
    60  func (a *Analyzer) GetPluginInfo() (workspace.PluginInfo, error) {
    61  	return workspace.PluginInfo{
    62  		Kind: workspace.AnalyzerPlugin,
    63  		Name: a.Info.Name,
    64  	}, nil
    65  }
    66  
    67  func (a *Analyzer) Configure(policyConfig map[string]plugin.AnalyzerPolicyConfig) error {
    68  	if a.ConfigureF != nil {
    69  		return a.ConfigureF(policyConfig)
    70  	}
    71  	return nil
    72  }