1- use crate :: { clients:: ServiceType , StorageCredentials } ;
2- use once_cell:: sync:: Lazy ;
1+ use crate :: clients:: ServiceType ;
32use std:: convert:: TryFrom ;
43use url:: Url ;
54
@@ -8,22 +7,13 @@ use url::Url;
87#[ derive( Debug , Clone ) ]
98pub enum CloudLocation {
109 /// Azure public cloud
11- Public {
12- account : String ,
13- credentials : StorageCredentials ,
14- } ,
10+ Public { account : String } ,
1511 /// Azure China cloud
16- China {
17- account : String ,
18- credentials : StorageCredentials ,
19- } ,
12+ China { account : String } ,
2013 /// Use the well-known emulator
2114 Emulator { address : String , port : u16 } ,
2215 /// A custom base URL
23- Custom {
24- uri : String ,
25- credentials : StorageCredentials ,
26- } ,
16+ Custom { uri : String } ,
2717}
2818
2919impl CloudLocation {
@@ -51,15 +41,6 @@ impl CloudLocation {
5141 } ;
5242 Ok ( url:: Url :: parse ( & url) ?)
5343 }
54-
55- pub fn credentials ( & self ) -> & StorageCredentials {
56- match self {
57- CloudLocation :: Public { credentials, .. }
58- | CloudLocation :: China { credentials, .. }
59- | CloudLocation :: Custom { credentials, .. } => credentials,
60- CloudLocation :: Emulator { .. } => & EMULATOR_CREDENTIALS ,
61- }
62- }
6344}
6445
6546impl TryFrom < & Url > for CloudLocation {
@@ -68,11 +49,6 @@ impl TryFrom<&Url> for CloudLocation {
6849 // TODO: This only works for Public and China clouds.
6950 // ref: https://github.com/Azure/azure-sdk-for-rust/issues/502
7051 fn try_from ( url : & Url ) -> azure_core:: Result < Self > {
71- let credentials = match url. query ( ) {
72- Some ( token) => StorageCredentials :: sas_token ( token) ?,
73- None => StorageCredentials :: Anonymous ,
74- } ;
75-
7652 let host = url. host_str ( ) . ok_or_else ( || {
7753 azure_core:: Error :: with_message ( azure_core:: error:: ErrorKind :: DataConversion , || {
7854 "unable to find the target host in the URL"
@@ -92,14 +68,8 @@ impl TryFrom<&Url> for CloudLocation {
9268 let rest = domain. join ( "." ) ;
9369
9470 match rest. as_str ( ) {
95- "core.windows.net" => Ok ( CloudLocation :: Public {
96- account,
97- credentials,
98- } ) ,
99- "core.chinacloudapi.cn" => Ok ( CloudLocation :: China {
100- account,
101- credentials,
102- } ) ,
71+ "core.windows.net" => Ok ( CloudLocation :: Public { account } ) ,
72+ "core.chinacloudapi.cn" => Ok ( CloudLocation :: China { account } ) ,
10373 _ => Err ( azure_core:: Error :: with_message (
10474 azure_core:: error:: ErrorKind :: DataConversion ,
10575 || format ! ( "URL refers to a domain that is not a Public or China domain: {host}" ) ,
@@ -108,10 +78,6 @@ impl TryFrom<&Url> for CloudLocation {
10878 }
10979}
11080
111- pub static EMULATOR_CREDENTIALS : Lazy < StorageCredentials > = Lazy :: new ( || {
112- StorageCredentials :: Key ( EMULATOR_ACCOUNT . to_owned ( ) , EMULATOR_ACCOUNT_KEY . to_owned ( ) )
113- } ) ;
114-
11581/// The well-known account used by Azurite and the legacy Azure Storage Emulator.
11682/// <https://docs.microsoft.com/azure/storage/common/storage-use-azurite#well-known-storage-account-and-key>
11783pub const EMULATOR_ACCOUNT : & str = "devstoreaccount1" ;
@@ -133,9 +99,6 @@ mod tests {
13399 let cloud_location: CloudLocation = ( & public_with_token) . try_into ( ) ?;
134100 assert_eq ! ( public_without_token, cloud_location. url( ServiceType :: Blob ) ?) ;
135101
136- let creds = cloud_location. credentials ( ) ;
137- assert ! ( matches!( creds, & StorageCredentials :: SASToken ( _) ) ) ;
138-
139102 let file_url = Url :: parse ( "file://tmp/test.txt" ) ?;
140103 let result: azure_core:: Result < CloudLocation > = ( & file_url) . try_into ( ) ;
141104 assert ! ( result. is_err( ) ) ;
0 commit comments