freckle / stackctl

Manage CloudFormation Stacks through specifications
MIT License
14 stars 1 forks source link

Add --auto-sso option to invoke aws-sso-login if necessary #47

Closed pbrisbin closed 1 year ago

pbrisbin commented 1 year ago

When you run stackctl after your AWS SSO credentials have timed out, you see:

stackctl: ServiceError (ServiceError'
{ _serviceErrorAbbrev = Abbrev {fromAbbrev = "SSO"}
, _serviceErrorStatus = Status {statusCode = 401, statusMessage = "Unauthorized"}
, _serviceErrorHeaders = [("Date","Mon, 22 May 2023 17:56:45 GMT"),("Content-Type","application/json"),("Content-Length","114"),("Connection","keep-alive"),("Access-Control-Expose-Headers","RequestId"),("Access-Control-Expose-Headers","x-amzn-RequestId"),("RequestId","0763ba60-15ca-4fec-9b56-a329844f269d"),("Server","AWS SSO"),("x-amzn-RequestId","0763ba60-15ca-4fec-9b56-a329844f269d")]
, _serviceErrorCode = ErrorCode "Unauthorized"
, _serviceErrorMessage = Just (ErrorMessage {fromErrorMessage = "Session token not found or invalid"})
, _serviceErrorRequestId = Just (RequestId {fromRequestId = "0763ba60-15ca-4fec-9b56-a329844f269d"})
})

The solution is to (re)run aws sso login and try again.

This PR adds some handling for that exception. What it does depends on the --auto-sso option:

Since this specifically uses Amazonka.SSO.Types._Unauthorized to catch the exception, I don't think it will have any effect on any other authorization errors.