Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
objectPath
)
const ownerAuthorizationExpression = this.resources.ownerAuthorizationExpressionForReadOperations(
ownerAuthorizationRules,
objectPath
)
const throwIfUnauthorizedExpression = this.resources.throwIfUnauthorized()
// Update the existing resolver with the authorization checks.
return compoundExpression([
staticGroupAuthorizationExpression,
newline(),
dynamicGroupAuthorizationExpression,
newline(),
ownerAuthorizationExpression,
newline(),
throwIfUnauthorizedExpression
]);
}
}
return false;
};
const ownerAuthorizationExpression = this.resources.ownerAuthorizationExpressionForSubscriptions(
ownerAuthorizationRules,
fieldIsList
);
const throwIfUnauthorizedExpression = this.resources.throwIfSubscriptionUnauthorized();
const templateParts = [
print(
compoundExpression([
staticGroupAuthorizationExpression,
newline(),
ownerAuthorizationExpression,
newline(),
throwIfUnauthorizedExpression
])
),
resolver.Properties.ResponseMappingTemplate
];
resolver.Properties.ResponseMappingTemplate = templateParts.join('\n\n');
ctx.setResource(resolverResourceId, resolver);
// check if owner is enabled in auth
const hasOwner = rules.find( rule => rule.allow === OWNER_AUTH_STRATEGY && !rule.ownerField);
const hasStaticGroupAuth = rules.find( rule => rule.allow === GROUPS_AUTH_STRATEGY && !rule.groupsField);
if (hasOwner) {
this.addOwner(ctx, parent.name.value);
// If static group is specified in any of the rules then it would specify the owner arg as optional
if (hasStaticGroupAuth) {
this.addSubscriptionOwnerArgument(ctx, resolver, false)
...keyNames.map((keyName, idx) =>
iff(
raw(`!$util.isNull($ctx.args.${sortKeyArgumentName}.ge.${keyName})`),
idx === 0
? set(ref(accumulatorVar1), str(`$ctx.args.${sortKeyArgumentName}.ge.${keyName}`))
: set(ref(accumulatorVar1), str(`$${accumulatorVar1}${sep}$ctx.args.${sortKeyArgumentName}.ge.${keyName}`)),
true
)
),
set(ref(`${queryExprReference}.expression`), raw(`"$${queryExprReference}.expression AND #sortKey >= :sortKey"`)),
qref(`$${queryExprReference}.expressionNames.put("#sortKey", "${sortKeyAttributeName}")`),
// TODO: Handle N & B.
qref(`$${queryExprReference}.expressionValues.put(":sortKey", { "S": "$${accumulatorVar1}" })`),
])
),
newline(),
]);
}
function applyCompositeSortKey(sortKeys: string[], sortKeyTypes: ('S' | 'N' | 'B')[], queryExprReference: string) {
if (sortKeys.length === 0) {
return newline();
}
// E.g. status#date
const sortKeyAttributeName = ModelResourceIDs.ModelCompositeAttributeName(sortKeys);
const sortKeyArgumentName = ModelResourceIDs.ModelCompositeKeyArgumentName(sortKeys);
return compoundExpression([
applyCompositeKeyConditionExpression(sortKeys, queryExprReference, sortKeyArgumentName, sortKeyAttributeName),
]);
}
compoundExpression([
dynamicGroupAuthorizationExpression,
newline(),
ownerAuthorizationExpression,
newline(),
collectAuthCondition
])
)
const throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty = this.resources.throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty()
const authorizationLogic = compoundExpression([
staticGroupAuthorizationExpression,
newline(),
ifNotStaticallyAuthedCreateAuthCondition,
newline(),
throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty
]);
const templateParts = [
print(
field && ifCondition ?
iff(ifCondition, authorizationLogic) :
authorizationLogic
),
resolver.Properties.RequestMappingTemplate
]
resolver.Properties.RequestMappingTemplate = templateParts.join('\n\n')
ctx.setResource(resolverResourceId, resolver)
}
}
field.name.value,
fieldIsList
)
const throwIfUnauthorizedExpression = this.resources.throwIfUnauthorized()
const templateParts = [
print(
iff(
raw(`$ctx.args.input.containsKey("${field.name.value}")`),
compoundExpression([
staticGroupAuthorizationExpression,
newline(),
dynamicGroupAuthorizationExpression,
newline(),
ownerAuthorizationExpression,
newline(),
throwIfUnauthorizedExpression
])
)
),
createResolverResource.Properties.RequestMappingTemplate
]
createResolverResource.Properties.RequestMappingTemplate = templateParts.join('\n\n')
ctx.setResource(resolverResourceId, createResolverResource)
}
}
}
const ownerAuthorizationExpression = this.resources.ownerAuthorizationExpressionForCreateOperations(
ownerAuthorizationRules,
fieldIsList
)
const throwIfUnauthorizedExpression = this.resources.throwIfUnauthorized()
const templateParts = [
print(
compoundExpression([
staticGroupAuthorizationExpression,
newline(),
dynamicGroupAuthorizationExpression,
newline(),
ownerAuthorizationExpression,
newline(),
throwIfUnauthorizedExpression
])
),
resolver.Properties.RequestMappingTemplate
]
resolver.Properties.RequestMappingTemplate = templateParts.join('\n\n')
ctx.setResource(resolverResourceId, resolver)
}
}
raw(`!$util.isNull($ctx.args.${sortKeyArgumentName})`),
compoundExpression([
set(ref('sortKeyArgumentOperations'), raw(`$ctx.args.${sortKeyArgumentName}.keySet()`)),
iff(
raw(`$sortKeyArgumentOperations.size() > 1`),
invalidArgumentError(`Argument ${sortKeyArgumentName} must specify at most one key condition operation.`)
),
forEach(ref('operation'), ref('sortKeyArgumentOperations'), [
ifElse(raw(`$operation == "between"`), validateBetween(), validateOtherOperation()),
]),
])
)
);
return block('Validate key arguments.', exprs);
} else {
return newline();
}
}