Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDP-1183, partial] Add cron-based sync of groups_external data from Google Sheet #360

Merged
merged 7 commits into from
Sep 9, 2024

Conversation

forevermatt
Copy link
Contributor

IDP-1183 Sync prefixed-groups from Google Sheet to ID Broker's groups_external field


Added

  • Add cron-based sync of groups_external data from Google Sheet

Fixed

  • Clean up some external-groups log message formatting
  • Remove redundant log message from $user->updateExternalGroups()

Feature PR Checklist

  • Documentation (README, local.env.dist, api.raml, etc.)
  • Tests created or updated
  • Run make composershow
  • Run make psr2

@forevermatt forevermatt requested a review from a team September 5, 2024 16:01
Copy link

sonarcloud bot commented Sep 5, 2024

Comment on lines +16 to +26
for ($i = 1; $i <= self::MAX_SYNC_SETS; $i++) {
$appPrefixKey = sprintf('set%uAppPrefix', $i);
$googleSheetIdKey = sprintf('set%uGoogleSheetId', $i);

if (! array_key_exists($appPrefixKey, $syncSetsParams)) {
Yii::warning(sprintf(
'Finished syncing external groups after %s sync set(s).',
($i - 1)
));
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be my preference, just because it's more consistent with typical for loops. Leave the 1-based numbering for user-focused text. (Note: there's one more $i further down.)

Suggested change
for ($i = 1; $i <= self::MAX_SYNC_SETS; $i++) {
$appPrefixKey = sprintf('set%uAppPrefix', $i);
$googleSheetIdKey = sprintf('set%uGoogleSheetId', $i);
if (! array_key_exists($appPrefixKey, $syncSetsParams)) {
Yii::warning(sprintf(
'Finished syncing external groups after %s sync set(s).',
($i - 1)
));
break;
}
for ($i = 0; $i < self::MAX_SYNC_SETS; $i++) {
$appPrefixKey = sprintf('set%uAppPrefix', $i+1);
$googleSheetIdKey = sprintf('set%uGoogleSheetId', $i+1);
if (! array_key_exists($appPrefixKey, $syncSetsParams)) {
Yii::warning(sprintf(
'Finished syncing external groups after %s sync set(s).',
$i
));
break;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, but since this is also used for the names of the environment variables, starting with 1 seems more intuitive than starting with 0 in this case. I agree that it's more intuitive/expected that code-only for-loops start with 0, though.

Yii::error(sprintf(
'Errors that occurred while syncing %s external groups: %s',
$appPrefix,
join(" / ", $errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's theoretically possible to accumulate thousands of errors, would it be good to limit the length of this log message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I hadn't thought of that. Yes, I can limit that error message length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do that in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@forevermatt forevermatt merged commit 236c123 into develop Sep 9, 2024
3 checks passed
@forevermatt forevermatt deleted the feature/IDP-1183-cron-sync branch September 9, 2024 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants