Skip to content

Commit

Permalink
fix metadata credentials again
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Bode committed Aug 23, 2017
1 parent 1f6c15c commit 6934ac0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/credentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ struct MetadataCredentials <: Credentials
scopes::Vector{String}
function MetadataCredentials(; url::AbstractString=METADATA_ROOT, service_account::AbstractString="default")
metadata = new(url, service_account)
try
metadata.project_id = get(metadata, "project-id"; context=:project)
metadata.client_email = get(metadata, "email"; context=:service_account)
metadata.scopes = split(get(metadata, "scopes"; context=:service_account), '\n')
project_id, client_email, scopes = try
(
get(metadata, "project-id"; context=:project),
get(metadata, "email"; context=:service_account),
split(chomp(get(metadata, "scopes"; context=:service_account)), '\n')
)
catch e
throw(CredentialError("Unable to contact metadata server"))
end
metadata
new(url, service_account, project_id, client_email, scopes)
end
end

Expand All @@ -52,7 +54,7 @@ function Base.get(credentials::MetadataCredentials, path::AbstractString; contex
throw(CredentialError("Unknown metadata context: $context"))
end
res = Requests.get(joinpath(url, path), headers=headers)
if statuscode(res) != 200
if Requests.statuscode(res) != 200
throw(CredentialError("Unable to obtain credentials from metadata server"))
end
String(res.data)
Expand Down

0 comments on commit 6934ac0

Please sign in to comment.