2022-05-24 22:05:16 +00:00
|
|
|
// Copyright 2016-2022, Pulumi Corporation.
|
2020-01-21 22:45:48 +00:00
|
|
|
//
|
|
|
|
// 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 schema
|
|
|
|
|
|
|
|
import (
|
2021-07-09 17:23:10 +00:00
|
|
|
"bytes"
|
2020-01-21 22:45:48 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-05-14 20:35:57 +00:00
|
|
|
"net/url"
|
2020-01-21 22:45:48 +00:00
|
|
|
"regexp"
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/blang/semver"
|
2021-08-31 02:29:24 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2023-06-28 16:02:04 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/slice"
|
2021-11-13 02:37:17 +00:00
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
2020-01-21 22:45:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
// - Providerless packages
|
|
|
|
|
|
|
|
// Type represents a datatype in the Pulumi Schema. Types created by this package are identical if they are
|
|
|
|
// equal values.
|
|
|
|
type Type interface {
|
|
|
|
String() string
|
|
|
|
|
|
|
|
isType()
|
|
|
|
}
|
|
|
|
|
|
|
|
type primitiveType int
|
|
|
|
|
|
|
|
const (
|
2024-04-09 07:59:16 +00:00
|
|
|
boolType primitiveType = 1
|
|
|
|
intType primitiveType = 2
|
|
|
|
numberType primitiveType = 3
|
|
|
|
stringType primitiveType = 4
|
|
|
|
archiveType primitiveType = 5
|
|
|
|
assetType primitiveType = 6
|
|
|
|
anyType primitiveType = 7
|
|
|
|
jsonType primitiveType = 8
|
|
|
|
anyResourceType primitiveType = 9
|
2020-01-21 22:45:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (t primitiveType) String() string {
|
|
|
|
switch t {
|
|
|
|
case boolType:
|
|
|
|
return "boolean"
|
|
|
|
case intType:
|
|
|
|
return "integer"
|
|
|
|
case numberType:
|
|
|
|
return "number"
|
|
|
|
case stringType:
|
|
|
|
return "string"
|
|
|
|
case archiveType:
|
|
|
|
return "pulumi:pulumi:Archive"
|
|
|
|
case assetType:
|
|
|
|
return "pulumi:pulumi:Asset"
|
2020-05-19 09:41:06 +00:00
|
|
|
case jsonType:
|
|
|
|
fallthrough
|
2024-04-09 07:59:16 +00:00
|
|
|
case anyResourceType:
|
|
|
|
fallthrough
|
2020-01-21 22:45:48 +00:00
|
|
|
case anyType:
|
|
|
|
return "pulumi:pulumi:Any"
|
|
|
|
default:
|
|
|
|
panic("unknown primitive type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (primitiveType) isType() {}
|
|
|
|
|
|
|
|
// IsPrimitiveType returns true if the given Type is a primitive type. The primitive types are bool, int, number,
|
|
|
|
// string, archive, asset, and any.
|
|
|
|
func IsPrimitiveType(t Type) bool {
|
2021-06-24 16:17:55 +00:00
|
|
|
_, ok := plainType(t).(primitiveType)
|
2020-01-21 22:45:48 +00:00
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
// BoolType represents the set of boolean values.
|
|
|
|
BoolType Type = boolType
|
|
|
|
// IntType represents the set of 32-bit integer values.
|
|
|
|
IntType Type = intType
|
|
|
|
// NumberType represents the set of IEEE754 double-precision values.
|
|
|
|
NumberType Type = numberType
|
|
|
|
// StringType represents the set of UTF-8 string values.
|
|
|
|
StringType Type = stringType
|
|
|
|
// ArchiveType represents the set of Pulumi Archive values.
|
|
|
|
ArchiveType Type = archiveType
|
|
|
|
// AssetType represents the set of Pulumi Asset values.
|
|
|
|
AssetType Type = assetType
|
2020-05-19 09:41:06 +00:00
|
|
|
// JSONType represents the set of JSON-encoded values.
|
|
|
|
JSONType Type = jsonType
|
2020-01-21 22:45:48 +00:00
|
|
|
// AnyType represents the complete set of values.
|
|
|
|
AnyType Type = anyType
|
2024-04-09 07:59:16 +00:00
|
|
|
// AnyResourceType represents any Pulumi resource - custom or component
|
|
|
|
AnyResourceType Type = anyResourceType
|
2020-01-21 22:45:48 +00:00
|
|
|
)
|
|
|
|
|
2021-08-31 02:29:24 +00:00
|
|
|
// An InvalidType represents an invalid type with associated diagnostics.
|
|
|
|
type InvalidType struct {
|
|
|
|
Diagnostics hcl.Diagnostics
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *InvalidType) String() string {
|
|
|
|
return "Invalid"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*InvalidType) isType() {}
|
|
|
|
|
|
|
|
func invalidType(diags ...*hcl.Diagnostic) (Type, hcl.Diagnostics) {
|
|
|
|
t := &InvalidType{Diagnostics: hcl.Diagnostics(diags)}
|
|
|
|
return t, hcl.Diagnostics(diags)
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// MapType represents maps from strings to particular element types.
|
|
|
|
type MapType struct {
|
|
|
|
// ElementType is the element type of the map.
|
|
|
|
ElementType Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *MapType) String() string {
|
|
|
|
return fmt.Sprintf("Map<%v>", t.ElementType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*MapType) isType() {}
|
|
|
|
|
|
|
|
// ArrayType represents arrays of particular element types.
|
|
|
|
type ArrayType struct {
|
|
|
|
// ElementType is the element type of the array.
|
|
|
|
ElementType Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ArrayType) String() string {
|
|
|
|
return fmt.Sprintf("Array<%v>", t.ElementType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*ArrayType) isType() {}
|
|
|
|
|
2020-09-16 20:47:40 +00:00
|
|
|
// EnumType represents an enum.
|
|
|
|
type EnumType struct {
|
2022-06-23 23:27:44 +00:00
|
|
|
// PackageReference is the PackageReference that defines the resource.
|
|
|
|
PackageReference PackageReference
|
2020-09-16 20:47:40 +00:00
|
|
|
// Token is the type's Pulumi type token.
|
|
|
|
Token string
|
|
|
|
// Comment is the description of the type, if any.
|
|
|
|
Comment string
|
|
|
|
// Elements are the predefined enum values.
|
|
|
|
Elements []*Enum
|
|
|
|
// ElementType is the underlying type for the enum.
|
|
|
|
ElementType Type
|
2021-11-16 23:53:28 +00:00
|
|
|
|
|
|
|
// IsOverlay indicates whether the type is an overlay provided by the package. Overlay code is generated by the
|
|
|
|
// package rather than using the core Pulumi codegen libraries.
|
|
|
|
IsOverlay bool
|
2020-09-16 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enum contains information about an enum.
|
|
|
|
type Enum struct {
|
|
|
|
// Value is the value of the enum.
|
|
|
|
Value interface{}
|
|
|
|
// Comment is the description for the enum value.
|
|
|
|
Comment string
|
|
|
|
// Name for the enum.
|
|
|
|
Name string
|
2020-10-07 16:32:00 +00:00
|
|
|
// DeprecationMessage indicates whether or not the value is deprecated.
|
|
|
|
DeprecationMessage string
|
2020-09-16 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *EnumType) String() string {
|
|
|
|
return t.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*EnumType) isType() {}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// UnionType represents values that may be any one of a specified set of types.
|
|
|
|
type UnionType struct {
|
|
|
|
// ElementTypes are the allowable types for the union type.
|
|
|
|
ElementTypes []Type
|
2020-06-03 01:15:21 +00:00
|
|
|
// DefaultType is the default type, if any, for the union type. This can be used by targets that do not support
|
|
|
|
// unions, or in positions where unions are not appropriate.
|
|
|
|
DefaultType Type
|
2021-04-16 12:04:42 +00:00
|
|
|
// Discriminator informs the consumer of an alternative schema based on the value associated with it.
|
|
|
|
Discriminator string
|
|
|
|
// Mapping is an optional object to hold mappings between payload values and schema names or references.
|
|
|
|
Mapping map[string]string
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *UnionType) String() string {
|
2022-05-24 22:05:16 +00:00
|
|
|
elements := make([]string, len(t.ElementTypes))
|
2020-01-21 22:45:48 +00:00
|
|
|
for i, e := range t.ElementTypes {
|
|
|
|
elements[i] = e.String()
|
|
|
|
}
|
2020-06-03 01:15:21 +00:00
|
|
|
|
|
|
|
if t.DefaultType != nil {
|
2022-05-24 22:05:16 +00:00
|
|
|
elements = append(elements, "default="+t.DefaultType.String())
|
2020-06-03 01:15:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
return fmt.Sprintf("Union<%v>", strings.Join(elements, ", "))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*UnionType) isType() {}
|
|
|
|
|
|
|
|
// ObjectType represents schematized maps from strings to particular types.
|
|
|
|
type ObjectType struct {
|
2022-06-23 23:27:44 +00:00
|
|
|
// PackageReference is the PackageReference that defines the resource.
|
|
|
|
PackageReference PackageReference
|
2020-01-21 22:45:48 +00:00
|
|
|
// Token is the type's Pulumi type token.
|
|
|
|
Token string
|
|
|
|
// Comment is the description of the type, if any.
|
|
|
|
Comment string
|
|
|
|
// Properties is the list of the type's properties.
|
|
|
|
Properties []*Property
|
|
|
|
// Language specifies additional language-specific data about the object type.
|
2020-04-20 23:36:05 +00:00
|
|
|
Language map[string]interface{}
|
2021-11-12 00:00:03 +00:00
|
|
|
// IsOverlay indicates whether the type is an overlay provided by the package. Overlay code is generated by the
|
|
|
|
// package rather than using the core Pulumi codegen libraries.
|
|
|
|
IsOverlay bool
|
2024-07-09 14:54:50 +00:00
|
|
|
// OverlaySupportedLanguages indicates what languages the overlay supports. This only has an effect if
|
|
|
|
// the Resource is an Overlay (IsOverlay == true).
|
|
|
|
// Supported values are "nodejs", "python", "go", "csharp", "java", "yaml"
|
|
|
|
OverlaySupportedLanguages []string
|
2020-04-21 16:18:09 +00:00
|
|
|
|
2021-06-24 16:17:55 +00:00
|
|
|
// InputShape is the input shape for this object. Only valid if IsPlainShape returns true.
|
|
|
|
InputShape *ObjectType
|
|
|
|
// PlainShape is the plain shape for this object. Only valid if IsInputShape returns true.
|
|
|
|
PlainShape *ObjectType
|
|
|
|
|
2020-04-21 16:18:09 +00:00
|
|
|
properties map[string]*Property
|
|
|
|
}
|
|
|
|
|
2021-06-24 16:17:55 +00:00
|
|
|
// IsPlainShape returns true if this object type is the plain shape of a (plain, input)
|
|
|
|
// pair. The plain shape of an object does not contain *InputType values and only
|
|
|
|
// references other plain shapes.
|
|
|
|
func (t *ObjectType) IsPlainShape() bool {
|
|
|
|
return t.PlainShape == nil
|
|
|
|
}
|
|
|
|
|
2022-04-21 09:29:30 +00:00
|
|
|
// IsInputShape returns true if this object type is the input shape of a (plain, input)
|
2021-06-24 16:17:55 +00:00
|
|
|
// pair. The input shape of an object may contain *InputType values and may
|
|
|
|
// reference other input shapes.
|
|
|
|
func (t *ObjectType) IsInputShape() bool {
|
|
|
|
return t.PlainShape != nil
|
|
|
|
}
|
|
|
|
|
2020-04-21 16:18:09 +00:00
|
|
|
func (t *ObjectType) Property(name string) (*Property, bool) {
|
|
|
|
if t.properties == nil && len(t.Properties) > 0 {
|
|
|
|
t.properties = make(map[string]*Property)
|
|
|
|
for _, p := range t.Properties {
|
|
|
|
t.properties[p.Name] = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p, ok := t.properties[name]
|
|
|
|
return p, ok
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ObjectType) String() string {
|
2021-06-24 16:17:55 +00:00
|
|
|
if t.PlainShape != nil {
|
|
|
|
return t.Token + "•Input"
|
|
|
|
}
|
2020-01-21 22:45:48 +00:00
|
|
|
return t.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*ObjectType) isType() {}
|
|
|
|
|
2020-09-22 17:09:27 +00:00
|
|
|
type ResourceType struct {
|
|
|
|
// Token is the type's Pulumi type token.
|
|
|
|
Token string
|
2020-10-29 23:41:12 +00:00
|
|
|
// Resource is the type's underlying resource.
|
|
|
|
Resource *Resource
|
2020-09-22 17:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ResourceType) String() string {
|
|
|
|
return t.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *ResourceType) isType() {}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// TokenType represents an opaque type that is referred to only by its token. A TokenType may have an underlying type
|
|
|
|
// that can be used in place of the token.
|
|
|
|
type TokenType struct {
|
|
|
|
// Token is the type's Pulumi type token.
|
|
|
|
Token string
|
|
|
|
// Underlying type is the type's underlying type, if any.
|
|
|
|
UnderlyingType Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TokenType) String() string {
|
|
|
|
return t.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*TokenType) isType() {}
|
|
|
|
|
2021-06-24 16:17:55 +00:00
|
|
|
// InputType represents a type that accepts either a prompt value or an output value.
|
|
|
|
type InputType struct {
|
|
|
|
// ElementType is the element type of the input.
|
|
|
|
ElementType Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *InputType) String() string {
|
|
|
|
return fmt.Sprintf("Input<%v>", t.ElementType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*InputType) isType() {}
|
|
|
|
|
|
|
|
// OptionalType represents a type that accepts an optional value.
|
|
|
|
type OptionalType struct {
|
|
|
|
// ElementType is the element type of the input.
|
|
|
|
ElementType Type
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *OptionalType) String() string {
|
|
|
|
return fmt.Sprintf("Optional<%v>", t.ElementType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*OptionalType) isType() {}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// DefaultValue describes a default value for a property.
|
|
|
|
type DefaultValue struct {
|
|
|
|
// Value specifies a static default value, if any. This value must be representable in the Pulumi schema type
|
|
|
|
// system, and its type must be assignable to that of the property to which the default applies.
|
|
|
|
Value interface{}
|
|
|
|
// Environment specifies a set of environment variables to probe for a default value.
|
|
|
|
Environment []string
|
|
|
|
// Language specifies additional language-specific data about the default value.
|
2020-04-20 23:36:05 +00:00
|
|
|
Language map[string]interface{}
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Property describes an object or resource property.
|
|
|
|
type Property struct {
|
|
|
|
// Name is the name of the property.
|
|
|
|
Name string
|
|
|
|
// Comment is the description of the property, if any.
|
|
|
|
Comment string
|
|
|
|
// Type is the type of the property.
|
|
|
|
Type Type
|
2020-04-03 03:47:07 +00:00
|
|
|
// ConstValue is the constant value for the property, if any.
|
|
|
|
ConstValue interface{}
|
2020-01-21 22:45:48 +00:00
|
|
|
// DefaultValue is the default value for the property, if any.
|
|
|
|
DefaultValue *DefaultValue
|
2020-02-06 17:29:06 +00:00
|
|
|
// DeprecationMessage indicates whether or not the property is deprecated.
|
|
|
|
DeprecationMessage string
|
2020-01-21 22:45:48 +00:00
|
|
|
// Language specifies additional language-specific data about the property.
|
2020-04-20 23:36:05 +00:00
|
|
|
Language map[string]interface{}
|
2020-07-01 20:17:49 +00:00
|
|
|
// Secret is true if the property is secret (default false).
|
|
|
|
Secret bool
|
2021-09-08 05:23:30 +00:00
|
|
|
// ReplaceOnChanges specifies if the property is to be replaced instead of updated (default false).
|
|
|
|
ReplaceOnChanges bool
|
2022-05-17 20:59:47 +00:00
|
|
|
// WillReplaceOnChanges indicates that the provider will replace the resource when
|
|
|
|
// this property is changed. This property is used exclusively for docs.
|
|
|
|
WillReplaceOnChanges bool
|
|
|
|
Plain bool
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 16:17:55 +00:00
|
|
|
// IsRequired returns true if this property is required (i.e. its type is not Optional).
|
|
|
|
func (p *Property) IsRequired() bool {
|
|
|
|
_, optional := p.Type.(*OptionalType)
|
|
|
|
return !optional
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// Alias describes an alias for a Pulumi resource.
|
|
|
|
type Alias struct {
|
|
|
|
// Name is the "name" portion of the alias, if any.
|
|
|
|
Name *string
|
|
|
|
// Project is the "project" portion of the alias, if any.
|
|
|
|
Project *string
|
|
|
|
// Type is the "type" portion of the alias, if any.
|
|
|
|
Type *string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resource describes a Pulumi resource.
|
|
|
|
type Resource struct {
|
2022-06-23 23:27:44 +00:00
|
|
|
// PackageReference is the PackageReference that defines the resource.
|
|
|
|
PackageReference PackageReference
|
2020-01-21 22:45:48 +00:00
|
|
|
// Token is the resource's Pulumi type token.
|
|
|
|
Token string
|
|
|
|
// Comment is the description of the resource, if any.
|
|
|
|
Comment string
|
|
|
|
// IsProvider is true if the resource is a provider resource.
|
|
|
|
IsProvider bool
|
|
|
|
// InputProperties is the list of the resource's input properties.
|
|
|
|
InputProperties []*Property
|
|
|
|
// Properties is the list of the resource's output properties. This should be a superset of the input properties.
|
|
|
|
Properties []*Property
|
|
|
|
// StateInputs is the set of inputs used to get an existing resource, if any.
|
|
|
|
StateInputs *ObjectType
|
|
|
|
// Aliases is the list of aliases for the resource.
|
|
|
|
Aliases []*Alias
|
|
|
|
// DeprecationMessage indicates whether or not the resource is deprecated.
|
|
|
|
DeprecationMessage string
|
|
|
|
// Language specifies additional language-specific data about the resource.
|
2020-04-20 23:36:05 +00:00
|
|
|
Language map[string]interface{}
|
2020-09-24 00:23:46 +00:00
|
|
|
// IsComponent indicates whether the resource is a ComponentResource.
|
|
|
|
IsComponent bool
|
2021-06-10 16:47:25 +00:00
|
|
|
// Methods is the list of methods for the resource.
|
|
|
|
Methods []*Method
|
2021-11-12 00:00:03 +00:00
|
|
|
// IsOverlay indicates whether the type is an overlay provided by the package. Overlay code is generated by the
|
|
|
|
// package rather than using the core Pulumi codegen libraries.
|
|
|
|
IsOverlay bool
|
2024-07-09 14:54:50 +00:00
|
|
|
// OverlaySupportedLanguages indicates what languages the overlay supports. This only has an effect if
|
|
|
|
// the Resource is an Overlay (IsOverlay == true).
|
|
|
|
// Supported values are "nodejs", "python", "go", "csharp", "java", "yaml"
|
|
|
|
OverlaySupportedLanguages []string
|
2021-06-10 16:47:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 05:23:30 +00:00
|
|
|
// The set of resource paths where ReplaceOnChanges is true.
|
|
|
|
//
|
|
|
|
// For example, if you have the following resource struct:
|
|
|
|
//
|
|
|
|
// Resource A {
|
2022-09-14 02:12:02 +00:00
|
|
|
//
|
|
|
|
// Properties: {
|
|
|
|
// Object B {
|
|
|
|
// Object D: {
|
|
|
|
// ReplaceOnChanges: true
|
|
|
|
// }
|
|
|
|
// Object F: {}
|
|
|
|
// }
|
|
|
|
// Object C {
|
|
|
|
// ReplaceOnChanges: true
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2021-09-08 05:23:30 +00:00
|
|
|
//
|
|
|
|
// A.ReplaceOnChanges() == [[B, D], [C]]
|
|
|
|
func (r *Resource) ReplaceOnChanges() (changes [][]*Property, err []error) {
|
|
|
|
for _, p := range r.Properties {
|
|
|
|
if p.ReplaceOnChanges {
|
|
|
|
changes = append(changes, []*Property{p})
|
|
|
|
} else {
|
|
|
|
stack := map[string]struct{}{p.Type.String(): {}}
|
|
|
|
childChanges, errList := replaceOnChangesType(p.Type, &stack)
|
|
|
|
err = append(err, errList...)
|
|
|
|
|
|
|
|
for _, c := range childChanges {
|
|
|
|
changes = append(changes, append([]*Property{p}, c...))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i, e := range err {
|
2021-11-13 02:37:17 +00:00
|
|
|
err[i] = fmt.Errorf("Failed to genereate full `ReplaceOnChanges`: %w", e)
|
2021-09-08 05:23:30 +00:00
|
|
|
}
|
|
|
|
return changes, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func replaceOnChangesType(t Type, stack *map[string]struct{}) ([][]*Property, []error) {
|
|
|
|
var errTmp []error
|
|
|
|
if o, ok := t.(*OptionalType); ok {
|
|
|
|
return replaceOnChangesType(o.ElementType, stack)
|
|
|
|
} else if o, ok := t.(*ObjectType); ok {
|
|
|
|
changes := [][]*Property{}
|
|
|
|
err := []error{}
|
|
|
|
for _, p := range o.Properties {
|
|
|
|
if p.ReplaceOnChanges {
|
|
|
|
changes = append(changes, []*Property{p})
|
|
|
|
} else if _, ok := (*stack)[p.Type.String()]; !ok {
|
|
|
|
// We handle recursive objects
|
|
|
|
(*stack)[p.Type.String()] = struct{}{}
|
|
|
|
var object [][]*Property
|
|
|
|
object, errTmp = replaceOnChangesType(p.Type, stack)
|
|
|
|
err = append(err, errTmp...)
|
|
|
|
for _, path := range object {
|
|
|
|
changes = append(changes, append([]*Property{p}, path...))
|
|
|
|
}
|
|
|
|
|
|
|
|
delete(*stack, p.Type.String())
|
|
|
|
} else {
|
2021-11-13 02:37:17 +00:00
|
|
|
err = append(err, fmt.Errorf("Found recursive object %q", p.Name))
|
2021-09-08 05:23:30 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-10 21:56:56 +00:00
|
|
|
// We don't want to emit errors where replaceOnChanges is not used.
|
|
|
|
if len(changes) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2021-09-08 05:23:30 +00:00
|
|
|
return changes, err
|
|
|
|
} else if a, ok := t.(*ArrayType); ok {
|
|
|
|
// This looks for types internal to the array, not a property of the array.
|
|
|
|
return replaceOnChangesType(a.ElementType, stack)
|
|
|
|
} else if m, ok := t.(*MapType); ok {
|
|
|
|
// This looks for types internal to the map, not a property of the array.
|
|
|
|
return replaceOnChangesType(m.ElementType, stack)
|
|
|
|
}
|
2021-09-10 21:56:56 +00:00
|
|
|
return nil, nil
|
2021-09-08 05:23:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Joins the output of `ReplaceOnChanges` into property path names.
|
|
|
|
//
|
|
|
|
// For example, given an input [[B, D], [C]] where each property has a name
|
|
|
|
// equivalent to it's variable, this function should yield: ["B.D", "C"]
|
|
|
|
func PropertyListJoinToString(propertyList [][]*Property, nameConverter func(string) string) []string {
|
|
|
|
var nonOptional func(Type) Type
|
|
|
|
nonOptional = func(t Type) Type {
|
|
|
|
if o, ok := t.(*OptionalType); ok {
|
|
|
|
return nonOptional(o.ElementType)
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
out := make([]string, len(propertyList))
|
|
|
|
for i, p := range propertyList {
|
|
|
|
names := make([]string, len(p))
|
|
|
|
for j, n := range p {
|
|
|
|
if _, ok := nonOptional(n.Type).(*ArrayType); ok {
|
|
|
|
names[j] = nameConverter(n.Name) + "[*]"
|
|
|
|
} else if _, ok := nonOptional(n.Type).(*MapType); ok {
|
|
|
|
names[j] = nameConverter(n.Name) + ".*"
|
|
|
|
} else {
|
|
|
|
names[j] = nameConverter(n.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out[i] = strings.Join(names, ".")
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
2021-06-10 16:47:25 +00:00
|
|
|
type Method struct {
|
|
|
|
// Name is the name of the method.
|
|
|
|
Name string
|
|
|
|
// Function is the function definition for the method.
|
|
|
|
Function *Function
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Function describes a Pulumi function.
|
|
|
|
type Function struct {
|
2022-12-07 12:03:41 +00:00
|
|
|
// PackageReference is the PackageReference that defines the function.
|
|
|
|
PackageReference PackageReference
|
2020-01-21 22:45:48 +00:00
|
|
|
// Token is the function's Pulumi type token.
|
|
|
|
Token string
|
|
|
|
// Comment is the description of the function, if any.
|
|
|
|
Comment string
|
|
|
|
// Inputs is the bag of input values for the function, if any.
|
|
|
|
Inputs *ObjectType
|
2023-01-11 22:17:14 +00:00
|
|
|
// Determines whether the input bag should be treated as a single argument or as multiple arguments.
|
|
|
|
MultiArgumentInputs bool
|
2020-01-21 22:45:48 +00:00
|
|
|
// Outputs is the bag of output values for the function, if any.
|
|
|
|
Outputs *ObjectType
|
2023-01-11 22:17:14 +00:00
|
|
|
// The return type of the function, if any.
|
|
|
|
ReturnType Type
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
// The return type is plain and not wrapped in an Output.
|
|
|
|
ReturnTypePlain bool
|
2023-01-11 22:17:14 +00:00
|
|
|
// When InlineObjectAsReturnType is true, it means that the return type definition is defined inline
|
|
|
|
// as an object type that should be generated as a separate type and it is not
|
|
|
|
// a reference to a existing type in the schema.
|
|
|
|
InlineObjectAsReturnType bool
|
2020-01-21 22:45:48 +00:00
|
|
|
// DeprecationMessage indicates whether or not the function is deprecated.
|
|
|
|
DeprecationMessage string
|
|
|
|
// Language specifies additional language-specific data about the function.
|
2020-04-20 23:36:05 +00:00
|
|
|
Language map[string]interface{}
|
2021-06-10 16:47:25 +00:00
|
|
|
// IsMethod indicates whether the function is a method of a resource.
|
|
|
|
IsMethod bool
|
2021-11-12 00:00:03 +00:00
|
|
|
// IsOverlay indicates whether the function is an overlay provided by the package. Overlay code is generated by the
|
|
|
|
// package rather than using the core Pulumi codegen libraries.
|
|
|
|
IsOverlay bool
|
2024-07-09 14:54:50 +00:00
|
|
|
// OverlaySupportedLanguages indicates what languages the overlay supports. This only has an effect if
|
|
|
|
// the Resource is an Overlay (IsOverlay == true).
|
|
|
|
// Supported values are "nodejs", "python", "go", "csharp", "java", "yaml"
|
|
|
|
OverlaySupportedLanguages []string
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:17:14 +00:00
|
|
|
// NeedsOutputVersion determines if codegen should emit a ${fn}Output version that
|
|
|
|
// automatically accepts Inputs and returns ReturnType.
|
2022-05-23 22:44:35 +00:00
|
|
|
func (fun *Function) NeedsOutputVersion() bool {
|
|
|
|
// Skip functions that return no value. Arguably we could
|
|
|
|
// support them and return `Task`, but there are no such
|
|
|
|
// functions in `pulumi-azure-native` or `pulumi-aws` so we
|
|
|
|
// omit to simplify.
|
2023-10-02 12:53:06 +00:00
|
|
|
return fun.ReturnType != nil
|
2022-05-23 22:44:35 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 10:29:39 +00:00
|
|
|
// BaseProvider
|
|
|
|
type BaseProvider struct {
|
|
|
|
// Name is the name of the provider.
|
|
|
|
Name string
|
|
|
|
// Version is the version of the provider.
|
|
|
|
Version semver.Version
|
|
|
|
// PluginDownloadURL is the URL to use to acquire the provider plugin binary, if any.
|
|
|
|
PluginDownloadURL string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Parameterization struct {
|
|
|
|
BaseProvider BaseProvider
|
|
|
|
// Parameter is the parameter for the provider.
|
2024-07-10 15:36:05 +00:00
|
|
|
Parameter []byte
|
2024-07-02 10:29:39 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// Package describes a Pulumi package.
|
|
|
|
type Package struct {
|
Add SupportPack to schemas to write out in the new style (#15713)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
This adds a new flag to the schema metadata to tell codegen to use the
new proposed style of SDKs where we fill in versions and write go.mods
etc.
I've reworked pack to operate on packages assuming they're in this new
style. That is pack no longer has the responsibility to fill in any
version information.
This updates python and node codegen to write out SDKs in this new
style, and fixes their core libraries to still be buildable via pack.
There are two approaches to fixing those, I've chosen option 1 below but
could pretty easily rework for option 2.
1) Write the version information directly to the SDKs at the same time
as we edit the .version file. To simplify this I've added a new
'set-version.py' script that takes a version string an writes it to all
the relevant places (.version, package.json, etc).
2) Write "pack" in the language host to search up the directory tree for
the ".version" file and then fill in the version information as we we're
doing before with envvar tricks and copying and editing package.json.
I think 1 is simpler long term, but does force some amount of cleanup in
unrelated bits of the system right now (release makefiles need a small
edit). 2 is much more localised but keeps this complexity that
sdk/nodejs sdk/python aren't actually valid source modules.
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-03-22 09:25:46 +00:00
|
|
|
// True if this package should be written in the new style to support pack and conformance testing.
|
|
|
|
SupportPack bool
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
moduleFormat *regexp.Regexp
|
|
|
|
|
|
|
|
// Name is the unqualified name of the package (e.g. "aws", "azure", "gcp", "kubernetes". "random")
|
|
|
|
Name string
|
2021-10-27 19:53:09 +00:00
|
|
|
// DisplayName is the human-friendly name of the package.
|
|
|
|
DisplayName string
|
2020-01-21 22:45:48 +00:00
|
|
|
// Version is the version of the package.
|
|
|
|
Version *semver.Version
|
|
|
|
// Description is the description of the package.
|
|
|
|
Description string
|
|
|
|
// Keywords is the list of keywords that are associated with the package, if any.
|
2021-11-10 19:07:43 +00:00
|
|
|
// Some reserved keywords can be specified as well that help with categorizing the
|
|
|
|
// package in the Pulumi registry. `category/<name>` and `kind/<type>` are the only
|
|
|
|
// reserved keywords at this time, where `<name>` can be one of:
|
|
|
|
// `cloud`, `database`, `infrastructure`, `monitoring`, `network`, `utility`, `vcs`
|
|
|
|
// and `<type>` is either `native` or `component`. If the package is a bridged Terraform
|
|
|
|
// provider, then don't include the `kind/` label.
|
2020-01-21 22:45:48 +00:00
|
|
|
Keywords []string
|
|
|
|
// Homepage is the package's homepage.
|
|
|
|
Homepage string
|
|
|
|
// License indicates which license is used for the package's contents.
|
|
|
|
License string
|
2020-04-02 00:22:23 +00:00
|
|
|
// Attribution allows freeform text attribution of derived work, if needed.
|
|
|
|
Attribution string
|
2020-01-21 22:45:48 +00:00
|
|
|
// Repository is the URL at which the source for the package can be found.
|
|
|
|
Repository string
|
|
|
|
// LogoURL is the URL for the package's logo, if any.
|
|
|
|
LogoURL string
|
2020-07-02 16:25:49 +00:00
|
|
|
// PluginDownloadURL is the URL to use to acquire the provider plugin binary, if any.
|
|
|
|
PluginDownloadURL string
|
2021-10-27 19:53:09 +00:00
|
|
|
// Publisher is the name of the person or organization that authored and published the package.
|
|
|
|
Publisher string
|
2022-10-24 23:16:13 +00:00
|
|
|
// A list of allowed package name in addition to the Name property.
|
|
|
|
AllowedPackageNames []string
|
2020-01-21 22:45:48 +00:00
|
|
|
|
|
|
|
// Types is the list of non-resource types defined by the package.
|
|
|
|
Types []Type
|
|
|
|
// Config is the set of configuration properties defined by the package.
|
|
|
|
Config []*Property
|
|
|
|
// Provider is the resource provider for the package, if any.
|
|
|
|
Provider *Resource
|
|
|
|
// Resources is the list of resource types defined by the package.
|
|
|
|
Resources []*Resource
|
|
|
|
// Functions is the list of functions defined by the package.
|
|
|
|
Functions []*Function
|
|
|
|
// Language specifies additional language-specific data about the package.
|
2020-04-20 23:36:05 +00:00
|
|
|
Language map[string]interface{}
|
2020-07-07 21:45:18 +00:00
|
|
|
|
2024-07-02 10:29:39 +00:00
|
|
|
// Parameterization is the optional parameterization for the package, if any.
|
|
|
|
Parameterization *Parameterization
|
|
|
|
|
2020-10-29 23:41:12 +00:00
|
|
|
resourceTable map[string]*Resource
|
|
|
|
resourceTypeTable map[string]*ResourceType
|
|
|
|
functionTable map[string]*Function
|
|
|
|
typeTable map[string]Type
|
2021-07-16 14:50:35 +00:00
|
|
|
|
|
|
|
importedLanguages map[string]struct{}
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Language provides hooks for importing language-specific metadata in a package.
|
|
|
|
type Language interface {
|
|
|
|
// ImportDefaultSpec decodes language-specific metadata associated with a DefaultValue.
|
|
|
|
ImportDefaultSpec(def *DefaultValue, bytes json.RawMessage) (interface{}, error)
|
|
|
|
// ImportPropertySpec decodes language-specific metadata associated with a Property.
|
|
|
|
ImportPropertySpec(property *Property, bytes json.RawMessage) (interface{}, error)
|
|
|
|
// ImportObjectTypeSpec decodes language-specific metadata associated with a ObjectType.
|
|
|
|
ImportObjectTypeSpec(object *ObjectType, bytes json.RawMessage) (interface{}, error)
|
|
|
|
// ImportResourceSpec decodes language-specific metadata associated with a Resource.
|
|
|
|
ImportResourceSpec(resource *Resource, bytes json.RawMessage) (interface{}, error)
|
|
|
|
// ImportFunctionSpec decodes language-specific metadata associated with a Function.
|
|
|
|
ImportFunctionSpec(function *Function, bytes json.RawMessage) (interface{}, error)
|
|
|
|
// ImportPackageSpec decodes language-specific metadata associated with a Package.
|
|
|
|
ImportPackageSpec(pkg *Package, bytes json.RawMessage) (interface{}, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortedLanguageNames(metadata map[string]interface{}) []string {
|
2023-06-28 16:02:04 +00:00
|
|
|
names := slice.Prealloc[string](len(metadata))
|
2020-04-20 23:36:05 +00:00
|
|
|
for lang := range metadata {
|
|
|
|
names = append(names, lang)
|
|
|
|
}
|
|
|
|
sort.Strings(names)
|
|
|
|
return names
|
|
|
|
}
|
|
|
|
|
|
|
|
func importDefaultLanguages(def *DefaultValue, languages map[string]Language) error {
|
|
|
|
for _, name := range sortedLanguageNames(def.Language) {
|
|
|
|
val := def.Language[name]
|
|
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
|
|
if lang, ok := languages[name]; ok {
|
|
|
|
val, err := lang.ImportDefaultSpec(def, raw)
|
|
|
|
if err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing %v metadata: %w", name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
def.Language[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func importPropertyLanguages(property *Property, languages map[string]Language) error {
|
|
|
|
if property.DefaultValue != nil {
|
|
|
|
if err := importDefaultLanguages(property.DefaultValue, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing default value: %w", err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range sortedLanguageNames(property.Language) {
|
|
|
|
val := property.Language[name]
|
|
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
|
|
if lang, ok := languages[name]; ok {
|
|
|
|
val, err := lang.ImportPropertySpec(property, raw)
|
|
|
|
if err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing %v metadata: %w", name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
property.Language[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func importObjectTypeLanguages(object *ObjectType, languages map[string]Language) error {
|
|
|
|
for _, property := range object.Properties {
|
|
|
|
if err := importPropertyLanguages(property, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing property %v: %w", property.Name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range sortedLanguageNames(object.Language) {
|
|
|
|
val := object.Language[name]
|
|
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
|
|
if lang, ok := languages[name]; ok {
|
|
|
|
val, err := lang.ImportObjectTypeSpec(object, raw)
|
|
|
|
if err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing %v metadata: %w", name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
object.Language[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func importResourceLanguages(resource *Resource, languages map[string]Language) error {
|
|
|
|
for _, property := range resource.InputProperties {
|
|
|
|
if err := importPropertyLanguages(property, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing input property %v: %w", property.Name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, property := range resource.Properties {
|
|
|
|
if err := importPropertyLanguages(property, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing property %v: %w", property.Name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 22:42:31 +00:00
|
|
|
if resource.StateInputs != nil {
|
|
|
|
for _, property := range resource.StateInputs.Properties {
|
|
|
|
if err := importPropertyLanguages(property, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing state input property %v: %w", property.Name, err)
|
2020-04-22 22:42:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:36:05 +00:00
|
|
|
for _, name := range sortedLanguageNames(resource.Language) {
|
|
|
|
val := resource.Language[name]
|
|
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
|
|
if lang, ok := languages[name]; ok {
|
|
|
|
val, err := lang.ImportResourceSpec(resource, raw)
|
|
|
|
if err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing %v metadata: %w", name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
resource.Language[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func importFunctionLanguages(function *Function, languages map[string]Language) error {
|
|
|
|
if function.Inputs != nil {
|
|
|
|
if err := importObjectTypeLanguages(function.Inputs, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing inputs: %w", err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 22:17:14 +00:00
|
|
|
if function.ReturnType != nil {
|
|
|
|
if objectType, ok := function.ReturnType.(*ObjectType); ok && objectType != nil {
|
|
|
|
if err := importObjectTypeLanguages(objectType, languages); err != nil {
|
|
|
|
return fmt.Errorf("importing outputs: %w", err)
|
|
|
|
}
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range sortedLanguageNames(function.Language) {
|
|
|
|
val := function.Language[name]
|
|
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
|
|
if lang, ok := languages[name]; ok {
|
|
|
|
val, err := lang.ImportFunctionSpec(function, raw)
|
|
|
|
if err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing %v metadata: %w", name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
function.Language[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) ImportLanguages(languages map[string]Language) error {
|
2021-07-16 14:50:35 +00:00
|
|
|
if pkg.importedLanguages == nil {
|
|
|
|
pkg.importedLanguages = map[string]struct{}{}
|
|
|
|
}
|
|
|
|
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
found := false
|
2021-07-16 14:50:35 +00:00
|
|
|
for lang := range languages {
|
|
|
|
if _, ok := pkg.importedLanguages[lang]; !ok {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
found = true
|
2021-07-16 14:50:35 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
if !found {
|
2020-04-20 23:36:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range pkg.Types {
|
|
|
|
if object, ok := t.(*ObjectType); ok {
|
|
|
|
if err := importObjectTypeLanguages(object, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing object type %v: %w", object.Token, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, config := range pkg.Config {
|
|
|
|
if err := importPropertyLanguages(config, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing configuration property %v: %w", config.Name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if pkg.Provider != nil {
|
|
|
|
if err := importResourceLanguages(pkg.Provider, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing provider: %w", err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, resource := range pkg.Resources {
|
|
|
|
if err := importResourceLanguages(resource, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing resource %v: %w", resource.Token, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, function := range pkg.Functions {
|
|
|
|
if err := importFunctionLanguages(function, languages); err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing function %v: %w", function.Token, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range sortedLanguageNames(pkg.Language) {
|
|
|
|
val := pkg.Language[name]
|
|
|
|
if raw, ok := val.(json.RawMessage); ok {
|
|
|
|
if lang, ok := languages[name]; ok {
|
|
|
|
val, err := lang.ImportPackageSpec(pkg, raw)
|
|
|
|
if err != nil {
|
2021-11-13 02:37:17 +00:00
|
|
|
return fmt.Errorf("importing %v metadata: %w", name, err)
|
2020-04-20 23:36:05 +00:00
|
|
|
}
|
|
|
|
pkg.Language[name] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-16 14:50:35 +00:00
|
|
|
for lang := range languages {
|
|
|
|
pkg.importedLanguages[lang] = struct{}{}
|
|
|
|
}
|
|
|
|
|
2020-04-20 23:36:05 +00:00
|
|
|
return nil
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-25 00:47:43 +00:00
|
|
|
func packageIdentity(name string, version *semver.Version) string {
|
|
|
|
// The package's identity is its name and version (if any) separated buy a ':'. The ':' character is not allowed
|
|
|
|
// in package names and so is safe to use as a separator.
|
|
|
|
id := name + ":"
|
|
|
|
if version != nil {
|
|
|
|
return id + version.String()
|
|
|
|
}
|
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) Identity() string {
|
|
|
|
return packageIdentity(pkg.Name, pkg.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) Equals(other *Package) bool {
|
|
|
|
return pkg == other || pkg.Identity() == other.Identity()
|
|
|
|
}
|
|
|
|
|
2022-05-10 02:08:43 +00:00
|
|
|
var defaultModuleFormat = regexp.MustCompile("(.*)")
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
func (pkg *Package) TokenToModule(tok string) string {
|
|
|
|
// token := pkg ":" module ":" member
|
|
|
|
|
|
|
|
components := strings.Split(tok, ":")
|
|
|
|
if len(components) != 3 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-05-01 10:45:47 +00:00
|
|
|
switch components[1] {
|
|
|
|
case "providers":
|
2020-01-21 22:45:48 +00:00
|
|
|
return ""
|
2020-05-01 10:45:47 +00:00
|
|
|
default:
|
2024-01-24 15:33:42 +00:00
|
|
|
format := pkg.moduleFormat
|
|
|
|
if format == nil {
|
|
|
|
format = defaultModuleFormat
|
2021-07-16 14:50:35 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 15:33:42 +00:00
|
|
|
matches := format.FindStringSubmatch(components[1])
|
2020-11-19 20:56:28 +00:00
|
|
|
if len(matches) < 2 || strings.HasPrefix(matches[1], "index") {
|
2020-05-01 10:45:47 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return matches[1]
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 12:03:41 +00:00
|
|
|
func TokenToRuntimeModule(tok string) string {
|
2020-11-24 20:43:23 +00:00
|
|
|
// token := pkg ":" module ":" member
|
|
|
|
|
|
|
|
components := strings.Split(tok, ":")
|
|
|
|
if len(components) != 3 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return components[1]
|
|
|
|
}
|
|
|
|
|
2022-12-07 12:03:41 +00:00
|
|
|
func (pkg *Package) TokenToRuntimeModule(tok string) string {
|
|
|
|
return TokenToRuntimeModule(tok)
|
|
|
|
}
|
|
|
|
|
2020-07-07 21:45:18 +00:00
|
|
|
func (pkg *Package) GetResource(token string) (*Resource, bool) {
|
|
|
|
r, ok := pkg.resourceTable[token]
|
|
|
|
return r, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) GetFunction(token string) (*Function, bool) {
|
|
|
|
f, ok := pkg.functionTable[token]
|
|
|
|
return f, ok
|
|
|
|
}
|
|
|
|
|
2020-10-29 23:41:12 +00:00
|
|
|
func (pkg *Package) GetResourceType(token string) (*ResourceType, bool) {
|
|
|
|
t, ok := pkg.resourceTypeTable[token]
|
|
|
|
return t, ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) GetType(token string) (Type, bool) {
|
|
|
|
t, ok := pkg.typeTable[token]
|
|
|
|
return t, ok
|
|
|
|
}
|
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
func (pkg *Package) Reference() PackageReference {
|
|
|
|
return packageDefRef{pkg: pkg}
|
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
func (pkg *Package) MarshalSpec() (spec *PackageSpec, err error) {
|
2021-07-09 17:23:10 +00:00
|
|
|
version := ""
|
|
|
|
if pkg.Version != nil {
|
|
|
|
version = pkg.Version.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
var metadata *MetadataSpec
|
Add SupportPack to schemas to write out in the new style (#15713)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
This adds a new flag to the schema metadata to tell codegen to use the
new proposed style of SDKs where we fill in versions and write go.mods
etc.
I've reworked pack to operate on packages assuming they're in this new
style. That is pack no longer has the responsibility to fill in any
version information.
This updates python and node codegen to write out SDKs in this new
style, and fixes their core libraries to still be buildable via pack.
There are two approaches to fixing those, I've chosen option 1 below but
could pretty easily rework for option 2.
1) Write the version information directly to the SDKs at the same time
as we edit the .version file. To simplify this I've added a new
'set-version.py' script that takes a version string an writes it to all
the relevant places (.version, package.json, etc).
2) Write "pack" in the language host to search up the directory tree for
the ".version" file and then fill in the version information as we we're
doing before with envvar tricks and copying and editing package.json.
I think 1 is simpler long term, but does force some amount of cleanup in
unrelated bits of the system right now (release makefiles need a small
edit). 2 is much more localised but keeps this complexity that
sdk/nodejs sdk/python aren't actually valid source modules.
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-03-22 09:25:46 +00:00
|
|
|
if pkg.moduleFormat != nil || pkg.SupportPack {
|
|
|
|
metadata = &MetadataSpec{SupportPack: pkg.SupportPack}
|
|
|
|
if pkg.moduleFormat != nil {
|
|
|
|
metadata.ModuleFormat = pkg.moduleFormat.String()
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 10:29:39 +00:00
|
|
|
var parameterization *ParameterizationSpec
|
|
|
|
if pkg.Parameterization != nil {
|
|
|
|
parameterization = &ParameterizationSpec{
|
|
|
|
BaseProvider: BaseProviderSpec{
|
|
|
|
Name: pkg.Parameterization.BaseProvider.Name,
|
|
|
|
Version: pkg.Parameterization.BaseProvider.Version.String(),
|
|
|
|
PluginDownloadURL: pkg.Parameterization.BaseProvider.PluginDownloadURL,
|
|
|
|
},
|
|
|
|
Parameter: pkg.Parameterization.Parameter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
spec = &PackageSpec{
|
2022-10-24 23:16:13 +00:00
|
|
|
Name: pkg.Name,
|
|
|
|
Version: version,
|
|
|
|
DisplayName: pkg.DisplayName,
|
|
|
|
Publisher: pkg.Publisher,
|
|
|
|
Description: pkg.Description,
|
|
|
|
Keywords: pkg.Keywords,
|
|
|
|
Homepage: pkg.Homepage,
|
|
|
|
License: pkg.License,
|
|
|
|
Attribution: pkg.Attribution,
|
|
|
|
Repository: pkg.Repository,
|
|
|
|
LogoURL: pkg.LogoURL,
|
|
|
|
PluginDownloadURL: pkg.PluginDownloadURL,
|
|
|
|
Meta: metadata,
|
|
|
|
Types: map[string]ComplexTypeSpec{},
|
|
|
|
Resources: map[string]ResourceSpec{},
|
|
|
|
Functions: map[string]FunctionSpec{},
|
|
|
|
AllowedPackageNames: pkg.AllowedPackageNames,
|
2024-07-02 10:29:39 +00:00
|
|
|
Parameterization: parameterization,
|
2022-10-24 23:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lang, err := marshalLanguage(pkg.Language)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling package language: %w", err)
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
2022-10-24 23:16:13 +00:00
|
|
|
spec.Language = lang
|
2021-07-09 17:23:10 +00:00
|
|
|
|
2021-07-09 20:33:15 +00:00
|
|
|
spec.Config.Required, spec.Config.Variables, err = pkg.marshalProperties(pkg.Config, true)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling package config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
spec.Provider, err = pkg.marshalResource(pkg.Provider)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling provider: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range pkg.Types {
|
|
|
|
switch t := t.(type) {
|
|
|
|
case *ObjectType:
|
|
|
|
if t.IsInputShape() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-07-09 20:33:15 +00:00
|
|
|
// Use the input shape when marshaling in order to get the plain annotations right.
|
|
|
|
o, err := pkg.marshalObject(t.InputShape, false)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling type '%v': %w", t.Token, err)
|
|
|
|
}
|
|
|
|
spec.Types[t.Token] = o
|
|
|
|
case *EnumType:
|
|
|
|
spec.Types[t.Token] = pkg.marshalEnum(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, res := range pkg.Resources {
|
|
|
|
r, err := pkg.marshalResource(res)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling resource '%v': %w", res.Token, err)
|
|
|
|
}
|
|
|
|
spec.Resources[res.Token] = r
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, fn := range pkg.Functions {
|
|
|
|
f, err := pkg.marshalFunction(fn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling function '%v': %w", fn.Token, err)
|
|
|
|
}
|
|
|
|
spec.Functions[fn.Token] = f
|
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
return spec, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) MarshalJSON() ([]byte, error) {
|
|
|
|
spec, err := pkg.MarshalSpec()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
return jsonMarshal(spec)
|
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
func (pkg *Package) MarshalYAML() ([]byte, error) {
|
|
|
|
spec, err := pkg.MarshalSpec()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var b bytes.Buffer
|
|
|
|
enc := yaml.NewEncoder(&b)
|
|
|
|
enc.SetIndent(2)
|
|
|
|
if err := enc.Encode(spec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2021-11-16 23:53:28 +00:00
|
|
|
func (pkg *Package) marshalObjectData(comment string, properties []*Property, language map[string]interface{},
|
2024-07-09 14:54:50 +00:00
|
|
|
plain, isOverlay bool, overlaySupportedLanguages []string,
|
2023-03-03 16:36:39 +00:00
|
|
|
) (ObjectTypeSpec, error) {
|
2021-07-09 20:33:15 +00:00
|
|
|
required, props, err := pkg.marshalProperties(properties, plain)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return ObjectTypeSpec{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
lang, err := marshalLanguage(language)
|
|
|
|
if err != nil {
|
|
|
|
return ObjectTypeSpec{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return ObjectTypeSpec{
|
2024-07-09 14:54:50 +00:00
|
|
|
Description: comment,
|
|
|
|
Properties: props,
|
|
|
|
Type: "object",
|
|
|
|
Required: required,
|
|
|
|
Language: lang,
|
|
|
|
IsOverlay: isOverlay,
|
|
|
|
OverlaySupportedLanguages: overlaySupportedLanguages,
|
2021-07-09 17:23:10 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-07-09 20:33:15 +00:00
|
|
|
func (pkg *Package) marshalObject(t *ObjectType, plain bool) (ComplexTypeSpec, error) {
|
2024-07-09 14:54:50 +00:00
|
|
|
data, err := pkg.marshalObjectData(t.Comment, t.Properties, t.Language, plain, t.IsOverlay, nil)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return ComplexTypeSpec{}, err
|
|
|
|
}
|
|
|
|
return ComplexTypeSpec{ObjectTypeSpec: data}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) marshalEnum(t *EnumType) ComplexTypeSpec {
|
|
|
|
values := make([]EnumValueSpec, len(t.Elements))
|
|
|
|
for i, el := range t.Elements {
|
|
|
|
values[i] = EnumValueSpec{
|
|
|
|
Name: el.Name,
|
|
|
|
Description: el.Comment,
|
|
|
|
Value: el.Value,
|
|
|
|
DeprecationMessage: el.DeprecationMessage,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ComplexTypeSpec{
|
2023-09-12 18:34:40 +00:00
|
|
|
ObjectTypeSpec: ObjectTypeSpec{
|
|
|
|
Description: t.Comment,
|
|
|
|
Type: pkg.marshalType(t.ElementType, false).Type,
|
|
|
|
IsOverlay: t.IsOverlay,
|
|
|
|
},
|
|
|
|
Enum: values,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) marshalResource(r *Resource) (ResourceSpec, error) {
|
2024-07-09 14:54:50 +00:00
|
|
|
object, err := pkg.marshalObjectData(r.Comment, r.Properties, r.Language, true, r.IsOverlay,
|
|
|
|
r.OverlaySupportedLanguages)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return ResourceSpec{}, fmt.Errorf("marshaling properties: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-07-09 20:33:15 +00:00
|
|
|
requiredInputs, inputs, err := pkg.marshalProperties(r.InputProperties, false)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return ResourceSpec{}, fmt.Errorf("marshaling input properties: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var stateInputs *ObjectTypeSpec
|
|
|
|
if r.StateInputs != nil {
|
2021-07-09 20:33:15 +00:00
|
|
|
o, err := pkg.marshalObject(r.StateInputs, false)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return ResourceSpec{}, fmt.Errorf("marshaling state inputs: %w", err)
|
|
|
|
}
|
|
|
|
stateInputs = &o.ObjectTypeSpec
|
|
|
|
}
|
|
|
|
|
2023-06-28 16:02:04 +00:00
|
|
|
aliases := slice.Prealloc[AliasSpec](len(r.Aliases))
|
2021-07-09 17:23:10 +00:00
|
|
|
for _, a := range r.Aliases {
|
|
|
|
aliases = append(aliases, AliasSpec{
|
|
|
|
Name: a.Name,
|
|
|
|
Project: a.Project,
|
|
|
|
Type: a.Type,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var methods map[string]string
|
|
|
|
if len(r.Methods) != 0 {
|
|
|
|
methods = map[string]string{}
|
|
|
|
for _, m := range r.Methods {
|
|
|
|
methods[m.Name] = m.Function.Token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResourceSpec{
|
|
|
|
ObjectTypeSpec: object,
|
|
|
|
InputProperties: inputs,
|
|
|
|
RequiredInputs: requiredInputs,
|
|
|
|
StateInputs: stateInputs,
|
|
|
|
Aliases: aliases,
|
|
|
|
DeprecationMessage: r.DeprecationMessage,
|
|
|
|
IsComponent: r.IsComponent,
|
|
|
|
Methods: methods,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (pkg *Package) marshalFunction(f *Function) (FunctionSpec, error) {
|
|
|
|
var inputs *ObjectTypeSpec
|
|
|
|
if f.Inputs != nil {
|
2021-07-09 20:33:15 +00:00
|
|
|
ins, err := pkg.marshalObject(f.Inputs, true)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return FunctionSpec{}, fmt.Errorf("marshaling inputs: %w", err)
|
|
|
|
}
|
|
|
|
inputs = &ins.ObjectTypeSpec
|
|
|
|
}
|
2023-01-11 22:17:14 +00:00
|
|
|
var multiArgumentInputs []string
|
|
|
|
if f.MultiArgumentInputs {
|
|
|
|
multiArgumentInputs = make([]string, len(f.Inputs.Properties))
|
|
|
|
for i, prop := range f.Inputs.Properties {
|
|
|
|
multiArgumentInputs[i] = prop.Name
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
|
|
|
|
var outputs *ObjectTypeSpec
|
|
|
|
if f.Outputs != nil {
|
2021-07-09 20:33:15 +00:00
|
|
|
outs, err := pkg.marshalObject(f.Outputs, true)
|
2021-07-09 17:23:10 +00:00
|
|
|
if err != nil {
|
2022-11-09 16:30:08 +00:00
|
|
|
return FunctionSpec{}, fmt.Errorf("marshaling outputs: %w", err)
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
outputs = &outs.ObjectTypeSpec
|
|
|
|
}
|
|
|
|
|
2023-01-11 22:17:14 +00:00
|
|
|
var returnType *ReturnTypeSpec
|
|
|
|
if f.ReturnType != nil {
|
|
|
|
returnType = &ReturnTypeSpec{}
|
|
|
|
if objectType, ok := f.ReturnType.(*ObjectType); ok {
|
|
|
|
ret, err := pkg.marshalObject(objectType, true)
|
|
|
|
if err != nil {
|
|
|
|
return FunctionSpec{}, fmt.Errorf("marshaling object spec: %w", err)
|
|
|
|
}
|
|
|
|
returnType.ObjectTypeSpec = &ret.ObjectTypeSpec
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
if f.ReturnTypePlain {
|
|
|
|
returnType.ObjectTypeSpecIsPlain = true
|
|
|
|
}
|
2023-01-11 22:17:14 +00:00
|
|
|
} else {
|
|
|
|
typeSpec := pkg.marshalType(f.ReturnType, true)
|
|
|
|
returnType.TypeSpec = &typeSpec
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
if f.ReturnTypePlain {
|
|
|
|
returnType.TypeSpec.Plain = true
|
|
|
|
}
|
2023-01-11 22:17:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 17:23:10 +00:00
|
|
|
lang, err := marshalLanguage(f.Language)
|
|
|
|
if err != nil {
|
|
|
|
return FunctionSpec{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return FunctionSpec{
|
2024-07-09 14:54:50 +00:00
|
|
|
Description: f.Comment,
|
|
|
|
DeprecationMessage: f.DeprecationMessage,
|
|
|
|
IsOverlay: f.IsOverlay,
|
|
|
|
OverlaySupportedLanguages: f.OverlaySupportedLanguages,
|
|
|
|
Inputs: inputs,
|
|
|
|
MultiArgumentInputs: multiArgumentInputs,
|
|
|
|
Outputs: outputs,
|
|
|
|
ReturnType: returnType,
|
|
|
|
Language: lang,
|
2021-07-09 17:23:10 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-07-09 23:05:03 +00:00
|
|
|
func (pkg *Package) marshalProperties(props []*Property, plain bool) (required []string, specs map[string]PropertySpec,
|
2023-03-03 16:36:39 +00:00
|
|
|
err error,
|
|
|
|
) {
|
2021-07-09 17:23:10 +00:00
|
|
|
if len(props) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
specs = make(map[string]PropertySpec, len(props))
|
|
|
|
for _, p := range props {
|
|
|
|
typ := p.Type
|
|
|
|
if t, optional := typ.(*OptionalType); optional {
|
|
|
|
typ = t.ElementType
|
|
|
|
} else {
|
|
|
|
required = append(required, p.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
var defaultValue interface{}
|
|
|
|
var defaultSpec *DefaultSpec
|
|
|
|
if p.DefaultValue != nil {
|
|
|
|
defaultValue = p.DefaultValue.Value
|
|
|
|
if len(p.DefaultValue.Environment) != 0 || len(p.DefaultValue.Language) != 0 {
|
|
|
|
lang, err := marshalLanguage(p.DefaultValue.Language)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("property '%v': %w", p.Name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultSpec = &DefaultSpec{
|
|
|
|
Environment: p.DefaultValue.Environment,
|
|
|
|
Language: lang,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lang, err := marshalLanguage(p.Language)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("property '%v': %w", p.Name, err)
|
|
|
|
}
|
|
|
|
|
2023-11-27 11:05:03 +00:00
|
|
|
propertyType := pkg.marshalType(typ, plain)
|
2023-12-01 19:41:51 +00:00
|
|
|
propertyType.Plain = p.Plain
|
2021-07-09 17:23:10 +00:00
|
|
|
specs[p.Name] = PropertySpec{
|
2023-11-27 11:05:03 +00:00
|
|
|
TypeSpec: propertyType,
|
2023-07-18 13:13:17 +00:00
|
|
|
Description: p.Comment,
|
|
|
|
Const: p.ConstValue,
|
|
|
|
Default: defaultValue,
|
|
|
|
DefaultInfo: defaultSpec,
|
|
|
|
DeprecationMessage: p.DeprecationMessage,
|
|
|
|
Language: lang,
|
|
|
|
Secret: p.Secret,
|
|
|
|
ReplaceOnChanges: p.ReplaceOnChanges,
|
|
|
|
WillReplaceOnChanges: p.WillReplaceOnChanges,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return required, specs, nil
|
|
|
|
}
|
|
|
|
|
2021-07-09 20:33:15 +00:00
|
|
|
// marshalType marshals the given type into a TypeSpec. If plain is true, then the type is being marshaled within a
|
|
|
|
// plain type context (e.g. a resource output property or a function input/output object type), and therefore does not
|
|
|
|
// require `Plain` annotations (hence the odd-looking `Plain: !plain` fields below).
|
|
|
|
func (pkg *Package) marshalType(t Type, plain bool) TypeSpec {
|
2021-07-09 17:23:10 +00:00
|
|
|
switch t := t.(type) {
|
|
|
|
case *InputType:
|
2024-07-26 21:36:22 +00:00
|
|
|
el := pkg.marshalType(t.ElementType, false)
|
2021-07-09 17:23:10 +00:00
|
|
|
el.Plain = false
|
|
|
|
return el
|
|
|
|
case *ArrayType:
|
2021-07-09 20:33:15 +00:00
|
|
|
el := pkg.marshalType(t.ElementType, plain)
|
2021-07-09 17:23:10 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Type: "array",
|
|
|
|
Items: &el,
|
2021-07-09 20:33:15 +00:00
|
|
|
Plain: !plain,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
case *MapType:
|
2021-07-09 20:33:15 +00:00
|
|
|
el := pkg.marshalType(t.ElementType, plain)
|
2021-07-09 17:23:10 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Type: "object",
|
|
|
|
AdditionalProperties: &el,
|
2021-07-09 20:33:15 +00:00
|
|
|
Plain: !plain,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
case *UnionType:
|
|
|
|
oneOf := make([]TypeSpec, len(t.ElementTypes))
|
|
|
|
for i, el := range t.ElementTypes {
|
2021-07-09 20:33:15 +00:00
|
|
|
oneOf[i] = pkg.marshalType(el, plain)
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
defaultType := ""
|
|
|
|
if t.DefaultType != nil {
|
2021-07-09 20:33:15 +00:00
|
|
|
defaultType = pkg.marshalType(t.DefaultType, plain).Type
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var discriminator *DiscriminatorSpec
|
|
|
|
if t.Discriminator != "" {
|
|
|
|
discriminator = &DiscriminatorSpec{
|
|
|
|
PropertyName: t.Discriminator,
|
|
|
|
Mapping: t.Mapping,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TypeSpec{
|
|
|
|
Type: defaultType,
|
|
|
|
OneOf: oneOf,
|
|
|
|
Discriminator: discriminator,
|
2021-07-09 20:33:15 +00:00
|
|
|
Plain: !plain,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
case *ObjectType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: pkg.marshalTypeRef(t.PackageReference, "types", t.Token),
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case *EnumType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: pkg.marshalTypeRef(t.PackageReference, "types", t.Token),
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case *ResourceType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: pkg.marshalTypeRef(t.Resource.PackageReference, "resources", t.Token),
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case *TokenType:
|
|
|
|
var defaultType string
|
|
|
|
if t.UnderlyingType != nil {
|
2021-07-09 20:33:15 +00:00
|
|
|
defaultType = pkg.marshalType(t.UnderlyingType, plain).Type
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TypeSpec{
|
2024-07-26 21:36:22 +00:00
|
|
|
Type: defaultType,
|
|
|
|
Ref: pkg.marshalTypeRef(pkg.Reference(), "types", t.Token),
|
|
|
|
Plain: !plain,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
switch t {
|
|
|
|
case BoolType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Type: "boolean",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case StringType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Type: "string",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case IntType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Type: "integer",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case NumberType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Type: "number",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case AnyType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: "pulumi.json#/Any",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case ArchiveType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: "pulumi.json#/Archive",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case AssetType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: "pulumi.json#/Asset",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
case JSONType:
|
2024-07-26 21:36:22 +00:00
|
|
|
return TypeSpec{
|
|
|
|
Ref: "pulumi.json#/Json",
|
|
|
|
Plain: !plain,
|
|
|
|
}
|
2021-07-09 17:23:10 +00:00
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unexepcted type %v (%T)", t, t))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 09:39:50 +00:00
|
|
|
func (pkg *Package) marshalTypeRef(container PackageReference, section, token string) string {
|
2021-07-09 17:23:10 +00:00
|
|
|
token = url.PathEscape(token)
|
|
|
|
|
2022-12-09 09:39:50 +00:00
|
|
|
if p, err := container.Definition(); err == nil && p == pkg {
|
2021-07-09 17:23:10 +00:00
|
|
|
return fmt.Sprintf("#/%s/%s", section, token)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(schema): this isn't quite right--it doesn't handle schemas sourced from URLs--but it's good enough for now.
|
2023-05-23 13:50:23 +00:00
|
|
|
return fmt.Sprintf("/%s/v%v/schema.json#/%s/%s", container.Name(), container.Version(), section, token)
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
func marshalLanguage(lang map[string]interface{}) (map[string]RawMessage, error) {
|
2021-07-09 17:23:10 +00:00
|
|
|
if len(lang) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
result := map[string]RawMessage{}
|
2021-07-09 17:23:10 +00:00
|
|
|
for name, data := range lang {
|
|
|
|
bytes, err := jsonMarshal(data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("marshaling %v language data: %w", name, err)
|
|
|
|
}
|
2021-07-13 23:41:40 +00:00
|
|
|
result[name] = RawMessage(bytes)
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
func jsonMarshal(v interface{}) ([]byte, error) {
|
|
|
|
var b bytes.Buffer
|
|
|
|
enc := json.NewEncoder(&b)
|
|
|
|
enc.SetEscapeHTML(false)
|
|
|
|
enc.SetIndent("", " ")
|
|
|
|
if err := enc.Encode(v); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2021-07-13 23:41:40 +00:00
|
|
|
type RawMessage []byte
|
|
|
|
|
|
|
|
func (m RawMessage) MarshalJSON() ([]byte, error) {
|
|
|
|
return []byte(m), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *RawMessage) UnmarshalJSON(bytes []byte) error {
|
|
|
|
*m = make([]byte, len(bytes))
|
|
|
|
copy(*m, bytes)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m RawMessage) MarshalYAML() ([]byte, error) {
|
|
|
|
return []byte(m), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *RawMessage) UnmarshalYAML(node *yaml.Node) error {
|
|
|
|
var value interface{}
|
|
|
|
if err := node.Decode(&value); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
bytes, err := jsonMarshal(value)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*m = bytes
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// TypeSpec is the serializable form of a reference to a type.
|
|
|
|
type TypeSpec struct {
|
2023-03-28 20:24:41 +00:00
|
|
|
// Type is the primitive or composite type, if any. May be "boolean", "string", "integer", "number", "array", or
|
2020-01-21 22:45:48 +00:00
|
|
|
// "object".
|
2021-07-13 23:41:40 +00:00
|
|
|
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Ref is a reference to a type in this or another document. For example, the built-in Archive, Asset, and Any
|
|
|
|
// types are referenced as "pulumi.json#/Archive", "pulumi.json#/Asset", and "pulumi.json#/Any", respectively.
|
|
|
|
// A type from this document is referenced as "#/types/pulumi:type:token".
|
2020-10-29 23:41:12 +00:00
|
|
|
// A type from another document is referenced as "path#/types/pulumi:type:token", where path is of the form:
|
|
|
|
// "/provider/vX.Y.Z/schema.json" or "pulumi.json" or "http[s]://example.com/provider/vX.Y.Z/schema.json"
|
2020-09-22 17:09:27 +00:00
|
|
|
// A resource from this document is referenced as "#/resources/pulumi:type:token".
|
2020-10-29 23:41:12 +00:00
|
|
|
// A resource from another document is referenced as "path#/resources/pulumi:type:token", where path is of the form:
|
|
|
|
// "/provider/vX.Y.Z/schema.json" or "pulumi.json" or "http[s]://example.com/provider/vX.Y.Z/schema.json"
|
2021-07-13 23:41:40 +00:00
|
|
|
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// AdditionalProperties, if set, describes the element type of an "object" (i.e. a string -> value map).
|
2021-07-13 23:41:40 +00:00
|
|
|
AdditionalProperties *TypeSpec `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Items, if set, describes the element type of an array.
|
2021-07-13 23:41:40 +00:00
|
|
|
Items *TypeSpec `json:"items,omitempty" yaml:"items,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// OneOf indicates that values of the type may be one of any of the listed types.
|
2021-07-13 23:41:40 +00:00
|
|
|
OneOf []TypeSpec `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
|
2021-04-16 12:04:42 +00:00
|
|
|
// Discriminator informs the consumer of an alternative schema based on the value associated with it.
|
2021-07-13 23:41:40 +00:00
|
|
|
Discriminator *DiscriminatorSpec `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`
|
2021-06-24 16:17:55 +00:00
|
|
|
// Plain indicates that when used as an input, this type does not accept eventual values.
|
2021-07-13 23:41:40 +00:00
|
|
|
Plain bool `json:"plain,omitempty" yaml:"plain,omitempty"`
|
2021-04-16 12:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DiscriminatorSpec informs the consumer of an alternative schema based on the value associated with it.
|
|
|
|
type DiscriminatorSpec struct {
|
|
|
|
// PropertyName is the name of the property in the payload that will hold the discriminator value.
|
2021-07-13 23:41:40 +00:00
|
|
|
PropertyName string `json:"propertyName" yaml:"propertyName"`
|
2021-04-16 12:04:42 +00:00
|
|
|
// Mapping is an optional object to hold mappings between payload values and schema names or references.
|
2021-07-13 23:41:40 +00:00
|
|
|
Mapping map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 19:43:39 +00:00
|
|
|
// DefaultSpec is the serializable form of extra information about the default value for a property.
|
2020-01-21 22:45:48 +00:00
|
|
|
type DefaultSpec struct {
|
|
|
|
// Environment specifies a set of environment variables to probe for a default value.
|
2021-07-13 23:41:40 +00:00
|
|
|
Environment []string `json:"environment,omitempty" yaml:"environment,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Language specifies additional language-specific data about the default value.
|
2021-07-13 23:41:40 +00:00
|
|
|
Language map[string]RawMessage `json:"language,omitempty" yaml:"language,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PropertySpec is the serializable form of an object or resource property.
|
|
|
|
type PropertySpec struct {
|
2021-07-13 23:41:40 +00:00
|
|
|
TypeSpec `yaml:",inline"`
|
2020-01-21 22:45:48 +00:00
|
|
|
|
|
|
|
// Description is the description of the property, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
2020-04-03 03:47:07 +00:00
|
|
|
// Const is the constant value for the property, if any. The type of the value must be assignable to the type of
|
|
|
|
// the property.
|
2021-07-13 23:41:40 +00:00
|
|
|
Const interface{} `json:"const,omitempty" yaml:"const,omitempty"`
|
2020-02-05 19:43:39 +00:00
|
|
|
// Default is the default value for the property, if any. The type of the value must be assignable to the type of
|
|
|
|
// the property.
|
2021-07-13 23:41:40 +00:00
|
|
|
Default interface{} `json:"default,omitempty" yaml:"default,omitempty"`
|
2020-04-03 03:47:07 +00:00
|
|
|
// DefaultInfo contains additional information about the property's default value, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
DefaultInfo *DefaultSpec `json:"defaultInfo,omitempty" yaml:"defaultInfo,omitempty"`
|
2020-02-06 17:29:06 +00:00
|
|
|
// DeprecationMessage indicates whether or not the property is deprecated.
|
2021-07-13 23:41:40 +00:00
|
|
|
DeprecationMessage string `json:"deprecationMessage,omitempty" yaml:"deprecationMessage,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Language specifies additional language-specific data about the property.
|
2021-07-13 23:41:40 +00:00
|
|
|
Language map[string]RawMessage `json:"language,omitempty" yaml:"language,omitempty"`
|
2020-07-01 20:17:49 +00:00
|
|
|
// Secret specifies if the property is secret (default false).
|
2021-07-13 23:41:40 +00:00
|
|
|
Secret bool `json:"secret,omitempty" yaml:"secret,omitempty"`
|
2021-09-08 05:23:30 +00:00
|
|
|
// ReplaceOnChanges specifies if the property is to be replaced instead of updated (default false).
|
|
|
|
ReplaceOnChanges bool `json:"replaceOnChanges,omitempty" yaml:"replaceOnChanges,omitempty"`
|
2022-05-17 20:59:47 +00:00
|
|
|
// WillReplaceOnChanges indicates that the provider will replace the resource when
|
|
|
|
// this property is changed. This property is used exclusively for docs.
|
|
|
|
WillReplaceOnChanges bool `json:"willReplaceOnChanges,omitempty" yaml:"willReplaceOnChanges,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectTypeSpec is the serializable form of an object type.
|
|
|
|
type ObjectTypeSpec struct {
|
|
|
|
// Description is the description of the type, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
// Properties, if present, is a map from property name to PropertySpec that describes the type's properties.
|
2021-07-13 23:41:40 +00:00
|
|
|
Properties map[string]PropertySpec `json:"properties,omitempty" yaml:"properties,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
// Type must be "object" if this is an object type, or the underlying type for an enum.
|
2021-07-13 23:41:40 +00:00
|
|
|
Type string `json:"type,omitempty" yaml:"type,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
// Required, if present, is a list of the names of an object type's required properties. These properties must be set
|
|
|
|
// for inputs and will always be set for outputs.
|
2021-07-13 23:41:40 +00:00
|
|
|
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
|
2021-06-24 16:17:55 +00:00
|
|
|
// Plain, was a list of the names of an object type's plain properties. This property is ignored: instead, property
|
|
|
|
// types should be marked as plain where necessary.
|
2021-07-13 23:41:40 +00:00
|
|
|
Plain []string `json:"plain,omitempty" yaml:"plain,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Language specifies additional language-specific data about the type.
|
2021-07-13 23:41:40 +00:00
|
|
|
Language map[string]RawMessage `json:"language,omitempty" yaml:"language,omitempty"`
|
2021-11-12 00:00:03 +00:00
|
|
|
// IsOverlay indicates whether the type is an overlay provided by the package. Overlay code is generated by the
|
|
|
|
// package rather than using the core Pulumi codegen libraries.
|
|
|
|
IsOverlay bool `json:"isOverlay,omitempty" yaml:"isOverlay,omitempty"`
|
2024-07-09 14:54:50 +00:00
|
|
|
// OverlaySupportedLanguages indicates what languages the overlay supports. This only has an effect if
|
|
|
|
// the Resource is an Overlay (IsOverlay == true).
|
|
|
|
// Supported values are "nodejs", "python", "go", "csharp", "java", "yaml"
|
|
|
|
OverlaySupportedLanguages []string `json:"overlaySupportedLanguages,omitempty" yaml:"overlaySupportedLanguages,omitempty"` //nolint:lll
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 20:47:40 +00:00
|
|
|
// ComplexTypeSpec is the serializable form of an object or enum type.
|
|
|
|
type ComplexTypeSpec struct {
|
2021-07-13 23:41:40 +00:00
|
|
|
ObjectTypeSpec `yaml:",inline"`
|
2020-09-16 20:47:40 +00:00
|
|
|
|
2020-11-03 07:02:56 +00:00
|
|
|
// Enum, if present, is the list of possible values for an enum type.
|
2021-07-13 23:41:40 +00:00
|
|
|
Enum []EnumValueSpec `json:"enum,omitempty" yaml:"enum,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
2024-04-16 07:21:22 +00:00
|
|
|
// EnumValueSpec is the serializable form of the values metadata associated with an enum type.
|
2020-09-16 20:47:40 +00:00
|
|
|
type EnumValueSpec struct {
|
|
|
|
// Name, if present, overrides the name of the enum value that would usually be derived from the value.
|
2021-07-13 23:41:40 +00:00
|
|
|
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
// Description of the enum value.
|
2021-07-13 23:41:40 +00:00
|
|
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
// Value is the enum value itself.
|
2021-07-13 23:41:40 +00:00
|
|
|
Value interface{} `json:"value" yaml:"value"`
|
2020-10-07 16:32:00 +00:00
|
|
|
// DeprecationMessage indicates whether or not the value is deprecated.
|
2021-07-13 23:41:40 +00:00
|
|
|
DeprecationMessage string `json:"deprecationMessage,omitempty" yaml:"deprecationMessage,omitempty"`
|
2020-09-16 20:47:40 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// AliasSpec is the serializable form of an alias description.
|
|
|
|
type AliasSpec struct {
|
|
|
|
// Name is the name portion of the alias, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Project is the project portion of the alias, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Project *string `json:"project,omitempty" yaml:"project,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Type is the type portion of the alias, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Type *string `json:"type,omitempty" yaml:"type,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResourceSpec is the serializable form of a resource description.
|
|
|
|
type ResourceSpec struct {
|
2021-07-13 23:41:40 +00:00
|
|
|
ObjectTypeSpec `yaml:",inline"`
|
2020-01-21 22:45:48 +00:00
|
|
|
|
|
|
|
// InputProperties is a map from property name to PropertySpec that describes the resource's input properties.
|
2021-07-13 23:41:40 +00:00
|
|
|
InputProperties map[string]PropertySpec `json:"inputProperties,omitempty" yaml:"inputProperties,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// RequiredInputs is a list of the names of the resource's required input properties.
|
2021-07-13 23:41:40 +00:00
|
|
|
RequiredInputs []string `json:"requiredInputs,omitempty" yaml:"requiredInputs,omitempty"`
|
2021-06-24 16:17:55 +00:00
|
|
|
// PlainInputs was a list of the names of the resource's plain input properties. This property is ignored:
|
|
|
|
// instead, property types should be marked as plain where necessary.
|
2021-07-13 23:41:40 +00:00
|
|
|
PlainInputs []string `json:"plainInputs,omitempty" yaml:"plainInputs,omitempty"`
|
2024-08-07 13:23:32 +00:00
|
|
|
// StateInputs is an optional ObjectTypeSpec that describes additional inputs that may be necessary to get an
|
2020-01-21 22:45:48 +00:00
|
|
|
// existing resource. If this is unset, only an ID is necessary.
|
2021-07-13 23:41:40 +00:00
|
|
|
StateInputs *ObjectTypeSpec `json:"stateInputs,omitempty" yaml:"stateInputs,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Aliases is the list of aliases for the resource.
|
2021-07-13 23:41:40 +00:00
|
|
|
Aliases []AliasSpec `json:"aliases,omitempty" yaml:"aliases,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// DeprecationMessage indicates whether or not the resource is deprecated.
|
2021-07-13 23:41:40 +00:00
|
|
|
DeprecationMessage string `json:"deprecationMessage,omitempty" yaml:"deprecationMessage,omitempty"`
|
2020-09-24 00:23:46 +00:00
|
|
|
// IsComponent indicates whether the resource is a ComponentResource.
|
2021-07-13 23:41:40 +00:00
|
|
|
IsComponent bool `json:"isComponent,omitempty" yaml:"isComponent,omitempty"`
|
2021-06-10 16:47:25 +00:00
|
|
|
// Methods maps method names to functions in this schema.
|
2021-07-13 23:41:40 +00:00
|
|
|
Methods map[string]string `json:"methods,omitempty" yaml:"methods,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
// ReturnTypeSpec is either ObjectTypeSpec or TypeSpec.
|
2023-01-11 22:17:14 +00:00
|
|
|
type ReturnTypeSpec struct {
|
|
|
|
ObjectTypeSpec *ObjectTypeSpec
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
|
|
|
|
// If ObjectTypeSpec is non-nil, it can also be marked with ObjectTypeSpecIsPlain: true
|
|
|
|
// indicating that the generated code should not wrap in the result in an Output but return
|
|
|
|
// it directly. This option is incompatible with marking individual properties with
|
|
|
|
// ObjectTypSpec.Plain.
|
|
|
|
ObjectTypeSpecIsPlain bool
|
|
|
|
|
|
|
|
TypeSpec *TypeSpec
|
|
|
|
}
|
|
|
|
|
|
|
|
type returnTypeSpecObjectSerialForm struct {
|
|
|
|
ObjectTypeSpec
|
|
|
|
Plain any `json:"plain,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (returnTypeSpec *ReturnTypeSpec) marshalJSONLikeObject() (map[string]interface{}, error) {
|
|
|
|
ts := returnTypeSpec
|
|
|
|
bytes, err := ts.MarshalJSON()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r map[string]interface{}
|
|
|
|
if err := json.Unmarshal(bytes, &r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return r, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (returnTypeSpec *ReturnTypeSpec) MarshalJSON() ([]byte, error) {
|
|
|
|
ts := returnTypeSpec
|
|
|
|
if ts.ObjectTypeSpec != nil {
|
|
|
|
form := returnTypeSpecObjectSerialForm{
|
|
|
|
ObjectTypeSpec: *ts.ObjectTypeSpec,
|
|
|
|
}
|
|
|
|
if ts.ObjectTypeSpecIsPlain {
|
|
|
|
form.Plain = true
|
|
|
|
} else if len(ts.ObjectTypeSpec.Plain) > 0 {
|
|
|
|
form.Plain = ts.ObjectTypeSpec.Plain
|
|
|
|
}
|
|
|
|
return json.Marshal(form)
|
|
|
|
}
|
|
|
|
return json.Marshal(ts.TypeSpec)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (returnTypeSpec *ReturnTypeSpec) UnmarshalJSON(inputJSON []byte) error {
|
|
|
|
ts := returnTypeSpec
|
|
|
|
var m returnTypeSpecObjectSerialForm
|
|
|
|
err := json.Unmarshal(inputJSON, &m)
|
|
|
|
if err == nil {
|
|
|
|
if m.ObjectTypeSpec.Properties != nil {
|
|
|
|
ts.ObjectTypeSpec = &m.ObjectTypeSpec
|
|
|
|
if plain, ok := m.Plain.(bool); ok && plain {
|
|
|
|
ts.ObjectTypeSpecIsPlain = true
|
|
|
|
}
|
|
|
|
if plain, ok := m.Plain.([]interface{}); ok {
|
|
|
|
for _, p := range plain {
|
|
|
|
if ps, ok := p.(string); ok {
|
|
|
|
ts.ObjectTypeSpec.Plain = append(ts.ObjectTypeSpec.Plain, ps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return json.Unmarshal(inputJSON, &ts.TypeSpec)
|
2023-01-11 22:17:14 +00:00
|
|
|
}
|
|
|
|
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
// Deprecated.
|
2023-01-11 22:17:14 +00:00
|
|
|
type Decoder func([]byte, interface{}) error
|
|
|
|
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
// Deprecated.
|
2023-01-11 22:17:14 +00:00
|
|
|
func (returnTypeSpec *ReturnTypeSpec) UnmarshalReturnTypeSpec(data []byte, decode Decoder) error {
|
|
|
|
var objectMap map[string]interface{}
|
|
|
|
if err := decode(data, &objectMap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(objectMap) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
inputJSON, err := json.Marshal(objectMap)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2023-01-11 22:17:14 +00:00
|
|
|
}
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
return returnTypeSpec.UnmarshalJSON(inputJSON)
|
2023-01-11 22:17:14 +00:00
|
|
|
}
|
|
|
|
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
// Deprecated.
|
2023-01-11 22:17:14 +00:00
|
|
|
func (returnTypeSpec *ReturnTypeSpec) UnmarshalYAML(inputYAML []byte) error {
|
|
|
|
return returnTypeSpec.UnmarshalReturnTypeSpec(inputYAML, yaml.Unmarshal)
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// FunctionSpec is the serializable form of a function description.
|
|
|
|
type FunctionSpec struct {
|
|
|
|
// Description is the description of the function, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Inputs is the bag of input values for the function, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
Inputs *ObjectTypeSpec `json:"inputs,omitempty" yaml:"inputs,omitempty"`
|
2023-01-11 22:17:14 +00:00
|
|
|
// Determines whether the input bag should be treated as a single argument or as multiple arguments.
|
|
|
|
// When MultiArgumentInputs is non-empty, it must match up 1:1 with the property names in of the Inputs object.
|
|
|
|
// The order in which the properties are listed in MultiArgumentInputs determines the order in which the
|
|
|
|
// arguments are passed to the function.
|
|
|
|
MultiArgumentInputs []string `json:"multiArgumentInputs,omitempty" yaml:"multiArgumentInputs,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Outputs is the bag of output values for the function, if any.
|
2023-01-11 22:17:14 +00:00
|
|
|
// This field is DEPRECATED. Use ReturnType instead where it allows for more flexible types
|
|
|
|
// to describe the outputs of the function definition. It is invalid to specify both Outputs and ReturnType.
|
2022-12-21 01:47:29 +00:00
|
|
|
Outputs *ObjectTypeSpec `json:"outputs,omitempty" yaml:"outputs,omitempty"`
|
2023-01-11 22:17:14 +00:00
|
|
|
// Specified the return type of the function definition
|
|
|
|
ReturnType *ReturnTypeSpec
|
|
|
|
// DeprecationMessage indicates whether the function is deprecated.
|
2021-07-13 23:41:40 +00:00
|
|
|
DeprecationMessage string `json:"deprecationMessage,omitempty" yaml:"deprecationMessage,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Language specifies additional language-specific data about the function.
|
2021-07-13 23:41:40 +00:00
|
|
|
Language map[string]RawMessage `json:"language,omitempty" yaml:"language,omitempty"`
|
2021-11-12 00:00:03 +00:00
|
|
|
// IsOverlay indicates whether the function is an overlay provided by the package. Overlay code is generated by the
|
|
|
|
// package rather than using the core Pulumi codegen libraries.
|
|
|
|
IsOverlay bool `json:"isOverlay,omitempty" yaml:"isOverlay,omitempty"`
|
2024-07-09 14:54:50 +00:00
|
|
|
// OverlaySupportedLanguages indicates what languages the overlay supports. This only has an effect if
|
|
|
|
// the Resource is an Overlay (IsOverlay == true).
|
|
|
|
// Supported values are "nodejs", "python", "go", "csharp", "java", "yaml"
|
|
|
|
OverlaySupportedLanguages []string `json:"overlaySupportedLanguages,omitempty" yaml:"overlaySupportedLanguages,omitempty"` //nolint:lll
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:17:14 +00:00
|
|
|
func emptyObject(data RawMessage) (bool, error) {
|
|
|
|
var objectData *map[string]RawMessage
|
|
|
|
if err := json.Unmarshal(data, &objectData); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if objectData == nil {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(*objectData) == 0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func unmarshalFunctionSpec(funcSpec *FunctionSpec, data map[string]RawMessage) error {
|
|
|
|
if description, ok := data["description"]; ok {
|
|
|
|
if err := json.Unmarshal(description, &funcSpec.Description); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if inputs, ok := data["inputs"]; ok {
|
|
|
|
if err := json.Unmarshal(inputs, &funcSpec.Inputs); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if multiArgumentInputs, ok := data["multiArgumentInputs"]; ok {
|
|
|
|
if err := json.Unmarshal(multiArgumentInputs, &funcSpec.MultiArgumentInputs); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if returnType, ok := data["outputs"]; ok {
|
|
|
|
isEmpty, err := emptyObject(returnType)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isEmpty {
|
|
|
|
if err := json.Unmarshal(returnType, &funcSpec.ReturnType); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
funcSpec.ReturnType = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if deprecationMessage, ok := data["deprecationMessage"]; ok {
|
|
|
|
if err := json.Unmarshal(deprecationMessage, &funcSpec.DeprecationMessage); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if language, ok := data["language"]; ok {
|
|
|
|
if err := json.Unmarshal(language, &funcSpec.Language); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if isOverlay, ok := data["isOverlay"]; ok {
|
|
|
|
if err := json.Unmarshal(isOverlay, &funcSpec.IsOverlay); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-09 14:54:50 +00:00
|
|
|
if overlaySupportedLanguages, ok := data["overlaySupportedLanguages"]; ok {
|
|
|
|
if err := json.Unmarshal(overlaySupportedLanguages, &funcSpec.OverlaySupportedLanguages); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-11 22:17:14 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON is custom unmarshalling logic for FunctionSpec so that we can derive Outputs from ReturnType
|
|
|
|
// which otherwise isn't possible when both are retrieved from the same JSON field
|
|
|
|
func (funcSpec *FunctionSpec) UnmarshalJSON(inputJSON []byte) error {
|
|
|
|
var data map[string]RawMessage
|
|
|
|
if err := json.Unmarshal(inputJSON, &data); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return unmarshalFunctionSpec(funcSpec, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML is custom unmarshalling logic for FunctionSpec so that we can derive Outputs from ReturnType
|
|
|
|
// which otherwise isn't possible when both are retrieved from the same JSON field
|
|
|
|
func (funcSpec *FunctionSpec) UnmarshalYAML(node *yaml.Node) error {
|
|
|
|
var data map[string]RawMessage
|
|
|
|
if err := node.Decode(&data); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return unmarshalFunctionSpec(funcSpec, data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (funcSpec FunctionSpec) marshalFunctionSpec() (map[string]interface{}, error) {
|
|
|
|
data := make(map[string]interface{})
|
|
|
|
if funcSpec.Description != "" {
|
|
|
|
data["description"] = funcSpec.Description
|
|
|
|
}
|
|
|
|
|
|
|
|
if funcSpec.Inputs != nil {
|
|
|
|
data["inputs"] = funcSpec.Inputs
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(funcSpec.MultiArgumentInputs) > 0 {
|
|
|
|
data["multiArgumentInputs"] = funcSpec.MultiArgumentInputs
|
|
|
|
}
|
|
|
|
|
|
|
|
if funcSpec.ReturnType != nil {
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
rto, err := funcSpec.ReturnType.marshalJSONLikeObject()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-01-11 22:17:14 +00:00
|
|
|
}
|
Support returning plain values from methods (#13592)
Support returning plain values from methods.
Implements Node, Python and Go support.
Remaining:
- [x] test receiving unknowns
- [x] acceptance tests written and passing locally for Node, Python, Go
clients against a Go server
- [x] acceptance tests passing in CI
- [x] tickets filed for remaining languages
- [x] https://github.com/pulumi/pulumi-yaml/issues/499
- [x] https://github.com/pulumi/pulumi-java/issues/1193
- [x] https://github.com/pulumi/pulumi-dotnet/issues/170
Known limitations:
- this is technically a breaking change in case there is code out there
that already uses methods that return Plain: true
- struct-wrapping limitation: the provider for the component resource
needs to still wrap the plain-returning Method response with a 1-arg
struct; by convention the field is named "res", and this is how it
travels through the plumbing
- resources cannot return plain values yet
- the provider for the component resource cannot have unknown
configuration, if it does, the methods will not be called
- Per Luke https://github.com/pulumi/pulumi/issues/11520 this might not
be supported/realizable yet
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
Fixes https://github.com/pulumi/pulumi/issues/12709
## Checklist
- [ ] I have run `make tidy` to update any new dependencies
- [ ] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2023-11-18 06:02:06 +00:00
|
|
|
data["outputs"] = rto
|
2023-01-11 22:17:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// for backward-compat when we only specify the outputs object of the function
|
|
|
|
if funcSpec.ReturnType == nil && funcSpec.Outputs != nil {
|
|
|
|
data["outputs"] = funcSpec.Outputs
|
|
|
|
}
|
|
|
|
|
|
|
|
if funcSpec.DeprecationMessage != "" {
|
|
|
|
data["deprecationMessage"] = funcSpec.DeprecationMessage
|
|
|
|
}
|
|
|
|
|
|
|
|
if funcSpec.IsOverlay {
|
|
|
|
// the default is false, so only write the property when it is true
|
|
|
|
data["isOverlay"] = true
|
|
|
|
}
|
|
|
|
|
2024-07-09 14:54:50 +00:00
|
|
|
if len(funcSpec.OverlaySupportedLanguages) > 0 {
|
|
|
|
// by default it supports all languages the provider supports, so only write the property when it is not the default
|
|
|
|
data["overlaySupportedLanguages"] = funcSpec.OverlaySupportedLanguages
|
|
|
|
}
|
|
|
|
|
2024-08-28 07:57:38 +00:00
|
|
|
if len(funcSpec.Language) > 0 {
|
2023-01-11 22:17:14 +00:00
|
|
|
data["language"] = funcSpec.Language
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (funcSpec FunctionSpec) MarshalJSON() ([]byte, error) {
|
|
|
|
data, err := funcSpec.marshalFunctionSpec()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return json.Marshal(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (funcSpec FunctionSpec) MarshalYAML() (interface{}, error) {
|
|
|
|
return funcSpec.marshalFunctionSpec()
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// ConfigSpec is the serializable description of a package's configuration variables.
|
|
|
|
type ConfigSpec struct {
|
|
|
|
// Variables is a map from variable name to PropertySpec that describes a package's configuration variables.
|
2021-07-13 23:41:40 +00:00
|
|
|
Variables map[string]PropertySpec `json:"variables,omitempty" yaml:"variables,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Required is a list of the names of the package's required configuration variables.
|
2021-07-13 23:41:40 +00:00
|
|
|
Required []string `json:"defaults,omitempty" yaml:"defaults,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MetadataSpec contains information for the importer about this package.
|
|
|
|
type MetadataSpec struct {
|
|
|
|
// ModuleFormat is a regex that is used by the importer to extract a module name from the module portion of a
|
2020-09-16 20:47:40 +00:00
|
|
|
// type token. Packages that use the module format "namespace1/namespace2/.../namespaceN" do not need to specify
|
2020-01-21 22:45:48 +00:00
|
|
|
// a format. The regex must define one capturing group that contains the module name, which must be formatted as
|
|
|
|
// "namespace1/namespace2/...namespaceN".
|
2021-07-13 23:41:40 +00:00
|
|
|
ModuleFormat string `json:"moduleFormat,omitempty" yaml:"moduleFormat,omitempty"`
|
Add SupportPack to schemas to write out in the new style (#15713)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
This adds a new flag to the schema metadata to tell codegen to use the
new proposed style of SDKs where we fill in versions and write go.mods
etc.
I've reworked pack to operate on packages assuming they're in this new
style. That is pack no longer has the responsibility to fill in any
version information.
This updates python and node codegen to write out SDKs in this new
style, and fixes their core libraries to still be buildable via pack.
There are two approaches to fixing those, I've chosen option 1 below but
could pretty easily rework for option 2.
1) Write the version information directly to the SDKs at the same time
as we edit the .version file. To simplify this I've added a new
'set-version.py' script that takes a version string an writes it to all
the relevant places (.version, package.json, etc).
2) Write "pack" in the language host to search up the directory tree for
the ".version" file and then fill in the version information as we we're
doing before with envvar tricks and copying and editing package.json.
I think 1 is simpler long term, but does force some amount of cleanup in
unrelated bits of the system right now (release makefiles need a small
edit). 2 is much more localised but keeps this complexity that
sdk/nodejs sdk/python aren't actually valid source modules.
## Checklist
- [x] I have run `make tidy` to update any new dependencies
- [x] I have run `make lint` to verify my code passes the lint check
- [x] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [x] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-03-22 09:25:46 +00:00
|
|
|
|
|
|
|
// SupportPack indicates whether or not the package is written to support the pack command. This causes versions to
|
|
|
|
// be written out, plugin.json files to be filled in, and package metadata to be written to the directory.
|
|
|
|
// This defaults to false currently, but conformance testing _always_ turns it on.
|
|
|
|
SupportPack bool `json:"supportPack,omitempty" yaml:"supportPack,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
// PackageInfoSpec is the serializable description of a Pulumi package's metadata.
|
|
|
|
type PackageInfoSpec struct {
|
|
|
|
// Name is the unqualified name of the package (e.g. "aws", "azure", "gcp", "kubernetes", "random")
|
|
|
|
Name string `json:"name" yaml:"name"`
|
|
|
|
// DisplayName is the human-friendly name of the package.
|
|
|
|
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`
|
|
|
|
// Version is the version of the package. The version must be valid semver.
|
|
|
|
Version string `json:"version,omitempty" yaml:"version,omitempty"`
|
|
|
|
// Description is the description of the package.
|
|
|
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
|
|
|
// Keywords is the list of keywords that are associated with the package, if any.
|
|
|
|
// Some reserved keywords can be specified as well that help with categorizing the
|
|
|
|
// package in the Pulumi registry. `category/<name>` and `kind/<type>` are the only
|
|
|
|
// reserved keywords at this time, where `<name>` can be one of:
|
|
|
|
// `cloud`, `database`, `infrastructure`, `monitoring`, `network`, `utility`, `vcs`
|
|
|
|
// and `<type>` is either `native` or `component`. If the package is a bridged Terraform
|
|
|
|
// provider, then don't include the `kind/` label.
|
|
|
|
Keywords []string `json:"keywords,omitempty" yaml:"keywords,omitempty"`
|
|
|
|
// Homepage is the package's homepage.
|
|
|
|
Homepage string `json:"homepage,omitempty" yaml:"homepage,omitempty"`
|
|
|
|
// License indicates which license is used for the package's contents.
|
|
|
|
License string `json:"license,omitempty" yaml:"license,omitempty"`
|
|
|
|
// Attribution allows freeform text attribution of derived work, if needed.
|
|
|
|
Attribution string `json:"attribution,omitempty" yaml:"attribution,omitempty"`
|
|
|
|
// Repository is the URL at which the source for the package can be found.
|
|
|
|
Repository string `json:"repository,omitempty" yaml:"repository,omitempty"`
|
|
|
|
// LogoURL is the URL for the package's logo, if any.
|
|
|
|
LogoURL string `json:"logoUrl,omitempty" yaml:"logoUrl,omitempty"`
|
|
|
|
// PluginDownloadURL is the URL to use to acquire the provider plugin binary, if any.
|
|
|
|
PluginDownloadURL string `json:"pluginDownloadURL,omitempty" yaml:"pluginDownloadURL,omitempty"`
|
|
|
|
// Publisher is the name of the person or organization that authored and published the package.
|
|
|
|
Publisher string `json:"publisher,omitempty" yaml:"publisher,omitempty"`
|
|
|
|
|
|
|
|
// Meta contains information for the importer about this package.
|
|
|
|
Meta *MetadataSpec `json:"meta,omitempty" yaml:"meta,omitempty"`
|
|
|
|
|
|
|
|
// A list of allowed package name in addition to the Name property.
|
|
|
|
AllowedPackageNames []string `json:"allowedPackageNames,omitempty" yaml:"allowedPackageNames,omitempty"`
|
|
|
|
|
|
|
|
// Language specifies additional language-specific data about the package.
|
|
|
|
Language map[string]RawMessage `json:"language,omitempty" yaml:"language,omitempty"`
|
|
|
|
}
|
|
|
|
|
2024-07-02 10:29:39 +00:00
|
|
|
// BaseProviderSpec is the serializable description of a Pulumi base provider.
|
|
|
|
type BaseProviderSpec struct {
|
|
|
|
// The name of the base provider.
|
|
|
|
Name string `json:"name" yaml:"name"`
|
|
|
|
// The version of the base provider.
|
|
|
|
Version string `json:"version" yaml:"version"`
|
|
|
|
// The plugin download URL for the base provider.
|
|
|
|
PluginDownloadURL string `json:"pluginDownloadURL,omitempty" yaml:"pluginDownloadURL,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParameterizationSpec is the serializable description of a provider parameterization.
|
|
|
|
type ParameterizationSpec struct {
|
|
|
|
// The base provider to parameterize.
|
|
|
|
BaseProvider BaseProviderSpec `json:"baseProvider" yaml:"baseProvider"`
|
|
|
|
// The parameter to apply to the base provider.
|
2024-07-10 15:36:05 +00:00
|
|
|
Parameter []byte `json:"parameter" yaml:"parameter"`
|
2024-07-02 10:29:39 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// PackageSpec is the serializable description of a Pulumi package.
|
|
|
|
type PackageSpec struct {
|
2020-09-16 20:47:40 +00:00
|
|
|
// Name is the unqualified name of the package (e.g. "aws", "azure", "gcp", "kubernetes", "random")
|
2021-07-13 23:41:40 +00:00
|
|
|
Name string `json:"name" yaml:"name"`
|
2021-10-27 19:53:09 +00:00
|
|
|
// DisplayName is the human-friendly name of the package.
|
|
|
|
DisplayName string `json:"displayName,omitempty" yaml:"displayName,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Version is the version of the package. The version must be valid semver.
|
2021-07-13 23:41:40 +00:00
|
|
|
Version string `json:"version,omitempty" yaml:"version,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Description is the description of the package.
|
2021-07-13 23:41:40 +00:00
|
|
|
Description string `json:"description,omitempty" yaml:"description,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Keywords is the list of keywords that are associated with the package, if any.
|
2021-11-10 19:07:43 +00:00
|
|
|
// Some reserved keywords can be specified as well that help with categorizing the
|
|
|
|
// package in the Pulumi registry. `category/<name>` and `kind/<type>` are the only
|
|
|
|
// reserved keywords at this time, where `<name>` can be one of:
|
|
|
|
// `cloud`, `database`, `infrastructure`, `monitoring`, `network`, `utility`, `vcs`
|
|
|
|
// and `<type>` is either `native` or `component`. If the package is a bridged Terraform
|
|
|
|
// provider, then don't include the `kind/` label.
|
2021-07-13 23:41:40 +00:00
|
|
|
Keywords []string `json:"keywords,omitempty" yaml:"keywords,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Homepage is the package's homepage.
|
2021-07-13 23:41:40 +00:00
|
|
|
Homepage string `json:"homepage,omitempty" yaml:"homepage,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// License indicates which license is used for the package's contents.
|
2021-07-13 23:41:40 +00:00
|
|
|
License string `json:"license,omitempty" yaml:"license,omitempty"`
|
2020-04-02 00:22:23 +00:00
|
|
|
// Attribution allows freeform text attribution of derived work, if needed.
|
2021-07-13 23:41:40 +00:00
|
|
|
Attribution string `json:"attribution,omitempty" yaml:"attribution,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Repository is the URL at which the source for the package can be found.
|
2021-07-13 23:41:40 +00:00
|
|
|
Repository string `json:"repository,omitempty" yaml:"repository,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// LogoURL is the URL for the package's logo, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
LogoURL string `json:"logoUrl,omitempty" yaml:"logoUrl,omitempty"`
|
2020-07-02 16:25:49 +00:00
|
|
|
// PluginDownloadURL is the URL to use to acquire the provider plugin binary, if any.
|
2021-07-13 23:41:40 +00:00
|
|
|
PluginDownloadURL string `json:"pluginDownloadURL,omitempty" yaml:"pluginDownloadURL,omitempty"`
|
2021-10-27 19:53:09 +00:00
|
|
|
// Publisher is the name of the person or organization that authored and published the package.
|
|
|
|
Publisher string `json:"publisher,omitempty" yaml:"publisher,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
|
|
|
|
// Meta contains information for the importer about this package.
|
2021-07-13 23:41:40 +00:00
|
|
|
Meta *MetadataSpec `json:"meta,omitempty" yaml:"meta,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
|
2021-12-08 05:21:04 +00:00
|
|
|
// A list of allowed package name in addition to the Name property.
|
|
|
|
AllowedPackageNames []string `json:"allowedPackageNames,omitempty" yaml:"allowedPackageNames,omitempty"`
|
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
// Language specifies additional language-specific data about the package.
|
|
|
|
Language map[string]RawMessage `json:"language,omitempty" yaml:"language,omitempty"`
|
|
|
|
|
2020-01-21 22:45:48 +00:00
|
|
|
// Config describes the set of configuration variables defined by this package.
|
2022-08-25 09:15:31 +00:00
|
|
|
Config ConfigSpec `json:"config,omitempty" yaml:"config"`
|
2020-09-16 20:47:40 +00:00
|
|
|
// Types is a map from type token to ComplexTypeSpec that describes the set of complex types (ie. object, enum)
|
|
|
|
// defined by this package.
|
2021-07-13 23:41:40 +00:00
|
|
|
Types map[string]ComplexTypeSpec `json:"types,omitempty" yaml:"types,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Provider describes the provider type for this package.
|
2022-08-25 09:15:31 +00:00
|
|
|
Provider ResourceSpec `json:"provider,omitempty" yaml:"provider"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Resources is a map from type token to ResourceSpec that describes the set of resources defined by this package.
|
2021-07-13 23:41:40 +00:00
|
|
|
Resources map[string]ResourceSpec `json:"resources,omitempty" yaml:"resources,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
// Functions is a map from token to FunctionSpec that describes the set of functions defined by this package.
|
2021-07-13 23:41:40 +00:00
|
|
|
Functions map[string]FunctionSpec `json:"functions,omitempty" yaml:"functions,omitempty"`
|
2024-07-02 10:29:39 +00:00
|
|
|
|
|
|
|
// Parameterization is the optional parameterization for this package.
|
|
|
|
Parameterization *ParameterizationSpec `json:"parameterization,omitempty" yaml:"parameterization,omitempty"`
|
2020-01-21 22:45:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
func (p *PackageSpec) Info() PackageInfoSpec {
|
|
|
|
return PackageInfoSpec{
|
|
|
|
Name: p.Name,
|
|
|
|
DisplayName: p.DisplayName,
|
|
|
|
Version: p.Version,
|
|
|
|
Description: p.Description,
|
|
|
|
Keywords: p.Keywords,
|
|
|
|
Homepage: p.Homepage,
|
|
|
|
License: p.License,
|
|
|
|
Attribution: p.Attribution,
|
|
|
|
Repository: p.Repository,
|
|
|
|
LogoURL: p.LogoURL,
|
|
|
|
PluginDownloadURL: p.PluginDownloadURL,
|
|
|
|
Publisher: p.Publisher,
|
|
|
|
Meta: p.Meta,
|
|
|
|
AllowedPackageNames: p.AllowedPackageNames,
|
|
|
|
Language: p.Language,
|
2021-07-09 17:23:10 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-23 20:46:09 +00:00
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
// PartialPackageSpec is a serializable description of a Pulumi package that defers the deserialization of most package
|
|
|
|
// members until they are needed. Used to support PartialPackage and PackageReferences.
|
|
|
|
type PartialPackageSpec struct {
|
|
|
|
PackageInfoSpec `yaml:",inline"`
|
2021-08-23 20:46:09 +00:00
|
|
|
|
2022-05-23 22:44:35 +00:00
|
|
|
// Config describes the set of configuration variables defined by this package.
|
|
|
|
Config json.RawMessage `json:"config" yaml:"config"`
|
|
|
|
// Types is a map from type token to ComplexTypeSpec that describes the set of complex types (ie. object, enum)
|
|
|
|
// defined by this package.
|
|
|
|
Types map[string]json.RawMessage `json:"types,omitempty" yaml:"types,omitempty"`
|
|
|
|
// Provider describes the provider type for this package.
|
|
|
|
Provider json.RawMessage `json:"provider" yaml:"provider"`
|
|
|
|
// Resources is a map from type token to ResourceSpec that describes the set of resources defined by this package.
|
|
|
|
Resources map[string]json.RawMessage `json:"resources,omitempty" yaml:"resources,omitempty"`
|
|
|
|
// Functions is a map from token to FunctionSpec that describes the set of functions defined by this package.
|
|
|
|
Functions map[string]json.RawMessage `json:"functions,omitempty" yaml:"functions,omitempty"`
|
2021-08-23 20:46:09 +00:00
|
|
|
}
|