in api/v1/src/lib/appliers/storageApplier.js [29:69]
async function applyPolicies(projectId, policyIds, fullRefresh) {
const labelKey = cfg.cdsManagedLabelKey;
let options = {};
const bigqueryUtil = new BigQueryUtil(projectId);
const bucketPermissionDiffProcedure = bigqueryUtil.getTableFqdn(projectId, cfg.cdsDatasetId, cfg.bucketPermissionDiffProcedureId);
if (!fullRefresh && policyIds && policyIds.length > 0) {
options = {
query: `CALL \`${bucketPermissionDiffProcedure}\`(@policyIds)`,
params: { policyIds: policyIds }
};
} else {
options = {
query: `CALL \`${bucketPermissionDiffProcedure}\`(null)`
};
}
const [rows] = await bigqueryUtil.executeQuery(options);
console.log(`Storage Bucket Permission Diff Result: ${JSON.stringify(rows, null, 3)}`);
const storageUtil = new StorageUtil(projectId);
if (fullRefresh === true) {
// Update all managed buckets
const buckets = await storageUtil.getBuckets();
for (const bucket of buckets) {
if (underscore.has(bucket.metadata.labels, labelKey)) {
let bucketPolicyRecord = underscore.findWhere(rows, { bucketName: bucket.name });
let accounts = [];
if (bucketPolicyRecord) {
accounts = bucketPolicyRecord.accounts;
}
await performBucketUpdate(projectId, bucket.name, accounts);
}
}
} else {
// Differential update, iterate over result based on the policyId filter only
for (const row of rows) {
await performBucketUpdate(projectId, row.bucketName, row.accounts);
}
}
}