Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
])
),
// If a single owner check for at least one.
iff(
raw(`$util.isString($${allowedOwnersVariable})`),
iff(raw(`$${allowedOwnersVariable} == $identityValue`), set(ref(variableToSet), raw('true')))
)
);
// If the owner field is not a list and the user does not
// provide a value for the owner, set the owner automatically.
if (!ownerFieldIsList) {
ownershipAuthorizationExpressions.push(
// If the owner is not provided set it automatically.
// If the user explicitly provides null this will be false and we leave it null.
iff(
and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
compoundExpression([qref(`$${variableToCheck}.put("${ownerAttribute}", $identityValue)`), set(ref(variableToSet), raw('true'))])
)
);
} else {
// If the owner field is a list and the user does not
// provide a list of values for the owner, set the list with
// the owner as the sole member.
ownershipAuthorizationExpressions.push(
// If the owner is not provided set it automatically.
// If the user explicitly provides null this will be false and we leave it null.
iff(
and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
compoundExpression([
qref(`$${variableToCheck}.put("${ownerAttribute}", ["$identityValue"])`),
set(ref(variableToSet), raw('true')),
])
// If the owner is not provided set it automatically.
// If the user explicitly provides null this will be false and we leave it null.
iff(
and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
compoundExpression([qref(`$${variableToCheck}.put("${ownerAttribute}", $identityValue)`), set(ref(variableToSet), raw('true'))])
)
);
} else {
// If the owner field is a list and the user does not
// provide a list of values for the owner, set the list with
// the owner as the sole member.
ownershipAuthorizationExpressions.push(
// If the owner is not provided set it automatically.
// If the user explicitly provides null this will be false and we leave it null.
iff(
and([raw(`$util.isNull($${allowedOwnersVariable})`), parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`))]),
compoundExpression([
qref(`$${variableToCheck}.put("${ownerAttribute}", ["$identityValue"])`),
set(ref(variableToSet), raw('true')),
])
)
);
}
ruleNumber++;
}
return compoundExpression([set(ref(variableToSet), raw(`false`)), ...ownershipAuthorizationExpressions]);
}
]),
compoundExpression([
qref(`$${variableToCheck}.put("${ownerAttribute}", $identityValue)`),
set(ref(variableToSet), raw('true'))
])
)
)
} else {
// If the owner field is a list and the user does not
// provide a list of values for the owner, set the list with
// the owner as the sole member.
ownershipAuthorizationExpressions.push(
// If the owner is not provided set it automatically.
// If the user explicitly provides null this will be false and we leave it null.
iff(
and([
raw(`$util.isNull($${allowedOwnersVariable})`),
parens(raw(`! $${variableToCheck}.containsKey("${ownerAttribute}")`)),
]),
compoundExpression([
qref(`$${variableToCheck}.put("${ownerAttribute}", ["$identityValue"])`),
set(ref(variableToSet), raw('true'))
])
)
)
}
ruleNumber++
}
return compoundExpression([
set(ref(variableToSet), raw(`false`)),
...ownershipAuthorizationExpressions,
]);
iff(
ref('context.args.condition'),
compoundExpression([
set(ref('condition.expressionValues'), obj({})),
set(
ref('conditionFilterExpressions'),
raw('$util.parseJson($util.transform.toDynamoDBConditionExpression($context.args.condition))')
),
// tslint:disable-next-line
qref(`$condition.put("expression", "($condition.expression) AND $conditionFilterExpressions.expression")`),
qref(`$condition.expressionNames.putAll($conditionFilterExpressions.expressionNames)`),
qref(`$condition.expressionValues.putAll($conditionFilterExpressions.expressionValues)`),
])
),
iff(
and([ref('condition.expressionValues'), raw('$condition.expressionValues.size() == 0')]),
set(
ref('condition'),
obj({
expression: ref('condition.expression'),
expressionNames: ref('condition.expressionNames'),
})
)
),
DynamoDBMappingTemplate.putItem(
{
key: ifElse(
ref(ResourceConstants.SNIPPETS.ModelObjectKey),
raw(`$util.toJson(\$${ResourceConstants.SNIPPETS.ModelObjectKey})`),
obj({
id: raw(`$util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.args.input.id, $util.autoId()))`),
}),
compoundExpression([
set(
ref('conditionFilterExpressions'),
raw('$util.parseJson($util.transform.toDynamoDBConditionExpression($context.args.condition))')
),
// tslint:disable-next-line
qref(`$condition.put("expression", "($condition.expression) AND $conditionFilterExpressions.expression")`),
qref(`$condition.expressionNames.putAll($conditionFilterExpressions.expressionNames)`),
set(ref('conditionExpressionValues'), raw('$util.defaultIfNull($condition.expressionValues, {})')),
qref(`$conditionExpressionValues.putAll($conditionFilterExpressions.expressionValues)`),
set(ref('condition.expressionValues'), ref('conditionExpressionValues')),
qref(`$condition.expressionValues.putAll($conditionFilterExpressions.expressionValues)`),
])
),
iff(
and([ref('condition.expressionValues'), raw('$condition.expressionValues.size() == 0')]),
set(
ref('condition'),
obj({
expression: ref('condition.expression'),
expressionNames: ref('condition.expressionNames'),
})
)
),
DynamoDBMappingTemplate.deleteItem({
key: ifElse(
ref(ResourceConstants.SNIPPETS.ModelObjectKey),
raw(`$util.toJson(\$${ResourceConstants.SNIPPETS.ModelObjectKey})`),
obj({
id: ref('util.dynamodb.toDynamoDBJson($ctx.args.input.id)'),
}),
true
if (authProvider === 'userPools') {
const statements = [
raw(`$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.AuthMode})`),
not(raw(`$util.isNull($ctx.identity)`)),
not(raw(`$util.isNull($ctx.identity.sub)`)),
not(raw(`$util.isNull($ctx.identity.issuer)`)),
not(raw(`$util.isNull($ctx.identity.username)`)),
not(raw(`$util.isNull($ctx.identity.claims)`)),
not(raw(`$util.isNull($ctx.identity.sourceIp)`)),
];
if (isUserPoolTheDefault === true) {
statements.push(not(raw(`$util.isNull($ctx.identity.defaultAuthStrategy)`)));
}
const userPoolsExpression = iff(and(statements), set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`userPools`)));
expressions.push(userPoolsExpression);
} else if (authProvider === 'oidc') {
const oidcExpression = iff(
and([
raw(`$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.AuthMode})`),
not(raw(`$util.isNull($ctx.identity)`)),
not(raw(`$util.isNull($ctx.identity.sub)`)),
not(raw(`$util.isNull($ctx.identity.issuer)`)),
not(raw(`$util.isNull($ctx.identity.claims)`)),
raw(`$util.isNull($ctx.identity.username)`),
raw(`$util.isNull($ctx.identity.sourceIp)`),
]),
set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`oidc`))
);
not(raw(`$util.isNull($ctx.identity.issuer)`)),
not(raw(`$util.isNull($ctx.identity.username)`)),
not(raw(`$util.isNull($ctx.identity.claims)`)),
not(raw(`$util.isNull($ctx.identity.sourceIp)`)),
];
if (isUserPoolTheDefault === true) {
statements.push(not(raw(`$util.isNull($ctx.identity.defaultAuthStrategy)`)));
}
const userPoolsExpression = iff(and(statements), set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`userPools`)));
expressions.push(userPoolsExpression);
} else if (authProvider === 'oidc') {
const oidcExpression = iff(
and([
raw(`$util.isNullOrEmpty($${ResourceConstants.SNIPPETS.AuthMode})`),
not(raw(`$util.isNull($ctx.identity)`)),
not(raw(`$util.isNull($ctx.identity.sub)`)),
not(raw(`$util.isNull($ctx.identity.issuer)`)),
not(raw(`$util.isNull($ctx.identity.claims)`)),
raw(`$util.isNull($ctx.identity.username)`),
raw(`$util.isNull($ctx.identity.sourceIp)`),
]),
set(ref(ResourceConstants.SNIPPETS.AuthMode), str(`oidc`))
);
if (expressions.length > 0) {
expressions.push(newline());
}
expressions.push(oidcExpression);