Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (groups) {
groupAuthorizationExpressions = groupAuthorizationExpressions.concat(
comment(`Authorization rule: { allow: groups, groups: ${JSON.stringify(groups)}, groupClaim: "${groupClaimAttribute}" }`),
this.setUserGroups(rule.groupClaim),
set(ref('allowedGroups'), list(groups.map(s => str(s)))),
forEach(ref('userGroup'), ref('userGroups'), [
iff(raw(`$allowedGroups.contains($userGroup)`), compoundExpression([set(ref(variableToSet), raw('true')), raw('#break')])),
])
);
}
}
const staticGroupAuthorizedVariable = this.getStaticAuthorizationVariable(field);
// tslint:disable-next-line
return block('Static Group Authorization Checks', [
raw(`#set($${staticGroupAuthorizedVariable} = $util.defaultIfNull(
$${staticGroupAuthorizedVariable}, false))`),
...groupAuthorizationExpressions,
]);
}
? set(ref(accumulatorVar1), str(`$ctx.args.${sortKeyArgumentName}.beginsWith.${keyName}`))
: set(ref(accumulatorVar1), str(`$${accumulatorVar1}${sep}$ctx.args.${sortKeyArgumentName}.beginsWith.${keyName}`)),
true
)
),
set(ref(`${queryExprReference}.expression`), raw(`"$${queryExprReference}.expression AND begins_with(#sortKey, :sortKey)"`)),
qref(`$${queryExprReference}.expressionNames.put("#sortKey", "${sortKeyAttributeName}")`),
// TODO: Handle N & B.
qref(`$${queryExprReference}.expressionValues.put(":sortKey", { "S": "$${accumulatorVar1}" })`),
])
),
iff(
raw(`!$util.isNull($ctx.args.${sortKeyArgumentName}) && !$util.isNull($ctx.args.${sortKeyArgumentName}.between)`),
compoundExpression([
iff(
raw(`$ctx.args.${sortKeyArgumentName}.between.size() != 2`),
raw(`$util.error("Argument ${sortKeyArgumentName}.between expects exactly 2 elements.")`)
),
...keyNames.map((keyName, idx) =>
iff(
raw(`!$util.isNull($ctx.args.${sortKeyArgumentName}.between[0].${keyName})`),
idx === 0
? set(ref(accumulatorVar1), str(`$ctx.args.${sortKeyArgumentName}.between[0].${keyName}`))
: set(ref(accumulatorVar1), str(`$${accumulatorVar1}${sep}$ctx.args.${sortKeyArgumentName}.between[0].${keyName}`)),
true
)
),
...keyNames.map((keyName, idx) =>
iff(
raw(`!$util.isNull($ctx.args.${sortKeyArgumentName}.between[1].${keyName})`),
idx === 0
? set(ref(accumulatorVar2), str(`$ctx.args.${sortKeyArgumentName}.between[1].${keyName}`))
) {
let groupAuthorizationExpressions = [];
for (const rule of rules) {
// for loop do check of rules here
const groupsAttribute = rule.groupsField || DEFAULT_GROUPS_FIELD;
const groupClaimAttribute = rule.groupClaim || DEFAULT_GROUP_CLAIM;
groupAuthorizationExpressions = groupAuthorizationExpressions.concat(
formatComment
? comment(formatComment(rule))
: comment(`Authorization rule: { allow: ${rule.allow}, groupsField: "${groupsAttribute}", groupClaim: "${groupClaimAttribute}"`),
this.setUserGroups(rule.groupClaim),
set(ref(variableToSet), raw(`$util.defaultIfNull($${variableToSet}, false)`)),
forEach(ref('userGroup'), ref('userGroups'), [
iff(
raw(`$util.isList($ctx.args.input.${groupsAttribute})`),
iff(ref(`${variableToCheck}.${groupsAttribute}.contains($userGroup)`), set(ref(variableToSet), raw('true')))
),
iff(
raw(`$util.isString($ctx.args.input.${groupsAttribute})`),
iff(raw(`$ctx.args.input.${groupsAttribute} == $userGroup`), set(ref(variableToSet), raw('true')))
),
])
);
}
return compoundExpression(groupAuthorizationExpressions);
}
qref('$headers.put("accept-encoding", "application/json")'),
...parsedHeaders,
HttpMappingTemplate.putRequest({
resourcePath: path,
params: obj({
body: ref('util.toJson($ctx.args.body)'),
query: ref('util.toJson($ctx.args.query)'),
headers: ref('util.toJson($headers)'),
}),
}),
])
)
),
ResponseMappingTemplate: print(
ifElse(
raw('$ctx.result.statusCode == 200 || $ctx.result.statusCode == 201'),
ifElse(
ref('ctx.result.headers.get("Content-Type").toLowerCase().contains("xml")'),
ref('utils.xml.toJsonString($ctx.result.body)'),
ref('ctx.result.body')
),
ref('util.qr($util.appendError($ctx.result.body, $ctx.result.statusCode))')
)
),
}); // .dependsOn(ResourceConstants.RESOURCES.GraphQLSchemaLogicalID)
}
public operationCheckExpression(operation: string, field: string) {
return block('Checking for allowed operations which can return this field', [
set(ref('operation'), raw('$util.defaultIfNull($context.source.operation, "null")')),
ifElse(raw(`$operation == "${operation}"`), ref('util.toJson(null)'), ref(`util.toJson($context.source.${field})`)),
]);
}
loopOverKeys((rightKey: string, previousKey: string) =>
compoundExpression([
iff(
raw(
`!$util.isNullOrBlank($ctx.args.${sortKeyArgumentName}.between[0].${rightKey}) && $util.isNullOrBlank($ctx.args.${sortKeyArgumentName}.between[0].${previousKey})`
),
invalidArgumentError(
`When providing argument '${sortKeyArgumentName}.between[0].${rightKey}' you must also provide '${sortKeyArgumentName}.between[0].${previousKey}'.`
)
),
iff(
raw(
`!$util.isNullOrBlank($ctx.args.${sortKeyArgumentName}.between[1].${rightKey}) && $util.isNullOrBlank($ctx.args.${sortKeyArgumentName}.between[1].${previousKey})`
),
invalidArgumentError(
`When providing argument '${sortKeyArgumentName}.between[1].${rightKey}' you must also provide '${sortKeyArgumentName}.between[1].${previousKey}'.`
)
),
])
),
public throwIfSubscriptionUnauthorized(): Expression {
const ifUnauthThrow = iff(
not(
parens(
or([
equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
equals(ref(ResourceConstants.SNIPPETS.IsOwnerAuthorizedVariable), raw('true')),
])
)
),
raw('$util.unauthorized()')
);
return block('Throw if unauthorized', [ifUnauthThrow]);
}
public setUserGroups(customGroup?: string): Expression {
if (customGroup) {
return compoundExpression([
set(ref('userGroups'), raw(`$util.defaultIfNull($ctx.identity.claims.get("${customGroup}"), [])`)),
iff(
raw('$util.isString($userGroups)'),
ifElse(
raw('$util.isList($util.parseJson($userGroups))'),
set(ref('userGroups'), raw('$util.parseJson($userGroups)')),
set(ref('userGroups'), raw('[$userGroups]'))
)
),
]);
}
return set(ref('userGroups'), raw(`$util.defaultIfNull($ctx.identity.claims.get("${DEFAULT_GROUP_CLAIM}"), [])`));
}