-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: key not from file & other improvements #29
base: main
Are you sure you want to change the base?
Conversation
d3ed7c9
to
c0a45bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @chris13524. Thanks for the PR. I managed to spot a few minor things, hope this is not too much of a hustle to do the changes. Also would be great to bump up the version in Cargo to 0.9
, since there is a breaking change to access_token
return type.
HttpRequest(reqwest::Error), | ||
|
||
#[error("failed to send request")] | ||
HttpRequestUnsuccessful(StatusCode, std::result::Result<String, reqwest::Error>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::result::Result could be shorted to StdResult, since there is already an import on line 3
src/serv_account/errors.rs
Outdated
HttpJson(reqwest::Error), | ||
|
||
#[error("response returned non-Bearer auth access token: {0}")] | ||
AccessTokenNotBeaarer(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there is a typo in Beaa
rer
} | ||
|
||
// Account for clock skew or time to receive or process the response | ||
const LEEWAY: Duration = Duration::seconds(30); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This piece seems not to compile for me. Here is the error message that I am get
error[E0015]: cannot call non-const fn `chrono::Duration::seconds` in constants
--> src/serv_account/mod.rs:108:34
|
108 | const LEEWAY: Duration = Duration::seconds(30);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
```
|
||
Ok(token) | ||
let expires_at = Utc::now() + Duration::seconds(json.expires_in) - LEEWAY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the options to resolve the issue with Duration above would be to keep it simple and use ints:
Utc::now().timestamp() as u64 + json.expires_in - 30
Thanks for the review! I'm working on some fixes for the above as well as some other tweaks |
This adds support for constructing a
ServiceAccount
directly from aServiceAccountKey
, rather than from a file. It also:RwLock
to enable cloningServiceAccount
while re-using the current access token across threads/instances. Also allowsServiceAccount
to be used without needing to bemut
.ServiceAccountKey
and its fields public to allow parsing or constructing the struct from any source (e.g. string, bytes, etc.) and also allows the fields inside to be re-used by other modules (e.g. readingproject_id
necessary for FCM)ServiceAccountBuilder
to enable the use of a variety of constructors, including the ability to re-usereqwest::Client
across instantiations which enables sharing connection pools. Existingfrom_file()
anduser_email()
methods continue to work for backwards-compatibility, but the builder pattern is generally a better alternativeaccess_token()
now returnsAccessToken
instead of e.g."Bearer token"
which allows the use of reqwest's.bearer_token()
method without needing to parse-out the token. Also enables the invoker to see when the token will expire.from_file()
retained as a helper method and now returns aResult
type since file reading and parsing is performed in this function, rather than lazily inaccess_token()
. Also now accepts any path-compatible value, rather than just&str
.RsaKeyPair
inJwtToken
rather than inputs to improve efficiencyResolves #28