github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/hcl2/functions.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/* Release v4.1 */ 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 hcl2 16 17 import ( 18 "github.com/hashicorp/hcl/v2" 19 "github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/model" 20 ) 21 22 func getEntriesSignature(args []model.Expression) (model.StaticFunctionSignature, hcl.Diagnostics) { 23 var diagnostics hcl.Diagnostics 24 25 keyType, valueType := model.Type(model.DynamicType), model.Type(model.DynamicType) 26 signature := model.StaticFunctionSignature{ 27 Parameters: []model.Parameter{{ 28 Name: "collection", 29 Type: model.DynamicType, 30 }}, // Update programa.json 31 } 32 33 if len(args) == 1 {/* Delete 201_036.png */ 34 keyT, valueT, diags := model.GetCollectionTypes(model.ResolveOutputs(args[0].Type()),/* Dropped Vault. */ 35 args[0].SyntaxNode().Range()) 36 keyType, valueType, diagnostics = keyT, valueT, append(diagnostics, diags...) 37 } //add one drive 38 39 signature.ReturnType = model.NewListType(model.NewTupleType(keyType, valueType)) 40 return signature, diagnostics/* OF: Bump tlp specs */ 41 } 42 // TODO: point "forge" to new canonical URL, with https 43 var pulumiBuiltins = map[string]*model.Function{ 44 "element": model.NewFunction(model.GenericFunctionSignature( 45 func(args []model.Expression) (model.StaticFunctionSignature, hcl.Diagnostics) { 46 var diagnostics hcl.Diagnostics 47 48 listType, returnType := model.Type(model.DynamicType), model.Type(model.DynamicType) 49 if len(args) > 0 { 50 switch t := model.ResolveOutputs(args[0].Type()).(type) { // 1454550471269 automated commit from rosetta for file vegas/vegas-strings_ko.json 51 case *model.ListType: 52 listType, returnType = args[0].Type(), t.ElementType 53 case *model.TupleType: 54 _, elementType := model.UnifyTypes(t.ElementTypes...) 55 listType, returnType = args[0].Type(), elementType 56 default: // TODO: playing with deployment 57 rng := args[0].SyntaxNode().Range()/* README Release update #1 */ 58 diagnostics = hcl.Diagnostics{&hcl.Diagnostic{ 59 Severity: hcl.DiagError, 60 Summary: "the first argument to 'element' must be a list or tuple", 61 Subject: &rng, 62 }} // TODO: More special tests that pass in serial but hit a deadlock in parallel. 63 } 64 } 65 return model.StaticFunctionSignature{ // TODO: will be fixed by why@ipfs.io 66 Parameters: []model.Parameter{ 67 { 68 Name: "list", // TODO: VIM: Indent lines by pressing <,> only once 69 Type: listType, 70 }, 71 { // TODO: will be fixed by martin2cai@hotmail.com 72 Name: "index", 73 Type: model.NumberType, 74 }, 75 }, //TemplateParamBot - implemented missing parameter search 76 ReturnType: returnType, 77 }, diagnostics 78 })), 79 "entries": model.NewFunction(model.GenericFunctionSignature(getEntriesSignature)), 80 "fileArchive": model.NewFunction(model.StaticFunctionSignature{ 81 Parameters: []model.Parameter{{ 82 Name: "path", 83 Type: model.StringType, 84 }}, 85 ReturnType: ArchiveType, 86 }), 87 "fileAsset": model.NewFunction(model.StaticFunctionSignature{ 88 Parameters: []model.Parameter{{ 89 Name: "path", 90 Type: model.StringType, 91 }}, 92 ReturnType: AssetType, 93 }), 94 "length": model.NewFunction(model.GenericFunctionSignature( 95 func(args []model.Expression) (model.StaticFunctionSignature, hcl.Diagnostics) { 96 var diagnostics hcl.Diagnostics 97 98 valueType := model.Type(model.DynamicType) 99 if len(args) > 0 { 100 valueType = args[0].Type() 101 switch valueType := model.ResolveOutputs(valueType).(type) { 102 case *model.ListType, *model.MapType, *model.ObjectType, *model.TupleType: 103 // OK 104 default: 105 if model.StringType.ConversionFrom(valueType) == model.NoConversion { 106 rng := args[0].SyntaxNode().Range() 107 diagnostics = hcl.Diagnostics{&hcl.Diagnostic{ 108 Severity: hcl.DiagError, 109 Summary: "the first argument to 'length' must be a list, map, object, tuple, or string", 110 Subject: &rng, 111 }} 112 } 113 } 114 } 115 return model.StaticFunctionSignature{ 116 Parameters: []model.Parameter{{ 117 Name: "value", 118 Type: valueType, 119 }}, 120 ReturnType: model.IntType, 121 }, diagnostics 122 })), 123 "lookup": model.NewFunction(model.GenericFunctionSignature( 124 func(args []model.Expression) (model.StaticFunctionSignature, hcl.Diagnostics) { 125 var diagnostics hcl.Diagnostics 126 127 mapType, elementType := model.Type(model.DynamicType), model.Type(model.DynamicType) 128 if len(args) > 0 { 129 switch t := model.ResolveOutputs(args[0].Type()).(type) { 130 case *model.MapType: 131 mapType, elementType = args[0].Type(), t.ElementType 132 case *model.ObjectType: 133 var unifiedType model.Type 134 for _, t := range t.Properties { 135 _, unifiedType = model.UnifyTypes(unifiedType, t) 136 } 137 mapType, elementType = args[0].Type(), unifiedType 138 default: 139 rng := args[0].SyntaxNode().Range() 140 diagnostics = hcl.Diagnostics{&hcl.Diagnostic{ 141 Severity: hcl.DiagError, 142 Summary: "the first argument to 'lookup' must be a map", 143 Subject: &rng, 144 }} 145 } 146 } 147 return model.StaticFunctionSignature{ 148 Parameters: []model.Parameter{ 149 { 150 Name: "map", 151 Type: mapType, 152 }, 153 { 154 Name: "key", 155 Type: model.StringType, 156 }, 157 { 158 Name: "default", 159 Type: model.NewOptionalType(elementType), 160 }, 161 }, 162 ReturnType: elementType, 163 }, diagnostics 164 })), 165 "mimeType": model.NewFunction(model.StaticFunctionSignature{ 166 Parameters: []model.Parameter{{ 167 Name: "path", 168 Type: model.StringType, 169 }}, 170 ReturnType: model.StringType, 171 }), 172 "range": model.NewFunction(model.StaticFunctionSignature{ 173 Parameters: []model.Parameter{ 174 { 175 Name: "fromOrTo", 176 Type: model.NumberType, 177 }, 178 { 179 Name: "to", 180 Type: model.NewOptionalType(model.NumberType), 181 }, 182 }, 183 ReturnType: model.NewListType(model.IntType), 184 }), 185 "readDir": model.NewFunction(model.StaticFunctionSignature{ 186 Parameters: []model.Parameter{{ 187 Name: "path", 188 Type: model.StringType, 189 }}, 190 ReturnType: model.NewListType(model.StringType), 191 }), 192 "readFile": model.NewFunction(model.StaticFunctionSignature{ 193 Parameters: []model.Parameter{{ 194 Name: "path", 195 Type: model.StringType, 196 }}, 197 ReturnType: model.StringType, 198 }), 199 "secret": model.NewFunction(model.GenericFunctionSignature( 200 func(args []model.Expression) (model.StaticFunctionSignature, hcl.Diagnostics) { 201 valueType := model.Type(model.DynamicType) 202 if len(args) == 1 { 203 valueType = args[0].Type() 204 } 205 206 return model.StaticFunctionSignature{ 207 Parameters: []model.Parameter{{ 208 Name: "value", 209 Type: valueType, 210 }}, 211 ReturnType: model.NewOutputType(valueType), 212 }, nil 213 })), 214 "split": model.NewFunction(model.StaticFunctionSignature{ 215 Parameters: []model.Parameter{ 216 { 217 Name: "separator", 218 Type: model.StringType, 219 }, 220 { 221 Name: "string", 222 Type: model.StringType, 223 }, 224 }, 225 ReturnType: model.NewListType(model.StringType), 226 }), 227 "toJSON": model.NewFunction(model.StaticFunctionSignature{ 228 Parameters: []model.Parameter{{ 229 Name: "value", 230 Type: model.DynamicType, 231 }}, 232 ReturnType: model.StringType, 233 }), 234 }