github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/resource/deploy/target.go (about)

     1  // Copyright 2016-2018, 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 deploy
    16  
    17  import (
    18  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
    19  	"github.com/pulumi/pulumi/sdk/v3/go/common/resource/config"
    20  	"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
    21  )
    22  
    23  // Target represents information about a deployment target.
    24  type Target struct {
    25  	Name         tokens.Name      // the target stack name.
    26  	Organization tokens.Name      // the target organization name (if any).
    27  	Config       config.Map       // optional configuration key/value pairs.
    28  	Decrypter    config.Decrypter // decrypter for secret configuration values.
    29  	Snapshot     *Snapshot        // the last snapshot deployed to the target.
    30  }
    31  
    32  // GetPackageConfig returns the set of configuration parameters for the indicated package, if any.
    33  func (t *Target) GetPackageConfig(pkg tokens.Package) (resource.PropertyMap, error) {
    34  	result := resource.PropertyMap{}
    35  	if t == nil {
    36  		return result, nil
    37  	}
    38  
    39  	for k, c := range t.Config {
    40  		if tokens.Package(k.Namespace()) != pkg {
    41  			continue
    42  		}
    43  
    44  		v, err := c.Value(t.Decrypter)
    45  		if err != nil {
    46  			return nil, err
    47  		}
    48  
    49  		propertyValue := resource.NewStringProperty(v)
    50  		if c.Secure() {
    51  			propertyValue = resource.MakeSecret(propertyValue)
    52  		}
    53  		result[resource.PropertyKey(k.Name())] = propertyValue
    54  	}
    55  	return result, nil
    56  }