Skip to content

Commit

Permalink
Show sign-in announcements less often (#25613)
Browse files Browse the repository at this point in the history
  • Loading branch information
isra-fel authored Jul 24, 2024
1 parent 5cd1e81 commit 8c8b3a0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public override void ExecuteCmdlet()
shouldPopulateContextList = false;
}
profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));
profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));
profileClient.InteractiveInformationLog = (message) => _tasks.Enqueue(new Task(() => WriteInteractiveInformation(message)));
profileClient.DebugLog = (message) => _tasks.Enqueue(new Task(() => this.WriteDebugWithTimestamp(message)));
profileClient.PromptAndReadLine = (message) =>
Expand Down Expand Up @@ -603,8 +603,28 @@ public override void ExecuteCmdlet()
}
});

WriteInteractiveInformation($"{Resources.AnnouncementsHeader}{System.Environment.NewLine}{Resources.AnnouncementsMessage}{System.Environment.NewLine}");
WriteInteractiveInformation($"{Resources.ReportIssue}{System.Environment.NewLine}");
WriteAnnouncementsPeriodically();
}
}

private void WriteAnnouncementsPeriodically()
{
if (ParameterSetName != UserParameterSet)
{
// Write-Host may block automation scenarios
return;
}
const string AnnouncementsFeatureName = "SignInAnnouncements";
TimeSpan AnnouncementsInterval = TimeSpan.FromDays(7);
if (AzureSession.Instance.TryGetComponent<IFrequencyService>(nameof(IFrequencyService), out var frequency))
{
frequency.Register(AnnouncementsFeatureName, AnnouncementsInterval);
// WriteInformation can't fail, so the second parameter always returns true
frequency.TryRun(AnnouncementsFeatureName, () => true, () =>
{
WriteInformation($"{Resources.AnnouncementsHeader}{System.Environment.NewLine}{Resources.AnnouncementsMessage}{System.Environment.NewLine}", false);
WriteInformation($"{Resources.ReportIssue}{System.Environment.NewLine}", false);
});
}
}

Expand Down Expand Up @@ -878,7 +898,7 @@ private void AddConfigTelemetry()
AzConfigReader.GetAzConfig(ConfigKeys.EnableLoginByWam, true).ToString());
}
}
catch(Exception ex)
catch (Exception ex)
{
WriteDebug(string.Format("Failed to add telemtry for config as {0}", ex.Message));
}
Expand Down
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Reduced the frequency of displaying sign-in announcement messages.
* Upgraded Azure.Core to 1.41.0 to include the fix for `BearerTokenAuthenticationPolicy`
* Removed the informational table about selected context to avoid duplication with output table.

Expand Down

0 comments on commit 8c8b3a0

Please sign in to comment.