Make service_account example compile and add README with warning

This commit is contained in:
Lewin Bormann
2021-03-04 11:37:50 +01:00
parent 00574f278b
commit 88e36b19f9
2 changed files with 14 additions and 6 deletions

View File

@@ -0,0 +1,8 @@
# `service_account` example
NOTE that this example uses yup-oauth2 v1. To see how the new asynchronous
versions (>4) can be used, please take a look at
[async-google-apis](https://github.com/dermesser/async-google-apis) and the
examples linked from there.
The API has changed a lot!

View File

@@ -54,6 +54,7 @@ fn check_or_create_topic(methods: &PubsubMethods) -> Topic {
let topic = pubsub::Topic {
name: Some(TOPIC_NAME.to_string()),
labels: None,
..Default::default()
};
let result = methods.topics_create(topic, TOPIC_NAME).doit().unwrap();
result.1
@@ -71,11 +72,8 @@ fn check_or_create_subscription(methods: &PubsubMethods) -> Subscription {
let sub = pubsub::Subscription {
topic: Some(TOPIC_NAME.to_string()),
ack_deadline_seconds: Some(30),
push_config: None,
message_retention_duration: None,
retain_acked_messages: None,
name: Some(SUBSCRIPTION_NAME.to_string()),
labels: None,
..Default::default()
};
let (_resp, sub) = methods
.subscriptions_create(sub, SUBSCRIPTION_NAME)
@@ -181,13 +179,15 @@ fn publish_stuff(methods: &PubsubMethods, message: &str) {
fn main() {
let client_secret =
oauth::service_account_key_from_file(&"pubsub-auth.json".to_string()).unwrap();
let mut access = oauth::ServiceAccountAccess::new(client_secret).build();
let client =
hyper::Client::with_connector(HttpsConnector::new(NativeTlsClient::new().unwrap()));
let mut access = oauth::ServiceAccountAccess::new(client_secret, client);
use yup_oauth2::GetToken;
println!(
"{:?}",
access
.token(vec!["https://www.googleapis.com/auth/pubsub"])
.token(vec![&"https://www.googleapis.com/auth/pubsub"])
.unwrap()
);