| | | 1 | | namespace Envilder; |
| | | 2 | | |
| | | 3 | | using System; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Thrown when an AWS request fails because the SSO session used to resolve |
| | | 7 | | /// credentials has expired or could not be loaded. Carries the AWS profile |
| | | 8 | | /// name (when known) so callers can surface a targeted remediation hint. |
| | | 9 | | /// </summary> |
| | | 10 | | public class SsoSessionExpiredException : Exception |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Gets the AWS profile whose SSO session expired, or <c>null</c> when no |
| | | 14 | | /// profile was configured. |
| | | 15 | | /// </summary> |
| | | 16 | | public string? ProfileName { get; } |
| | | 17 | | |
| | | 18 | | /// <summary>Initializes a new instance for the given AWS profile.</summary> |
| | | 19 | | /// <param name="profileName">The AWS profile whose SSO session expired, or <c>null</c>.</param> |
| | | 20 | | public SsoSessionExpiredException(string? profileName) |
| | 1 | 21 | | : base(BuildMessage(profileName)) |
| | | 22 | | { |
| | 1 | 23 | | ProfileName = profileName; |
| | 1 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary>Initializes a new instance wrapping the underlying AWS exception.</summary> |
| | | 27 | | /// <param name="profileName">The AWS profile whose SSO session expired, or <c>null</c>.</param> |
| | | 28 | | /// <param name="innerException">The original AWS SDK exception.</param> |
| | | 29 | | public SsoSessionExpiredException(string? profileName, Exception innerException) |
| | 1 | 30 | | : base(BuildMessage(profileName), innerException) |
| | | 31 | | { |
| | 1 | 32 | | ProfileName = profileName; |
| | 1 | 33 | | } |
| | | 34 | | |
| | | 35 | | private static string BuildMessage(string? profileName) |
| | | 36 | | { |
| | 1 | 37 | | if (string.IsNullOrWhiteSpace(profileName)) |
| | | 38 | | { |
| | 1 | 39 | | return "Your AWS SSO session has expired. Run 'aws sso login' " + |
| | 1 | 40 | | "and re-run this command."; |
| | | 41 | | } |
| | | 42 | | |
| | 1 | 43 | | return $"Your AWS SSO session for profile '{profileName}' has expired. " + |
| | 1 | 44 | | $"Run 'aws sso login --profile {profileName}' and re-run this command."; |
| | | 45 | | } |
| | | 46 | | } |