Skip to content
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

Diff tracker PR rebased on feature/track2 fork #2

Draft
wants to merge 83 commits into
base: jpalvarezl/feature/track2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
8d15041
fix azure_data_cosmos build with key_auth feature (#1802)
analogrelay Sep 16, 2024
29a36f6
AMQP changes for C++ Connection support (#1801)
LarryOsterman Sep 17, 2024
43bdca3
Use standard options with calling cargo (#1804)
hallipr Sep 18, 2024
2d5e159
Removed unsupported or undesirable credentials (#1807)
heaths Sep 19, 2024
b4ecd85
Add pre-reqs and tasks for launching a live version of the docs site …
analogrelay Sep 23, 2024
9dd612c
Give CODEOWNERS owners (#1819)
JimSuplizio Sep 24, 2024
9d5c324
Remove ClientSecretCredential, EnvironmentCredential (#1821)
heaths Sep 25, 2024
d97b0d1
[Cosmos] Add APIs to perform single-partition queries against a conta…
analogrelay Sep 26, 2024
9773819
Add more codeowners for Azure Cosmos DB (#1817)
Pilchie Sep 26, 2024
f1dedb4
Cache `BearerToken`s on `BearerTokenCredentialPolicy` (#1759)
vincenttran-msft Sep 26, 2024
7d1b96c
complete session implementation; C++ related changes (#1822)
LarryOsterman Sep 27, 2024
c877711
Always return `Result<Arc<Self>>` from `new` credential constructors …
heaths Sep 27, 2024
6709010
New inference crate builds
jpalvarezl Aug 29, 2024
ae57b1b
Added more dependencies
jpalvarezl Aug 29, 2024
897078b
Internal state of clients is setup
jpalvarezl Aug 30, 2024
67e5a12
Somehow hitting the noop client
jpalvarezl Aug 30, 2024
5b5e3a9
getting 200 but no content
jpalvarezl Aug 30, 2024
80e2853
format
jpalvarezl Sep 3, 2024
5157d81
Attempt at using the pipeline
jpalvarezl Sep 6, 2024
4967330
tried implementing custom type as policy and pass in the pipeline
jpalvarezl Sep 6, 2024
817cd3b
Works with policy
jpalvarezl Sep 6, 2024
9056e38
WIP
jpalvarezl Sep 10, 2024
d65edb4
Extracted client_options to a separate module
jpalvarezl Sep 12, 2024
0e9f8e2
Re-organized models
jpalvarezl Sep 12, 2024
060a944
Renamed new to with_key and provided context on request method
jpalvarezl Sep 12, 2024
3417181
Added api service version as a policy
jpalvarezl Sep 12, 2024
d6be9f3
Refactored clients
jpalvarezl Sep 12, 2024
f8b21a8
Added comment for clarity
jpalvarezl Sep 12, 2024
96eec97
More clarity in comments
jpalvarezl Sep 12, 2024
ba1490b
Added client option modules to differenciate between nonAzure and Azure
jpalvarezl Sep 12, 2024
c92cbe5
added module visibility
jpalvarezl Sep 12, 2024
12e61e4
Made auth classes private
jpalvarezl Sep 13, 2024
eff2f89
wip
jpalvarezl Sep 13, 2024
b07cece
cleanup
jpalvarezl Sep 13, 2024
5cd0925
Project compiles and runs, but request errors
jpalvarezl Sep 13, 2024
ff6cba0
Functionality restored
jpalvarezl Sep 13, 2024
bcba5b9
Running state after rebase
jpalvarezl Sep 13, 2024
053b4f7
Running state after rebase
jpalvarezl Sep 13, 2024
a2c1752
Adding comment for clarity
jpalvarezl Sep 13, 2024
35fd48c
OpenAIClient code builds
jpalvarezl Sep 13, 2024
b2fdf31
non-Azure OpenAI works again
jpalvarezl Sep 13, 2024
8836f2b
Old approach to streaming response not working yet
jpalvarezl Sep 13, 2024
e888582
Resolved one issue, but now having ownership problems
jpalvarezl Sep 13, 2024
74ac180
Streaming verified working with Azure
jpalvarezl Sep 13, 2024
69fcf6c
Added example for non Azure usage for streaming
jpalvarezl Sep 13, 2024
acbd3f3
Using correct method in examples for deserialization
jpalvarezl Sep 13, 2024
1e288ef
Added lifetime parameter for string slice to be able to move to lambda
jpalvarezl Sep 17, 2024
f9869ff
Added ctx for AAD and related sample
jpalvarezl Sep 18, 2024
4757c9f
Cleaned up imports
jpalvarezl Sep 18, 2024
af6ab14
Renamed methods to be guideline compliant
jpalvarezl Sep 18, 2024
53d23b0
Restored ChatCompletionStreamHandler struct
jpalvarezl Sep 18, 2024
1465a7b
stream mapping function handles errors better
jpalvarezl Sep 18, 2024
6349265
Ported tests for string_chunks
jpalvarezl Sep 18, 2024
624e988
Made crate level visible the BaseOpenAIClientMethods trait
jpalvarezl Sep 18, 2024
49a19cf
Extracted json request builder method
jpalvarezl Sep 19, 2024
becd225
Added unhappy path test
jpalvarezl Sep 19, 2024
3f8f4cd
Updated comment
jpalvarezl Sep 19, 2024
f471f29
Added crate readme
jpalvarezl Sep 19, 2024
711aa97
Example docs and comments
jpalvarezl Sep 19, 2024
48d7dfa
Added comments to crate::options module
jpalvarezl Sep 19, 2024
cf98e01
Added docs for models and renamed methods
jpalvarezl Sep 19, 2024
32f59ef
restricted visibility of EventHandler trait
jpalvarezl Sep 19, 2024
de711b6
Various visibility restrictions
jpalvarezl Sep 19, 2024
2c1a3c0
Added documentation for auth module
jpalvarezl Sep 19, 2024
a071db5
Documented helpers module
jpalvarezl Sep 19, 2024
cbfa466
wip
jpalvarezl Sep 19, 2024
ba93ea4
Added docs for azure openai client
jpalvarezl Sep 19, 2024
3eb7cac
Added docs for ChatCompletionsClient
jpalvarezl Sep 19, 2024
f22d74e
clients module documented
jpalvarezl Sep 19, 2024
811279b
renamed auth module to credentials
jpalvarezl Sep 30, 2024
b2b8f45
Removed usage of azure_core::Result in examples
jpalvarezl Sep 30, 2024
e427611
crate description correction
jpalvarezl Sep 30, 2024
3802d55
Update sdk/openai/inference/src/lib.rs
jpalvarezl Sep 30, 2024
984645b
request module flattening fixes
jpalvarezl Sep 30, 2024
a82e472
Added license header to source files
jpalvarezl Sep 30, 2024
687858a
rebase new changes to feature/track2 and changed from auth->credentia…
jpalvarezl Sep 30, 2024
611f716
Addressed clippy warnings and errors
jpalvarezl Sep 30, 2024
8f82cd1
Fixed tests in comments
jpalvarezl Sep 30, 2024
bc04acd
No longer holding reference to options in the base clients
jpalvarezl Sep 30, 2024
4240214
Broken struct link fixed
jpalvarezl Sep 30, 2024
fe004b7
Added openai to word list
jpalvarezl Sep 30, 2024
314dc75
More spell checks
jpalvarezl Sep 30, 2024
d148db8
more spell checks
jpalvarezl Sep 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye

USER vscode

# Install nightly toolchain to give access to nightly features for docs-site build.
RUN rustup toolchain install nightly

# Install pre-requisite tools
RUN cargo install \
cargo-watch \
http-server
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
{
"name": "Azure SDK for Rust",
"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
"build": {
"dockerfile": "Dockerfile"
},
"onCreateCommand": ".devcontainer/oncreate",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {},
Expand All @@ -20,4 +22,4 @@
]
}
}
}
}
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
# ServiceOwner: @Pilchie
# ServiceLabel: %Cosmos
# PRLabel: %Cosmos
/sdk/cosmos/ @analogrelay @Pilchie
/sdk/cosmos/ @analogrelay @Pilchie @kirankumarkolli @tvaron3 @FabianMeiswinkel @kundadebdatta

###########
# Eng Sys
###########
/eng/ @weshaggard @heaths @RickWinter
/.github/CODEOWNERS @RickWinter @ronniegeraghty @Azure/azure-sdk-eng
19 changes: 14 additions & 5 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"**/test-resources.bicep",
"**/test-resources.json",
".devcontainer/devcontainer.json",
".devcontainer/Dockerfile",
".devcontainer/oncreate",
".github/CODEOWNERS",
".github/dependabot.yml",
".vscode/cspell.json",
".vscode/extensions.json",
".vscode/tasks.json",
"NOTICE.txt",
"eng/",
"*.dict.txt",
Expand All @@ -21,6 +23,7 @@
"asyncoperation",
"azsdk",
"azurecli",
"Contoso",
"cplusplus",
"datalake",
"datetime",
Expand All @@ -29,13 +32,15 @@
"downcasted",
"downcasting",
"entra",
"endregion",
"etag",
"eventhub",
"eventhubs",
"hmac",
"iothub",
"keyvault",
"msrc",
"openai",
"pageable",
"pkce",
"pkcs",
Expand Down Expand Up @@ -63,6 +68,11 @@
"name": "cosmos",
"path": "../sdk/cosmos/.dict.txt",
"noSuggest": true
},
{
"name": "identity",
"path": "../sdk/identity/.dict.txt",
"noSuggest": true
}
],
"overrides": [
Expand Down Expand Up @@ -92,11 +102,10 @@
},
{
"filename": "sdk/identity/**",
"words": [
"adfs",
"azureauth",
"msal",
"imds"
"dictionaries": [
"crates",
"rust-custom",
"identity"
]
},
{
Expand Down
22 changes: 22 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"tasks": [
{
"label": "Start docs site (requires nightly)",
"options": {
"cwd": "${workspaceFolder}"
},
"command": "cargo",
"args": [
"watch",
"-s",
"RUSTDOCFLAGS=\"--cfg=docsrs --enable-index-page -Z unstable-options\" cargo +nightly doc --all-features --workspace --no-deps",
"-s",
"http-server --index --port 8080 ./target/doc"
],
"isBackground": true,
"problemMatcher": [
"$rustc"
]
}
]
}
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"eng/test/mock_transport",
"sdk/storage",
"sdk/storage/azure_storage_blob",
"sdk/openai/inference",
]

[workspace.package]
Expand Down
1 change: 1 addition & 0 deletions eng/dict/rust-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ newtype
repr
rustc
rustls
turbofish
6 changes: 3 additions & 3 deletions eng/scripts/Analyze-Code.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ Write-Host "Analyzing code with
$env:RUSTDOCFLAGS = "-D warnings"
$env:RUSTFLAGS = "-Dwarnings"

Invoke-LoggedCommand "cargo +$Toolchain check -p azure_core --no-default-features"
Invoke-LoggedCommand "cargo +$Toolchain check -p azure_core --no-default-features --keep-going"

Invoke-LoggedCommand "cargo +$Toolchain fmt --all -- --check"

Invoke-LoggedCommand "cargo +$Toolchain clippy --all"
Invoke-LoggedCommand "cargo +$Toolchain clippy --workspace --keep-going --no-deps"

Invoke-LoggedCommand "cargo +$Toolchain doc --all --no-deps"
Invoke-LoggedCommand "cargo +$Toolchain doc --workspace --no-deps"

# Verify package dependencies

Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust-version.workspace = true
[dependencies]
typespec = { workspace = true, features = ["http", "json"] }
typespec_client_core = { workspace = true, features = ["http", "json"] }
async-lock = { workspace = true }
async-trait.workspace = true
bytes.workspace = true
futures.workspace = true
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sdk/core/azure_core/src/hmac.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use crate::auth::Secret;
use crate::credentials::Secret;
#[cfg(any(feature = "hmac_rust", feature = "hmac_openssl"))]
use crate::{
base64,
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod options;
mod pipeline;
mod policies;

pub mod auth;
pub mod credentials;
pub mod headers;
pub mod lro;
pub mod request_options;
Expand Down
50 changes: 41 additions & 9 deletions sdk/core/azure_core/src/policies/bearer_token_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@
// Licensed under the MIT License.

use crate::{
auth::TokenCredential,
credentials::{AccessToken, TokenCredential},
error::{Error, ErrorKind},
headers::AUTHORIZATION,
policies::{Policy, PolicyResult},
Context, Request,
};
use async_lock::RwLock;
use async_trait::async_trait;
use std::sync::Arc;
use std::time::Duration;

#[derive(Debug, Clone)]
pub struct BearerTokenCredentialPolicy {
credential: Arc<dyn TokenCredential>,
scopes: Vec<String>,
access_token: Arc<RwLock<Option<AccessToken>>>,
}

/// Default timeout in seconds before refreshing a new token.
const DEFAULT_REFRESH_TIME: Duration = Duration::from_secs(120);

impl BearerTokenCredentialPolicy {
pub fn new<A, B>(credential: Arc<dyn TokenCredential>, scopes: A) -> Self
where
Expand All @@ -25,8 +32,21 @@ impl BearerTokenCredentialPolicy {
Self {
credential,
scopes: scopes.into_iter().map(|s| s.into()).collect(),
access_token: Arc::new(RwLock::new(None)),
}
}

fn scopes(&self) -> Vec<&str> {
self.scopes
.iter()
.map(String::as_str)
.collect::<Vec<&str>>()
}

async fn access_token(&self) -> Option<String> {
let access_token = self.access_token.read().await;
access_token.as_ref().map(|s| s.token.secret().to_string())
}
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
Expand All @@ -38,15 +58,27 @@ impl Policy for BearerTokenCredentialPolicy {
request: &mut Request,
next: &[Arc<dyn Policy>],
) -> PolicyResult {
let scopes = self
.scopes
.iter()
.map(|s| s.as_str())
.collect::<Vec<&str>>();
let access_token = self.credential.get_token(&scopes).await?;
let token = access_token.token.secret();
let access_token = self.access_token.read().await;

if let Some(token) = &(*access_token) {
if token.is_expired(Some(DEFAULT_REFRESH_TIME)) {
drop(access_token);
let mut access_token = self.access_token.write().await;
*access_token = Some(self.credential.get_token(&self.scopes()).await?);
}
} else {
drop(access_token);
let mut access_token = self.access_token.write().await;
*access_token = Some(self.credential.get_token(&self.scopes()).await?);
}

request.insert_header(AUTHORIZATION, format!("Bearer {token}"));
let access_token = self.access_token().await.ok_or_else(|| {
Error::message(
ErrorKind::Credential,
"The request failed due to an error while fetching the access token.",
)
})?;
request.insert_header(AUTHORIZATION, format!("Bearer {}", access_token));

next[0].send(ctx, request, &next[1..]).await
}
Expand Down
1 change: 1 addition & 0 deletions sdk/core/azure_core_amqp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fe2o3-amqp-cbs = { workspace = true, optional = true }
fe2o3-amqp-types = { workspace = true, optional = true }
serde_amqp = { workspace = true, optional = true }
serde_bytes = { workspace = true, optional = true }
uuid = { workspace = true }

[dev-dependencies]
tracing-subscriber = { workspace = true, features = ["env-filter"] }
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/azure_core_amqp/src/cbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ impl AmqpClaimsBasedSecurityApis for AmqpClaimsBasedSecurity {
}

impl AmqpClaimsBasedSecurity {
pub fn new(session: AmqpSession) -> Self {
Self {
implementation: CbsImplementation::new(session),
}
pub fn new(session: AmqpSession) -> Result<Self> {
Ok(Self {
implementation: CbsImplementation::new(session)?,
})
}
}
Loading