mirror of https://github.com/pulumi/pulumi.git
124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
// Copyright 2016-2023, Pulumi Corporation.
|
|
//
|
|
// Licensed 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.
|
|
|
|
package providers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/blang/semver"
|
|
|
|
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/resource/plugin"
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/workspace"
|
|
)
|
|
|
|
type BadProvider struct {
|
|
plugin.UnimplementedProvider
|
|
}
|
|
|
|
var _ plugin.Provider = (*BadProvider)(nil)
|
|
|
|
func (p *BadProvider) Close() error {
|
|
return nil
|
|
}
|
|
|
|
func (p *BadProvider) Pkg() tokens.Package {
|
|
return "bad"
|
|
}
|
|
|
|
func (p *BadProvider) GetSchema(request plugin.GetSchemaRequest) ([]byte, error) {
|
|
// The whole point of this provider is to return an invalid schema, so just make up a type for the
|
|
// property value.
|
|
resourceProperties := map[string]schema.PropertySpec{
|
|
"value": {
|
|
TypeSpec: schema.TypeSpec{
|
|
Type: "not a type",
|
|
},
|
|
},
|
|
}
|
|
resourceRequired := []string{"value"}
|
|
|
|
pkg := schema.PackageSpec{
|
|
Name: "simple",
|
|
Version: "3.0.0",
|
|
Resources: map[string]schema.ResourceSpec{
|
|
"simple:index:Resource": {
|
|
ObjectTypeSpec: schema.ObjectTypeSpec{
|
|
Type: "object",
|
|
Properties: resourceProperties,
|
|
Required: resourceRequired,
|
|
},
|
|
InputProperties: resourceProperties,
|
|
RequiredInputs: resourceRequired,
|
|
},
|
|
},
|
|
}
|
|
|
|
jsonBytes, err := json.Marshal(pkg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return jsonBytes, nil
|
|
}
|
|
|
|
func (p *BadProvider) CheckConfig(urn resource.URN, oldInputs, newInputs resource.PropertyMap,
|
|
allowUnknowns bool,
|
|
) (resource.PropertyMap, []plugin.CheckFailure, error) {
|
|
// Expect just the version
|
|
version, ok := newInputs["version"]
|
|
if !ok {
|
|
return nil, makeCheckFailure("version", "missing version"), nil
|
|
}
|
|
if !version.IsString() {
|
|
return nil, makeCheckFailure("version", "version is not a string"), nil
|
|
}
|
|
if version.StringValue() != "3.0.0" {
|
|
return nil, makeCheckFailure("version", "version is not 3.0.0"), nil
|
|
}
|
|
|
|
if len(newInputs) != 1 {
|
|
return nil, makeCheckFailure("", fmt.Sprintf("too many properties: %v", newInputs)), nil
|
|
}
|
|
|
|
return newInputs, nil, nil
|
|
}
|
|
|
|
func (p *BadProvider) Configure(inputs resource.PropertyMap) error {
|
|
return nil
|
|
}
|
|
|
|
func (p *BadProvider) GetPluginInfo() (workspace.PluginInfo, error) {
|
|
ver := semver.MustParse("3.0.0")
|
|
return workspace.PluginInfo{
|
|
Version: &ver,
|
|
}, nil
|
|
}
|
|
|
|
func (p *BadProvider) SignalCancellation() error {
|
|
return nil
|
|
}
|
|
|
|
func (p *BadProvider) GetMapping(key, provider string) ([]byte, string, error) {
|
|
return nil, "", nil
|
|
}
|
|
|
|
func (p *BadProvider) GetMappings(key string) ([]string, error) {
|
|
return nil, nil
|
|
}
|