本文整理汇总了Golang中github.com/crewjam/go-cloudformation.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了String函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseFnJoinExpr
func parseFnJoinExpr(data map[string]interface{}) (*gocf.StringExpr, error) {
if len(data) <= 0 {
return nil, fmt.Errorf("FnJoinExpr data is empty")
}
for eachKey, eachValue := range data {
switch eachKey {
case "Ref":
return gocf.Ref(eachValue.(string)).String(), nil
case "Fn::GetAtt":
attrValues, attrValuesErr := toExpressionSlice(eachValue)
if nil != attrValuesErr {
return nil, attrValuesErr
}
if len(attrValues) != 2 {
return nil, fmt.Errorf("Invalid params for Fn::GetAtt: %s", eachValue)
}
return gocf.GetAtt(attrValues[0], attrValues[1]).String(), nil
case "Fn::FindInMap":
attrValues, attrValuesErr := toExpressionSlice(eachValue)
if nil != attrValuesErr {
return nil, attrValuesErr
}
if len(attrValues) != 3 {
return nil, fmt.Errorf("Invalid params for Fn::FindInMap: %s", eachValue)
}
return gocf.FindInMap(attrValues[0], gocf.String(attrValues[1]), gocf.String(attrValues[2])), nil
}
}
return nil, fmt.Errorf("Unsupported AWS Function detected: %#v", data)
}
示例2: integrationResponses
func integrationResponses(userResponses map[int]*IntegrationResponse,
corsEnabled bool) *gocf.APIGatewayMethodIntegrationIntegrationResponseList {
var integrationResponses gocf.APIGatewayMethodIntegrationIntegrationResponseList
// We've already populated this entire map in the NewMethod call
for eachHTTPStatusCode, eachMethodIntegrationResponse := range userResponses {
responseParameters := eachMethodIntegrationResponse.Parameters
if corsEnabled {
for eachKey, eachValue := range corsIntegrationResponseParams() {
responseParameters[eachKey] = eachValue
}
}
integrationResponse := gocf.APIGatewayMethodIntegrationIntegrationResponse{
ResponseTemplates: eachMethodIntegrationResponse.Templates,
SelectionPattern: gocf.String(eachMethodIntegrationResponse.SelectionPattern),
StatusCode: gocf.String(strconv.Itoa(eachHTTPStatusCode)),
}
if len(responseParameters) != 0 {
integrationResponse.ResponseParameters = responseParameters
}
integrationResponses = append(integrationResponses, integrationResponse)
}
return &integrationResponses
}
示例3: export
func (resourceInfo *customResourceInfo) export(serviceName string,
targetLambda *gocf.StringExpr,
S3Bucket string,
S3Key string,
roleNameMap map[string]*gocf.StringExpr,
template *gocf.Template,
logger *logrus.Logger) error {
// Figure out the role name
iamRoleArnName := resourceInfo.roleName
// If there is no user supplied role, that means that the associated
// IAMRoleDefinition name has been created and this resource needs to
// depend on that being created.
if iamRoleArnName == "" && resourceInfo.roleDefinition != nil {
iamRoleArnName = resourceInfo.roleDefinition.logicalName(serviceName, resourceInfo.userFunctionName)
}
lambdaDescription := resourceInfo.options.Description
if "" == lambdaDescription {
lambdaDescription = fmt.Sprintf("%s CustomResource: %s", serviceName, resourceInfo.userFunctionName)
}
// Create the Lambda Function
lambdaResource := gocf.LambdaFunction{
Code: &gocf.LambdaFunctionCode{
S3Bucket: gocf.String(S3Bucket),
S3Key: gocf.String(S3Key),
},
Description: gocf.String(lambdaDescription),
Handler: gocf.String(fmt.Sprintf("index.%s", resourceInfo.jsHandlerName())),
MemorySize: gocf.Integer(resourceInfo.options.MemorySize),
Role: roleNameMap[iamRoleArnName],
Runtime: gocf.String(NodeJSVersion),
Timeout: gocf.Integer(resourceInfo.options.Timeout),
VpcConfig: resourceInfo.options.VpcConfig,
}
lambdaFunctionCFName := CloudFormationResourceName("CustomResourceLambda",
resourceInfo.userFunctionName,
resourceInfo.logicalName())
cfResource := template.AddResource(lambdaFunctionCFName, lambdaResource)
safeMetadataInsert(cfResource, "golangFunc", resourceInfo.userFunctionName)
// And create the CustomResource that actually invokes it...
newResource, newResourceError := newCloudFormationResource(cloudFormationLambda, logger)
if nil != newResourceError {
return newResourceError
}
customResource := newResource.(*cloudFormationLambdaCustomResource)
customResource.ServiceToken = gocf.GetAtt(lambdaFunctionCFName, "Arn")
customResource.UserProperties = resourceInfo.properties
template.AddResource(resourceInfo.logicalName(), customResource)
return nil
}
示例4: toResourceRule
func (rule *ReceiptRule) toResourceRule(serviceName string,
functionArnRef interface{},
messageBodyStorage *MessageBodyStorage) *cloudformationresources.SESLambdaEventSourceResourceRule {
resourceRule := &cloudformationresources.SESLambdaEventSourceResourceRule{
Name: gocf.String(rule.Name),
ScanEnabled: gocf.Bool(!rule.ScanDisabled),
Enabled: gocf.Bool(!rule.Disabled),
Actions: make([]*cloudformationresources.SESLambdaEventSourceResourceAction, 0),
Recipients: make([]*gocf.StringExpr, 0),
}
for _, eachRecipient := range rule.Recipients {
resourceRule.Recipients = append(resourceRule.Recipients, gocf.String(eachRecipient))
}
if "" != rule.TLSPolicy {
resourceRule.TLSPolicy = gocf.String(rule.TLSPolicy)
}
// If there is a MessageBodyStorage reference, push that S3Action
// to the head of the Actions list
if nil != messageBodyStorage && !rule.BodyStorageOptions.DisableStorage {
s3Action := &cloudformationresources.SESLambdaEventSourceResourceAction{
ActionType: gocf.String("S3Action"),
ActionProperties: map[string]interface{}{
"BucketName": messageBodyStorage.bucketNameExpr,
},
}
if "" != rule.BodyStorageOptions.ObjectKeyPrefix {
s3Action.ActionProperties["ObjectKeyPrefix"] = rule.BodyStorageOptions.ObjectKeyPrefix
}
if "" != rule.BodyStorageOptions.KmsKeyArn {
s3Action.ActionProperties["KmsKeyArn"] = rule.BodyStorageOptions.KmsKeyArn
}
if "" != rule.BodyStorageOptions.TopicArn {
s3Action.ActionProperties["TopicArn"] = rule.BodyStorageOptions.TopicArn
}
resourceRule.Actions = append(resourceRule.Actions, s3Action)
}
// There's always a lambda action
lambdaAction := &cloudformationresources.SESLambdaEventSourceResourceAction{
ActionType: gocf.String("LambdaAction"),
ActionProperties: map[string]interface{}{
"FunctionArn": functionArnRef,
},
}
lambdaAction.ActionProperties["InvocationType"] = rule.InvocationType
if "" == rule.InvocationType {
lambdaAction.ActionProperties["InvocationType"] = "Event"
}
if "" != rule.TopicArn {
lambdaAction.ActionProperties["TopicArn"] = rule.TopicArn
}
resourceRule.Actions = append(resourceRule.Actions, lambdaAction)
return resourceRule
}
示例5: toResource
func (roleDefinition *IAMRoleDefinition) toResource(eventSourceMappings []*EventSourceMapping,
options *LambdaFunctionOptions,
logger *logrus.Logger) gocf.IAMRole {
statements := CommonIAMStatements.Core
for _, eachPrivilege := range roleDefinition.Privileges {
statements = append(statements, spartaIAM.PolicyStatement{
Effect: "Allow",
Action: eachPrivilege.Actions,
Resource: eachPrivilege.resourceExpr(),
})
}
// Add VPC permissions iff needed
if options != nil && options.VpcConfig != nil {
for _, eachStatement := range CommonIAMStatements.VPC {
statements = append(statements, eachStatement)
}
}
// http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
for _, eachEventSourceMapping := range eventSourceMappings {
arnParts := strings.Split(eachEventSourceMapping.EventSourceArn, ":")
// 3rd slot is service scope
if len(arnParts) >= 2 {
awsService := arnParts[2]
logger.Debug("Looking up common IAM privileges for EventSource: ", awsService)
switch awsService {
case "dynamodb":
statements = append(statements, CommonIAMStatements.DynamoDB...)
case "kinesis":
for _, statement := range CommonIAMStatements.Kinesis {
statement.Resource = gocf.String(eachEventSourceMapping.EventSourceArn)
statements = append(statements, statement)
}
default:
logger.Debug("No additional statements found")
}
}
}
iamPolicies := gocf.IAMPoliciesList{}
iamPolicies = append(iamPolicies, gocf.IAMPolicies{
PolicyDocument: ArbitraryJSONObject{
"Version": "2012-10-17",
"Statement": statements,
},
PolicyName: gocf.String(CloudFormationResourceName("LambdaPolicy")),
})
return gocf.IAMRole{
AssumeRolePolicyDocument: AssumePolicyDocument,
Policies: &iamPolicies,
}
}
示例6: annotateDiscoveryInfo
func annotateDiscoveryInfo(template *gocf.Template, logger *logrus.Logger) *gocf.Template {
for eachResourceID, eachResource := range template.Resources {
// Only apply this to lambda functions
if eachResource.Properties.CfnResourceType() == "AWS::Lambda::Function" {
// Update the metdata with a reference to the output of each
// depended on item...
for _, eachDependsKey := range eachResource.DependsOn {
dependencyOutputs, _ := outputsForResource(template, eachDependsKey, logger)
if nil != dependencyOutputs && len(dependencyOutputs) != 0 {
logger.WithFields(logrus.Fields{
"Resource": eachDependsKey,
"DependsOn": eachResource.DependsOn,
"Outputs": dependencyOutputs,
}).Debug("Resource metadata")
safeMetadataInsert(eachResource, eachDependsKey, dependencyOutputs)
}
}
// Also include standard AWS outputs at a resource level if a lambda
// needs to self-discover other resources
safeMetadataInsert(eachResource, TagLogicalResourceID, gocf.String(eachResourceID))
safeMetadataInsert(eachResource, TagStackRegion, gocf.Ref("AWS::Region"))
safeMetadataInsert(eachResource, TagStackID, gocf.Ref("AWS::StackId"))
safeMetadataInsert(eachResource, TagStackName, gocf.Ref("AWS::StackName"))
}
}
return template
}
示例7: appendDynamicSNSLambda
func appendDynamicSNSLambda(api *sparta.API, lambdaFunctions []*sparta.LambdaAWSInfo) []*sparta.LambdaAWSInfo {
snsTopicName := sparta.CloudFormationResourceName("SNSDynamicTopic")
lambdaFn := sparta.NewLambda(sparta.IAMRoleDefinition{}, echoDynamicSNSEvent, nil)
lambdaFn.Permissions = append(lambdaFn.Permissions, sparta.SNSPermission{
BasePermission: sparta.BasePermission{
SourceArn: gocf.Ref(snsTopicName),
},
})
lambdaFn.Decorator = func(serviceName string,
lambdaResourceName string,
lambdaResource gocf.LambdaFunction,
resourceMetadata map[string]interface{},
S3Bucket string,
S3Key string,
buildID string,
template *gocf.Template,
context map[string]interface{},
logger *logrus.Logger) error {
template.AddResource(snsTopicName, &gocf.SNSTopic{
DisplayName: gocf.String("Sparta Application SNS topic"),
})
return nil
}
return append(lambdaFunctions, lambdaFn)
}
示例8: S3ArnForBucket
// S3ArnForBucket returns a CloudFormation-compatible Arn expression
// (string or Ref) suitable for template reference. The bucket
// parameter may be either a string or an interface{} ("Ref: "myResource")
// value
func S3ArnForBucket(bucket interface{}) *gocf.StringExpr {
arnParts := []gocf.Stringable{gocf.String("arn:aws:s3:::")}
switch bucket.(type) {
case string:
// Don't be smart if the Arn value is a user supplied literal
arnParts = append(arnParts, gocf.String(bucket.(string)))
case *gocf.StringExpr:
arnParts = append(arnParts, bucket.(*gocf.StringExpr))
case gocf.RefFunc:
arnParts = append(arnParts, bucket.(gocf.RefFunc).String())
default:
panic(fmt.Sprintf("Unsupported SourceArn value type: %+v", bucket))
}
return gocf.Join("", arnParts...).String()
}
示例9: methodResponses
// DefaultMethodResponses returns the default set of Method HTTPStatus->Response
// pass through responses. The successfulHTTPStatusCode param is the single
// 2XX response code to use for the method.
func methodResponses(userResponses map[int]*Response, corsEnabled bool) *gocf.APIGatewayMethodMethodResponseList {
var responses gocf.APIGatewayMethodMethodResponseList
for eachHTTPStatusCode, eachResponse := range userResponses {
methodResponseParams := eachResponse.Parameters
if corsEnabled {
for eachString, eachBool := range corsMethodResponseParams() {
methodResponseParams[eachString] = eachBool
}
}
// Then transform them all to strings because internet
methodResponseStringParams := make(map[string]string, len(methodResponseParams))
for eachKey, eachBool := range methodResponseParams {
methodResponseStringParams[eachKey] = fmt.Sprintf("%t", eachBool)
}
methodResponse := gocf.APIGatewayMethodMethodResponse{
StatusCode: gocf.String(strconv.Itoa(eachHTTPStatusCode)),
}
if len(methodResponseStringParams) != 0 {
methodResponse.ResponseParameters = methodResponseStringParams
}
responses = append(responses, methodResponse)
}
return &responses
}
示例10: templateDecorator
func templateDecorator(serviceName string,
lambdaResourceName string,
lambdaResource gocf.LambdaFunction,
resourceMetadata map[string]interface{},
S3Bucket string,
S3Key string,
buildID string,
cfTemplate *gocf.Template,
context map[string]interface{},
logger *logrus.Logger) error {
// Add an empty resource
newResource, err := newCloudFormationResource("Custom::ProvisionTestEmpty", logger)
if nil != err {
return err
}
customResource := newResource.(*cloudFormationProvisionTestResource)
customResource.ServiceToken = "arn:aws:sns:us-east-1:84969EXAMPLE:CRTest"
customResource.TestKey = "Hello World"
cfTemplate.AddResource("ProvisionTestResource", customResource)
// Add an output
cfTemplate.Outputs["OutputDecorationTest"] = &gocf.Output{
Description: "Information about the value",
Value: gocf.String("My key"),
}
return nil
}
示例11: resourceExpr
func (rolePrivilege *IAMRolePrivilege) resourceExpr() *gocf.StringExpr {
switch rolePrivilege.Resource.(type) {
case string:
return gocf.String(rolePrivilege.Resource.(string))
default:
return rolePrivilege.Resource.(*gocf.StringExpr)
}
}
示例12: export
func (perm SNSPermission) export(serviceName string,
lambdaFunctionDisplayName string,
lambdaLogicalCFResourceName string,
template *gocf.Template,
S3Bucket string,
S3Key string,
logger *logrus.Logger) (string, error) {
sourceArnExpression := perm.BasePermission.sourceArnExpr(snsSourceArnParts...)
targetLambdaResourceName, err := perm.BasePermission.export(gocf.String(SNSPrincipal),
snsSourceArnParts,
lambdaFunctionDisplayName,
lambdaLogicalCFResourceName,
template,
S3Bucket,
S3Key,
logger)
if nil != err {
return "", err
}
// Make sure the custom lambda that manages s3 notifications is provisioned.
configuratorResName, err := ensureCustomResourceHandler(serviceName,
cloudformationresources.SNSLambdaEventSource,
sourceArnExpression,
[]string{},
template,
S3Bucket,
S3Key,
logger)
if nil != err {
return "", err
}
// Add a custom resource invocation for this configuration
//////////////////////////////////////////////////////////////////////////////
newResource, newResourceError := newCloudFormationResource(cloudformationresources.SNSLambdaEventSource, logger)
if nil != newResourceError {
return "", newResourceError
}
customResource := newResource.(*cloudformationresources.SNSLambdaEventSourceResource)
customResource.ServiceToken = gocf.GetAtt(configuratorResName, "Arn")
customResource.LambdaTargetArn = gocf.GetAtt(lambdaLogicalCFResourceName, "Arn")
customResource.SNSTopicArn = sourceArnExpression
// Name?
resourceInvokerName := CloudFormationResourceName("ConfigSNS",
lambdaLogicalCFResourceName,
perm.BasePermission.SourceAccount)
// Add it
cfResource := template.AddResource(resourceInvokerName, customResource)
cfResource.DependsOn = append(cfResource.DependsOn,
targetLambdaResourceName,
configuratorResName)
return "", nil
}
示例13: appendDynamicS3BucketLambda
func appendDynamicS3BucketLambda(api *sparta.API, lambdaFunctions []*sparta.LambdaAWSInfo) []*sparta.LambdaAWSInfo {
s3BucketResourceName := sparta.CloudFormationResourceName("S3DynamicBucket")
lambdaFn := sparta.NewLambda(sparta.IAMRoleDefinition{}, echoS3DynamicBucketEvent, nil)
lambdaFn.Permissions = append(lambdaFn.Permissions, sparta.S3Permission{
BasePermission: sparta.BasePermission{
SourceArn: gocf.Ref(s3BucketResourceName),
},
Events: []string{"s3:ObjectCreated:*", "s3:ObjectRemoved:*"},
})
lambdaFn.DependsOn = append(lambdaFn.DependsOn, s3BucketResourceName)
// Add permission s.t. the lambda function could read from the S3 bucket
lambdaFn.RoleDefinition.Privileges = append(lambdaFn.RoleDefinition.Privileges,
sparta.IAMRolePrivilege{
Actions: []string{"s3:GetObject", "s3:HeadObject"},
Resource: spartaCF.S3AllKeysArnForBucket(gocf.Ref(s3BucketResourceName)),
})
lambdaFn.Decorator = func(serviceName string,
lambdaResourceName string,
lambdaResource gocf.LambdaFunction,
resourceMetadata map[string]interface{},
S3Bucket string,
S3Key string,
buildID string,
template *gocf.Template,
context map[string]interface{},
logger *logrus.Logger) error {
cfResource := template.AddResource(s3BucketResourceName, &gocf.S3Bucket{
AccessControl: gocf.String("PublicRead"),
Tags: []gocf.ResourceTag{
gocf.ResourceTag{
Key: gocf.String("SpecialKey"),
Value: gocf.String("SpecialValue"),
},
},
})
cfResource.DeletionPolicy = "Delete"
return nil
}
return append(lambdaFunctions, lambdaFn)
}
示例14: toResource
func (roleDefinition *IAMRoleDefinition) toResource(eventSourceMappings []*EventSourceMapping,
logger *logrus.Logger) gocf.IAMRole {
statements := CommonIAMStatements["core"]
for _, eachPrivilege := range roleDefinition.Privileges {
statements = append(statements, iamPolicyStatement{
Effect: "Allow",
Action: eachPrivilege.Actions,
Resource: eachPrivilege.resourceExpr(),
})
}
// http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
for _, eachEventSourceMapping := range eventSourceMappings {
arnParts := strings.Split(eachEventSourceMapping.EventSourceArn, ":")
// 3rd slot is service scope
if len(arnParts) >= 2 {
awsService := arnParts[2]
logger.Debug("Looking up common IAM privileges for EventSource: ", awsService)
serviceStatements, exists := CommonIAMStatements[awsService]
if exists {
statements = append(statements, serviceStatements...)
statements[len(statements)-1].Resource = gocf.String(eachEventSourceMapping.EventSourceArn)
}
}
}
return gocf.IAMRole{
AssumeRolePolicyDocument: AssumePolicyDocument,
Policies: &gocf.IAMPoliciesList{
gocf.IAMPolicies{
PolicyDocument: ArbitraryJSONObject{
"Version": "2012-10-17",
"Statement": statements,
},
PolicyName: gocf.String(CloudFormationResourceName("LambdaPolicy")),
},
},
}
}
示例15: corsOptionsGatewayMethod
func corsOptionsGatewayMethod(restAPIID gocf.Stringable, resourceID gocf.Stringable) *gocf.ApiGatewayMethod {
methodResponse := gocf.APIGatewayMethodMethodResponse{
StatusCode: gocf.String("200"),
ResponseParameters: corsMethodResponseParams(),
}
integrationResponse := gocf.APIGatewayMethodIntegrationIntegrationResponse{
ResponseTemplates: map[string]string{
"application/*": "",
"text/*": "",
},
StatusCode: gocf.String("200"),
ResponseParameters: corsIntegrationResponseParams(),
}
methodIntegrationIntegrationResponseList := gocf.APIGatewayMethodIntegrationIntegrationResponseList{}
methodIntegrationIntegrationResponseList = append(methodIntegrationIntegrationResponseList,
integrationResponse)
methodResponseList := gocf.APIGatewayMethodMethodResponseList{}
methodResponseList = append(methodResponseList, methodResponse)
corsMethod := &gocf.ApiGatewayMethod{
HttpMethod: gocf.String("OPTIONS"),
AuthorizationType: gocf.String("NONE"),
RestApiId: restAPIID.String(),
ResourceId: resourceID.String(),
Integration: &gocf.APIGatewayMethodIntegration{
Type: gocf.String("MOCK"),
RequestTemplates: map[string]string{
"application/json": "{\"statusCode\": 200}",
"text/plain": "statusCode: 200",
},
IntegrationResponses: &methodIntegrationIntegrationResponseList,
},
MethodResponses: &methodResponseList,
}
return corsMethod
}