Skip to content

Commit

Permalink
fix: bandaid solution for content check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Maed223 committed Oct 13, 2023
1 parent f965caa commit 3104a3a
Show file tree
Hide file tree
Showing 9 changed files with 602 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,11 @@ export const functionsMapGenerated = {
},
],
},
plantimestamp: {
name: "plantimestamp",
returnType: "string",
parameters: [],
},
pow: {
name: "pow",
returnType: "number",
Expand Down Expand Up @@ -820,6 +825,18 @@ export const functionsMapGenerated = {
},
],
},
strcontains: {
name: "strcontains",
returnType: "bool",
parameters: [
{
type: "string",
},
{
type: "string",
},
],
},
strrev: {
name: "strrev",
returnType: "string",
Expand Down
34 changes: 25 additions & 9 deletions packages/cdktf/lib/functions/terraform-functions.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export class FnGenerated {
return asString(terraformFunction("abspath", [stringValue])(path));
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/alltrue alltrue} returns `true` if all elements in a given collection are `true` or `"true"`. It also returns `true` if the collection is empty.
* {@link https://developer.hashicorp.com/terraform/language/functions/alltrue alltrue} returns `true` if all elements in a given collection are `true` or `"true"`. It also returns `true` if the collection is empty.
* @param {Array<any>} list
*/
static alltrue(list: any[]) {
return asBoolean(terraformFunction("alltrue", [listOf(anyValue)])(list));
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/anytrue anytrue} returns `true` if any element in a given collection is `true` or `&#34;true&#34;`. It also returns `false` if the collection is empty.
* {@link https://developer.hashicorp.com/terraform/language/functions/anytrue anytrue} returns `true` if any element in a given collection is `true` or `"true"`. It also returns `false` if the collection is empty.
* @param {Array<any>} list
*/
static anytrue(list: any[]) {
Expand Down Expand Up @@ -70,14 +70,14 @@ export class FnGenerated {
return asString(terraformFunction("base64gzip", [stringValue])(str));
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/base64sha256 base64sha256} computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256(&#34;test&#34;))` since `sha256()` returns hexadecimal representation.
* {@link https://developer.hashicorp.com/terraform/language/functions/base64sha256 base64sha256} computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256("test"))` since `sha256()` returns hexadecimal representation.
* @param {string} str
*/
static base64sha256(str: string) {
return asString(terraformFunction("base64sha256", [stringValue])(str));
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/base64sha512 base64sha512} computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512(&#34;test&#34;))` since `sha512()` returns hexadecimal representation.
* {@link https://developer.hashicorp.com/terraform/language/functions/base64sha512 base64sha512} computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512("test"))` since `sha512()` returns hexadecimal representation.
* @param {string} str
*/
static base64sha512(str: string) {
Expand Down Expand Up @@ -187,14 +187,14 @@ export class FnGenerated {
);
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/coalesce coalesce} takes any number of arguments and returns the first one that isn&#39;t null or an empty string.
* {@link https://developer.hashicorp.com/terraform/language/functions/coalesce coalesce} takes any number of arguments and returns the first one that isn't null or an empty string.
* @param {Array<any>} vals
*/
static coalesce(vals: any[]) {
return asAny(terraformFunction("coalesce", [variadic(anyValue)])(vals));
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/coalescelist coalescelist} takes any number of list arguments and returns the first one that isn&#39;t empty.
* {@link https://developer.hashicorp.com/terraform/language/functions/coalescelist coalescelist} takes any number of list arguments and returns the first one that isn't empty.
* @param {Array<any>} vals
*/
static coalescelist(vals: any[]) {
Expand Down Expand Up @@ -553,12 +553,18 @@ export class FnGenerated {
);
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/pathexpand pathexpand} takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user&#39;s home directory path.
* {@link https://developer.hashicorp.com/terraform/language/functions/pathexpand pathexpand} takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user's home directory path.
* @param {string} path
*/
static pathexpand(path: string) {
return asString(terraformFunction("pathexpand", [stringValue])(path));
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/plantimestamp plantimestamp} returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format, fixed to a constant time representing the time of the plan.
*/
static plantimestamp() {
return asString(terraformFunction("plantimestamp", [])());
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/pow pow} calculates an exponent, by raising its first argument to the power of the second argument.
* @param {number} num
Expand Down Expand Up @@ -633,7 +639,7 @@ export class FnGenerated {
);
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/sensitive sensitive} takes any value and returns a copy of it marked so that Terraform will treat it as sensitive, with the same meaning and behavior as for [sensitive input variables](/language/values/variables#suppressing-values-in-cli-output).
* {@link https://developer.hashicorp.com/terraform/language/functions/sensitive sensitive} takes any value and returns a copy of it marked so that Terraform will treat it as sensitive, with the same meaning and behavior as for [sensitive input variables](/terraform/language/values/variables#suppressing-values-in-cli-output).
* @param {any} value
*/
static sensitive(value: any) {
Expand Down Expand Up @@ -755,6 +761,16 @@ export class FnGenerated {
terraformFunction("startswith", [stringValue, stringValue])(str, prefix)
);
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/strcontains strcontains} takes two values: a string to check and an expected substring. The function returns true if the string has the substring contained within it.
* @param {string} str
* @param {string} substr
*/
static strcontains(str: string, substr: string) {
return asBoolean(
terraformFunction("strcontains", [stringValue, stringValue])(str, substr)
);
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/strrev strrev} reverses the characters in a string. Note that the characters are treated as _Unicode characters_ (in technical terms, Unicode [grapheme cluster boundaries](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries) are respected).
* @param {string} str
Expand Down Expand Up @@ -973,7 +989,7 @@ export class FnGenerated {
return asString(terraformFunction("uuid", [])());
}
/**
* {@link https://developer.hashicorp.com/terraform/language/functions/uuidv5 uuidv5} generates a _name-based_ UUID, as described in [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), also known as a &#34;version 5&#34; UUID.
* {@link https://developer.hashicorp.com/terraform/language/functions/uuidv5 uuidv5} generates a _name-based_ UUID, as described in [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), also known as a "version 5" UUID.
* @param {string} namespace
* @param {string} name
*/
Expand Down
28 changes: 20 additions & 8 deletions tools/generate-function-bindings/scripts/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"parameters": [{ "name": "path", "type": "string" }]
},
"alltrue": {
"description": "`alltrue` returns `true` if all elements in a given collection are `true` or `\u0026#34;true\u0026#34;`. It also returns `true` if the collection is empty.",
"description": "`alltrue` returns `true` if all elements in a given collection are `true` or `\"true\"`. It also returns `true` if the collection is empty.",
"return_type": "bool",
"parameters": [{ "name": "list", "type": ["list", "bool"] }]
},
"anytrue": {
"description": "`anytrue` returns `true` if any element in a given collection is `true` or `\u0026#34;true\u0026#34;`. It also returns `false` if the collection is empty.",
"description": "`anytrue` returns `true` if any element in a given collection is `true` or `\"true\"`. It also returns `false` if the collection is empty.",
"return_type": "bool",
"parameters": [{ "name": "list", "type": ["list", "bool"] }]
},
Expand All @@ -37,12 +37,12 @@
"parameters": [{ "name": "str", "type": "string" }]
},
"base64sha256": {
"description": "`base64sha256` computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256(\u0026#34;test\u0026#34;))` since `sha256()` returns hexadecimal representation.",
"description": "`base64sha256` computes the SHA256 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha256(\"test\"))` since `sha256()` returns hexadecimal representation.",
"return_type": "string",
"parameters": [{ "name": "str", "type": "string" }]
},
"base64sha512": {
"description": "`base64sha512` computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512(\u0026#34;test\u0026#34;))` since `sha512()` returns hexadecimal representation.",
"description": "`base64sha512` computes the SHA512 hash of a given string and encodes it with Base64. This is not equivalent to `base64encode(sha512(\"test\"))` since `sha512()` returns hexadecimal representation.",
"return_type": "string",
"parameters": [{ "name": "str", "type": "string" }]
},
Expand Down Expand Up @@ -149,7 +149,7 @@
"variadic_parameter": { "name": "newbits", "type": "number" }
},
"coalesce": {
"description": "`coalesce` takes any number of arguments and returns the first one that isn\u0026#39;t null or an empty string.",
"description": "`coalesce` takes any number of arguments and returns the first one that isn't null or an empty string.",
"return_type": "dynamic",
"variadic_parameter": {
"name": "vals",
Expand All @@ -158,7 +158,7 @@
}
},
"coalescelist": {
"description": "`coalescelist` takes any number of list arguments and returns the first one that isn\u0026#39;t empty.",
"description": "`coalescelist` takes any number of list arguments and returns the first one that isn't empty.",
"return_type": "dynamic",
"variadic_parameter": {
"name": "vals",
Expand Down Expand Up @@ -449,10 +449,14 @@
]
},
"pathexpand": {
"description": "`pathexpand` takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user\u0026#39;s home directory path.",
"description": "`pathexpand` takes a filesystem path that might begin with a `~` segment, and if so it replaces that segment with the current user's home directory path.",
"return_type": "string",
"parameters": [{ "name": "path", "type": "string" }]
},
"plantimestamp": {
"description": "`plantimestamp` returns a UTC timestamp string in [RFC 3339](https://tools.ietf.org/html/rfc3339) format, fixed to a constant time representing the time of the plan.",
"return_type": "string"
},
"pow": {
"description": "`pow` calculates an exponent, by raising its first argument to the power of the second argument.",
"return_type": "number",
Expand Down Expand Up @@ -590,6 +594,14 @@
{ "name": "prefix", "type": "string" }
]
},
"strcontains": {
"description": "`strcontains` takes two values: a string to check and an expected substring. The function returns true if the string has the substring contained within it.",
"return_type": "bool",
"parameters": [
{ "name": "str", "type": "string" },
{ "name": "substr", "type": "string" }
]
},
"strrev": {
"description": "`strrev` reverses the characters in a string. Note that the characters are treated as _Unicode characters_ (in technical terms, Unicode [grapheme cluster boundaries](https://unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries) are respected).",
"return_type": "string",
Expand Down Expand Up @@ -746,7 +758,7 @@
"return_type": "string"
},
"uuidv5": {
"description": "`uuidv5` generates a _name-based_ UUID, as described in [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), also known as a \u0026#34;version 5\u0026#34; UUID.",
"description": "`uuidv5` generates a _name-based_ UUID, as described in [RFC 4122 section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3), also known as a \"version 5\" UUID.",
"return_type": "string",
"parameters": [
{ "name": "namespace", "type": "string" },
Expand Down
21 changes: 14 additions & 7 deletions tools/generate-function-bindings/scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ async function generateFunctionBindings() {
const file = path.join(__dirname, FUNCTIONS_METADATA_FILE);
const json = JSON.parse((await fs.readFile(file)).toString())
.function_signatures as {
[name: string]: FunctionSignature;
};
[name: string]: FunctionSignature;
};

const staticMethods = Object.entries(json).map(([name, signature]) =>
renderStaticMethod(name, signature)
Expand Down Expand Up @@ -128,8 +128,8 @@ async function generateFunctionsMap() {
const file = path.join(__dirname, FUNCTIONS_METADATA_FILE);
const json = JSON.parse((await fs.readFile(file)).toString())
.function_signatures as {
[name: string]: FunctionSignature;
};
[name: string]: FunctionSignature;
};

const properties: t.ObjectProperty[] = [];

Expand Down Expand Up @@ -273,8 +273,7 @@ function mapParameter(p: Parameter) {
};
}
throw new Error(
`Function ${name} has parameter ${
p.name
`Function ${name} has parameter ${p.name
} with unsupported type ${JSON.stringify(p.type)}`
);
};
Expand Down Expand Up @@ -340,10 +339,18 @@ function renderStaticMethod(
);

// comment with docstring for method
const descriptionWithLink = signature.description.replace(
let descriptionWithLink = signature.description.replace(
`\`${name}\``,
`{@link https://developer.hashicorp.com/terraform/language/functions/${name} ${name}}`
);
// Bandaid solution for content check errors https://github.com/hashicorp/terraform-cdk/issues/2816
// Must include product in link– unfortunately it comes with it from the generation of terraform function bindings
if (name == "sensitive") {
descriptionWithLink = descriptionWithLink.replace(
"/language/values/variables#suppressing-values-in-cli-output",
"/terraform/language/values/variables#suppressing-values-in-cli-output"
);
}
t.addComment(
method,
"leading",
Expand Down
Loading

0 comments on commit 3104a3a

Please sign in to comment.