Skip to content

Commit

Permalink
remove ResourceContext until we need other fields
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay authored Oct 21, 2024
1 parent f18f0e4 commit 2e07ccb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use azure_core::{
use std::sync::Arc;
use tracing::trace;

use crate::pipeline::{signature_target::SignatureTarget, ResourceContext};
use crate::{pipeline::signature_target::SignatureTarget, resource_context::ResourceLink};

use crate::utils::url_encode;

Expand Down Expand Up @@ -71,14 +71,14 @@ impl Policy for AuthorizationPolicy {

let time_nonce = OffsetDateTime::now_utc();

let resource_context: &ResourceContext = ctx
let resource_link: &ResourceLink = ctx
.value()
.expect("ResourceContext should have been provided by CosmosPipeline");

let auth = generate_authorization(
&self.credential,
request.url(),
SignatureTarget::new(*request.method(), &resource_context.link, time_nonce),
SignatureTarget::new(*request.method(), resource_link, time_nonce),
)
.await?;

Expand Down
10 changes: 5 additions & 5 deletions sdk/cosmos/azure_data_cosmos/src/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use azure_core::{Context, Pager, Request};
use serde::de::DeserializeOwned;
use typespec_client_core::http::PagerResult;

use crate::{constants, resource_context::ResourceContext, Query};
use crate::{constants, resource_context::ResourceLink, Query};

/// Newtype that wraps an Azure Core pipeline to provide a Cosmos-specific pipeline which configures our authorization policy and enforces that a [`ResourceType`] is set on the context.
#[derive(Debug, Clone)]
Expand All @@ -35,17 +35,17 @@ impl CosmosPipeline {
&self,
ctx: azure_core::Context<'_>,
request: &mut azure_core::Request,
resource_context: impl Into<ResourceContext>,
resource_link: ResourceLink,
) -> azure_core::Result<azure_core::Response<T>> {
let ctx = ctx.with_value(resource_context.into());
let ctx = ctx.with_value(resource_link);
self.0.send(&ctx, request).await
}

pub fn send_query_request<T: DeserializeOwned>(
&self,
query: Query,
mut base_request: Request,
resource_context: impl Into<ResourceContext>,
resource_link: ResourceLink,
) -> azure_core::Result<Pager<T>> {
base_request.insert_header(constants::QUERY, "True");
base_request.add_mandatory_header(&constants::QUERY_CONTENT_TYPE);
Expand All @@ -54,7 +54,7 @@ impl CosmosPipeline {
// We have to double-clone here.
// First we clone the pipeline to pass it in to the closure
let pipeline = self.0.clone();
let context = Context::new().with_value(resource_context.into());
let context = Context::new().with_value(resource_link);
Ok(Pager::from_callback(move |continuation| {
// Then we have to clone it again to pass it in to the async block.
// This is because Pageable can't borrow any data, it has to own it all.
Expand Down
12 changes: 0 additions & 12 deletions sdk/cosmos/azure_data_cosmos/src/resource_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,6 @@ impl ResourceLink {
}
}

/// Provides the context necessary to authorize a Cosmos DB request, and control other headers expected by Cosmos DB.
pub struct ResourceContext {
pub link: ResourceLink,
// There will be more options here later, like "is_write_operation" for handling certain headers.
}

impl From<ResourceLink> for ResourceContext {
fn from(link: ResourceLink) -> Self {
Self { link }
}
}

#[cfg(test)]
mod tests {
use crate::resource_context::{ResourceLink, ResourceType};
Expand Down

0 comments on commit 2e07ccb

Please sign in to comment.