Skip to content

Commit 291b370

Browse files
Merge pull request #148 from code0-tech/#147-auth-metadata
added auth header to status and usage
2 parents 881b1fc + 15d74c1 commit 291b370

3 files changed

Lines changed: 52 additions & 23 deletions

File tree

crates/taurus/src/client/runtime_status.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::time::{SystemTime, UNIX_EPOCH};
22

3-
use code0_flow::flow_service::retry::create_channel_with_retry;
4-
use tonic::transport::Channel;
3+
use code0_flow::flow_service::{
4+
auth::get_authorization_metadata, retry::create_channel_with_retry,
5+
};
6+
use tonic::{Extensions, Request, transport::Channel};
57
use tucana::{
68
aquila::{
79
RuntimeStatusUpdateRequest, runtime_status_service_client::RuntimeStatusServiceClient,
@@ -14,23 +16,31 @@ pub struct TaurusRuntimeStatusService {
1416
channel: Channel,
1517
identifier: String,
1618
features: Vec<RuntimeFeature>,
19+
aquila_token: String,
1720
}
1821

1922
impl TaurusRuntimeStatusService {
2023
pub async fn from_url(
2124
aquila_url: String,
25+
aquila_token: String,
2226
identifier: String,
2327
features: Vec<RuntimeFeature>,
2428
) -> Self {
2529
let channel = create_channel_with_retry("Aquila", aquila_url).await;
26-
Self::new(channel, identifier, features)
30+
Self::new(channel, aquila_token, identifier, features)
2731
}
2832

29-
pub fn new(channel: Channel, identifier: String, features: Vec<RuntimeFeature>) -> Self {
33+
pub fn new(
34+
channel: Channel,
35+
aquila_token: String,
36+
identifier: String,
37+
features: Vec<RuntimeFeature>,
38+
) -> Self {
3039
TaurusRuntimeStatusService {
3140
channel,
3241
identifier,
3342
features,
43+
aquila_token,
3444
}
3545
}
3646

@@ -50,14 +60,18 @@ impl TaurusRuntimeStatusService {
5060
}
5161
};
5262

53-
let request = RuntimeStatusUpdateRequest {
54-
status: Some(Status::ExecutionRuntimeStatus(ExecutionRuntimeStatus {
55-
status: status.into(),
56-
timestamp: timestamp as i64,
57-
identifier: self.identifier.clone(),
58-
features: self.features.clone(),
59-
})),
60-
};
63+
let request = Request::from_parts(
64+
get_authorization_metadata(&self.aquila_token),
65+
Extensions::new(),
66+
RuntimeStatusUpdateRequest {
67+
status: Some(Status::ExecutionRuntimeStatus(ExecutionRuntimeStatus {
68+
status: status.into(),
69+
timestamp: timestamp as i64,
70+
identifier: self.identifier.clone(),
71+
features: self.features.clone(),
72+
})),
73+
},
74+
);
6175

6276
match client.update(request).await {
6377
Ok(response) => {

crates/taurus/src/client/runtime_usage.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
1-
use code0_flow::flow_service::retry::create_channel_with_retry;
2-
use tonic::transport::Channel;
1+
use code0_flow::flow_service::{
2+
auth::get_authorization_metadata, retry::create_channel_with_retry,
3+
};
4+
use tonic::{Extensions, Request, transport::Channel};
35
use tucana::{
46
aquila::{RuntimeUsageRequest, runtime_usage_service_client::RuntimeUsageServiceClient},
57
shared::RuntimeUsage,
68
};
79

810
pub struct TaurusRuntimeUsageService {
911
channel: Channel,
12+
aquila_token: String,
1013
}
1114

1215
impl TaurusRuntimeUsageService {
13-
pub async fn from_url(aquila_url: String) -> Self {
16+
pub async fn from_url(aquila_url: String, aquila_token: String) -> Self {
1417
let channel = create_channel_with_retry("Aquila", aquila_url).await;
15-
TaurusRuntimeUsageService { channel }
18+
TaurusRuntimeUsageService {
19+
channel,
20+
aquila_token,
21+
}
1622
}
1723

1824
pub async fn update_runtime_usage(&self, runtime_usage: RuntimeUsage) {
19-
log::info!("Updating the current Runtime Status!");
25+
log::info!("Updating the current Runtime Usage!");
2026
let mut client = RuntimeUsageServiceClient::new(self.channel.clone());
2127

22-
let request = RuntimeUsageRequest {
23-
runtime_usage: vec![runtime_usage],
24-
};
28+
let request = Request::from_parts(
29+
get_authorization_metadata(&self.aquila_token),
30+
Extensions::new(),
31+
RuntimeUsageRequest {
32+
runtime_usage: vec![runtime_usage],
33+
},
34+
);
2535

2636
match client.update(request).await {
2737
Ok(response) => {
2838
log::info!(
29-
"Was the update of the RuntimeStatus accepted by Sagittarius? {}",
39+
"Was the update of the RuntimeUsage accepted by Sagittarius? {}",
3040
response.into_inner().success
3141
);
3242
}
3343
Err(err) => {
34-
log::error!("Failed to update RuntimeStatus: {:?}", err);
44+
log::error!("Failed to update RuntimeUsage: {:?}", err);
3545
}
3646
}
3747
}

crates/taurus/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,16 @@ async fn main() {
116116
.send()
117117
.await;
118118

119-
let usage_service = TaurusRuntimeUsageService::from_url(config.aquila_url.clone()).await;
119+
let usage_service = TaurusRuntimeUsageService::from_url(
120+
config.aquila_url.clone(),
121+
config.aquila_token.clone(),
122+
)
123+
.await;
120124
runtime_usage_service = Some(usage_service);
121125

122126
let status_service = TaurusRuntimeStatusService::from_url(
123127
config.aquila_url.clone(),
128+
config.aquila_token.clone(),
124129
"taurus".into(),
125130
vec![RuntimeFeature {
126131
name: vec![Translation {

0 commit comments

Comments
 (0)