github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/python/importer.go (about)

     1  // Copyright 2016-2020, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package python
    16  
    17  import (
    18  	"encoding/json"
    19  
    20  	"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
    21  )
    22  
    23  // Compatibility mode for Kubernetes 2.0 SDK
    24  const kubernetes20 = "kubernetes20"
    25  
    26  // Compatibility mode for tfbridge 2.x SDKs
    27  const tfbridge20 = "tfbridge20"
    28  
    29  // PropertyInfo tracks Python-specific information associated with properties in a package.
    30  type PropertyInfo struct {
    31  	MapCase bool `json:"mapCase,omitempty"`
    32  }
    33  
    34  // PackageInfo tracks Python-specific information associated with a package.
    35  type PackageInfo struct {
    36  	// PackageName is an override for the name of the generated python package.
    37  	PackageName string `json:"packageName,omitempty"`
    38  	// PythonRequires determines the Python versions that the generated provider supports
    39  	PythonRequires string            `json:"pythonRequires,omitempty"`
    40  	Requires       map[string]string `json:"requires,omitempty"`
    41  	// Readme contains the text for the package's README.md files.
    42  	Readme string `json:"readme,omitempty"`
    43  	// Optional overrides for Pulumi module names
    44  	//
    45  	//    { "flowcontrol.apiserver.k8s.io/v1alpha1": "flowcontrol/v1alpha1" }
    46  	//
    47  	ModuleNameOverrides map[string]string `json:"moduleNameOverrides,omitempty"`
    48  	// Toggle compatibility mode for a specified target.
    49  	Compatibility string `json:"compatibility,omitempty"`
    50  	// Deprecated: This bool is no longer needed since all providers now use input/output classes.
    51  	UsesIOClasses bool `json:"usesIOClasses,omitempty"`
    52  	// Determines whether to make single-return-value methods return an output object or the single value.
    53  	LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"`
    54  
    55  	// Respect the Pkg.Version field for emitted code.
    56  	RespectSchemaVersion bool `json:"respectSchemaVersion,omitempty"`
    57  }
    58  
    59  // Importer implements schema.Language for Python.
    60  var Importer schema.Language = importer(0)
    61  
    62  type importer int
    63  
    64  // ImportDefaultSpec decodes language-specific metadata associated with a DefaultValue.
    65  func (importer) ImportDefaultSpec(def *schema.DefaultValue, raw json.RawMessage) (interface{}, error) {
    66  	return raw, nil
    67  }
    68  
    69  // ImportPropertySpec decodes language-specific metadata associated with a Property.
    70  func (importer) ImportPropertySpec(property *schema.Property, raw json.RawMessage) (interface{}, error) {
    71  	var info PropertyInfo
    72  	if err := json.Unmarshal([]byte(raw), &info); err != nil {
    73  		return nil, err
    74  	}
    75  	return info, nil
    76  }
    77  
    78  // ImportObjectTypeSpec decodes language-specific metadata associated with a ObjectType.
    79  func (importer) ImportObjectTypeSpec(object *schema.ObjectType, raw json.RawMessage) (interface{}, error) {
    80  	return raw, nil
    81  }
    82  
    83  // ImportResourceSpec decodes language-specific metadata associated with a Resource.
    84  func (importer) ImportResourceSpec(resource *schema.Resource, raw json.RawMessage) (interface{}, error) {
    85  	return raw, nil
    86  }
    87  
    88  // ImportFunctionSpec decodes language-specific metadata associated with a Function.
    89  func (importer) ImportFunctionSpec(function *schema.Function, raw json.RawMessage) (interface{}, error) {
    90  	return raw, nil
    91  }
    92  
    93  // ImportPackageSpec decodes language-specific metadata associated with a Package.
    94  func (importer) ImportPackageSpec(pkg *schema.Package, raw json.RawMessage) (interface{}, error) {
    95  	var info PackageInfo
    96  	if err := json.Unmarshal([]byte(raw), &info); err != nil {
    97  		return nil, err
    98  	}
    99  	return info, nil
   100  }