pulumi/pkg/resource/deploy/deploytest/provider.go

145 lines
4.7 KiB
Go

// Copyright 2016-2018, 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 deploytest
import (
"github.com/blang/semver"
uuid "github.com/satori/go.uuid"
"github.com/pulumi/pulumi/pkg/resource"
"github.com/pulumi/pulumi/pkg/resource/plugin"
"github.com/pulumi/pulumi/pkg/tokens"
"github.com/pulumi/pulumi/pkg/util/contract"
"github.com/pulumi/pulumi/pkg/workspace"
)
type Provider struct {
Name string
Package tokens.Package
Version semver.Version
configured bool
CheckConfigF func(olds, news resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error)
DiffConfigF func(olds, news resource.PropertyMap) (plugin.DiffResult, error)
ConfigureF func(news resource.PropertyMap) error
CheckF func(urn resource.URN,
olds, news resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error)
DiffF func(urn resource.URN, id resource.ID, olds, news resource.PropertyMap) (plugin.DiffResult, error)
CreateF func(urn resource.URN,
inputs resource.PropertyMap) (resource.ID, resource.PropertyMap, resource.Status, error)
UpdateF func(urn resource.URN, id resource.ID,
olds, news resource.PropertyMap) (resource.PropertyMap, resource.Status, error)
DeleteF func(urn resource.URN, id resource.ID, olds resource.PropertyMap) (resource.Status, error)
ReadF func(urn resource.URN, id resource.ID, props resource.PropertyMap) (resource.PropertyMap, error)
InvokeF func(tok tokens.ModuleMember,
inputs resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error)
}
func (prov *Provider) SignalCancellation() error {
return nil
}
func (prov *Provider) Close() error {
return nil
}
func (prov *Provider) Pkg() tokens.Package {
return prov.Package
}
func (prov *Provider) GetPluginInfo() (workspace.PluginInfo, error) {
return workspace.PluginInfo{
Name: prov.Name,
Version: &prov.Version,
}, nil
}
func (prov *Provider) CheckConfig(olds,
news resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error) {
if prov.CheckConfigF == nil {
return news, nil, nil
}
return prov.CheckConfigF(olds, news)
}
func (prov *Provider) DiffConfig(olds, news resource.PropertyMap) (plugin.DiffResult, error) {
if prov.DiffConfigF == nil {
return plugin.DiffResult{}, nil
}
return prov.DiffConfigF(olds, news)
}
func (prov *Provider) Configure(inputs resource.PropertyMap) error {
contract.Assert(!prov.configured)
prov.configured = true
if prov.ConfigureF == nil {
return nil
}
return prov.ConfigureF(inputs)
}
func (prov *Provider) Check(urn resource.URN,
olds, news resource.PropertyMap, _ bool) (resource.PropertyMap, []plugin.CheckFailure, error) {
if prov.CheckF == nil {
return news, nil, nil
}
return prov.CheckF(urn, olds, news)
}
func (prov *Provider) Create(urn resource.URN, props resource.PropertyMap) (resource.ID,
resource.PropertyMap, resource.Status, error) {
if prov.CreateF == nil {
return resource.ID(uuid.NewV4().String()), resource.PropertyMap{}, resource.StatusOK, nil
}
return prov.CreateF(urn, props)
}
func (prov *Provider) Diff(urn resource.URN, id resource.ID,
olds resource.PropertyMap, news resource.PropertyMap, _ bool) (plugin.DiffResult, error) {
if prov.DiffF == nil {
return plugin.DiffResult{}, nil
}
return prov.DiffF(urn, id, olds, news)
}
func (prov *Provider) Update(urn resource.URN, id resource.ID,
olds resource.PropertyMap, news resource.PropertyMap) (resource.PropertyMap, resource.Status, error) {
if prov.UpdateF == nil {
return resource.PropertyMap{}, resource.StatusOK, nil
}
return prov.UpdateF(urn, id, olds, news)
}
func (prov *Provider) Delete(urn resource.URN,
id resource.ID, props resource.PropertyMap) (resource.Status, error) {
if prov.DeleteF == nil {
return resource.StatusOK, nil
}
return prov.DeleteF(urn, id, props)
}
func (prov *Provider) Read(urn resource.URN, id resource.ID,
props resource.PropertyMap) (resource.PropertyMap, error) {
if prov.ReadF == nil {
return resource.PropertyMap{}, nil
}
return prov.ReadF(urn, id, props)
}
func (prov *Provider) Invoke(tok tokens.ModuleMember,
args resource.PropertyMap) (resource.PropertyMap, []plugin.CheckFailure, error) {
if prov.InvokeF == nil {
return resource.PropertyMap{}, nil, nil
}
return prov.InvokeF(tok, args)
}