pulumi/pkg/codegen/dotnet/importer.go

104 lines
3.8 KiB
Go
Raw Permalink Normal View History

// Copyright 2016-2020, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dotnet
import (
"encoding/json"
"github.com/pulumi/pulumi/pkg/v3/codegen/schema"
)
// CSharpPropertyInfo represents the C# language-specific info for a property.
type CSharpPropertyInfo struct {
Name string `json:"name,omitempty"`
}
feat: Add support for language specific settings for resources (#14308) <!--- 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 This PR contains changes to support language specific settings for resources. This PR is a prerequisite to resolve a corresponding [bug](https://github.com/pulumi/pulumi-terraform-bridge/issues/1460) in the Terraform Bridge. <!--- 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-terraform-bridge/issues/1460 ## 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. --> - [x] 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. --> --------- Co-authored-by: Thomas Meckel <tmeckel@users.noreply.github.com>
2023-11-29 16:35:08 +00:00
// CSharpResourceInfo represents the C# language-specific info for a resource.
type CSharpResourceInfo struct {
Name string `json:"name,omitempty"`
}
// CSharpPackageInfo represents the C# language-specific info for a package.
type CSharpPackageInfo struct {
PackageReferences map[string]string `json:"packageReferences,omitempty"`
Namespaces map[string]string `json:"namespaces,omitempty"`
Compatibility string `json:"compatibility,omitempty"`
DictionaryConstructors bool `json:"dictionaryConstructors,omitempty"`
ProjectReferences []string `json:"projectReferences,omitempty"`
// Determines whether to make single-return-value methods return an output object or the single value.
LiftSingleValueMethodReturns bool `json:"liftSingleValueMethodReturns,omitempty"`
// The root namespace used for the package. This defaults to `Pulumi`.
RootNamespace string `json:"rootNamespace,omitempty"`
// Allow the Pkg.Version field to filter down to emitted code.
RespectSchemaVersion bool `json:"respectSchemaVersion,omitempty"`
}
// Returns the root namespace, or "Pulumi" if not provided.
func (info *CSharpPackageInfo) GetRootNamespace() string {
if r := info.RootNamespace; r != "" {
return r
}
return "Pulumi"
}
// Importer implements schema.Language for .NET.
var Importer schema.Language = importer(0)
type importer int
// ImportDefaultSpec decodes language-specific metadata associated with a DefaultValue.
func (importer) ImportDefaultSpec(def *schema.DefaultValue, raw json.RawMessage) (interface{}, error) {
return raw, nil
}
// ImportPropertySpec decodes language-specific metadata associated with a Property.
func (importer) ImportPropertySpec(property *schema.Property, raw json.RawMessage) (interface{}, error) {
var info CSharpPropertyInfo
if err := json.Unmarshal([]byte(raw), &info); err != nil {
return nil, err
}
return info, nil
}
// ImportObjectTypeSpec decodes language-specific metadata associated with a ObjectType.
func (importer) ImportObjectTypeSpec(object *schema.ObjectType, raw json.RawMessage) (interface{}, error) {
return raw, nil
}
// ImportResourceSpec decodes language-specific metadata associated with a Resource.
func (importer) ImportResourceSpec(resource *schema.Resource, raw json.RawMessage) (interface{}, error) {
feat: Add support for language specific settings for resources (#14308) <!--- 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 This PR contains changes to support language specific settings for resources. This PR is a prerequisite to resolve a corresponding [bug](https://github.com/pulumi/pulumi-terraform-bridge/issues/1460) in the Terraform Bridge. <!--- 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-terraform-bridge/issues/1460 ## 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. --> - [x] 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. --> --------- Co-authored-by: Thomas Meckel <tmeckel@users.noreply.github.com>
2023-11-29 16:35:08 +00:00
var info CSharpResourceInfo
if err := json.Unmarshal([]byte(raw), &info); err != nil {
return nil, err
}
return info, nil
}
// ImportFunctionSpec decodes language-specific metadata associated with a Function.
func (importer) ImportFunctionSpec(function *schema.Function, raw json.RawMessage) (interface{}, error) {
return raw, nil
}
// ImportPackageSpec decodes language-specific metadata associated with a Package.
func (importer) ImportPackageSpec(pkg *schema.Package, raw json.RawMessage) (interface{}, error) {
var info CSharpPackageInfo
if err := json.Unmarshal([]byte(raw), &info); err != nil {
return nil, err
}
return info, nil
}