Skip to content

Commit

Permalink
support old and new credentials format
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd authored and MrFlashAccount committed Mar 8, 2024
1 parent 0801dbe commit 63622f7
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ authorization_header =
token = AuthenticationProvider.getToken.if_nothing <|
f = credentials_file
if f.exists.not then Error.throw Not_Logged_In else
AuthenticationProvider.setToken (f.read_text)
access_token = read_access_token f
AuthenticationProvider.setToken access_token
Header.authorization_bearer token

## PRIVATE
Expand All @@ -50,6 +51,18 @@ credentials_file = case Environment.get "ENSO_CLOUD_CREDENTIALS_FILE" of
Nothing -> File.home / ".enso" / "credentials"
path -> File.new path

## PRIVATE
Reads the access token from the provided credentials file.

It supports both the old (raw string) and new (JSON) formats.
read_access_token (file:File) -> Text =
content = file.read_text
as_json = content.parse_json
# If this is not valid JSON, we assume old format - raw token.
if as_json.is_error then content else
# Otherwise, we extract the token from JSON:
as_json.get "access_token" if_missing=(Error.throw "Invalid credentials file format: missing field `access_token`.")

## PRIVATE
Root address for listing folders
directory_api = cloud_root_uri + "directories"
Expand Down

0 comments on commit 63622f7

Please sign in to comment.