1
- use crate :: requests:: * ;
2
- use azure_core:: error:: { ErrorKind , ResultExt } ;
3
- use azure_storage:: core:: clients:: { AsStorageClient , StorageAccountClient , StorageClient } ;
4
- use std:: fmt:: Debug ;
5
- use std:: sync:: Arc ;
1
+ use crate :: { operations:: * , QueueStoredAccessPolicy } ;
2
+ use azure_core:: {
3
+ error:: { ErrorKind , ResultExt } ,
4
+ prelude:: * ,
5
+ Context , Request , Response ,
6
+ } ;
7
+ use azure_storage:: core:: clients:: {
8
+ AsStorageClient , ServiceType , StorageAccountClient , StorageClient ,
9
+ } ;
10
+ use std:: { fmt:: Debug , sync:: Arc } ;
6
11
7
12
pub trait AsQueueClient < QN : Into < String > > {
8
13
fn queue_client ( & self , queue_name : QN ) -> Arc < QueueClient > ;
@@ -34,6 +39,16 @@ impl QueueClient {
34
39
} )
35
40
}
36
41
42
+ pub ( crate ) async fn send (
43
+ & self ,
44
+ context : & mut Context ,
45
+ request : & mut Request ,
46
+ ) -> azure_core:: Result < Response > {
47
+ self . storage_client
48
+ . send ( context, request, ServiceType :: Queue )
49
+ . await
50
+ }
51
+
37
52
pub ( crate ) fn storage_client ( & self ) -> & StorageClient {
38
53
self . storage_client . as_ref ( )
39
54
}
@@ -53,68 +68,77 @@ impl QueueClient {
53
68
54
69
/// Creates the queue.
55
70
pub fn create ( & self ) -> CreateQueueBuilder {
56
- CreateQueueBuilder :: new ( self )
71
+ CreateQueueBuilder :: new ( self . clone ( ) )
57
72
}
58
73
59
74
/// Deletes the queue.
60
75
pub fn delete ( & self ) -> DeleteQueueBuilder {
61
- DeleteQueueBuilder :: new ( self )
76
+ DeleteQueueBuilder :: new ( self . clone ( ) )
62
77
}
63
78
64
- /// Sets or clears the queue metadata. The metadata
65
- /// will be passed to the `execute` function of the returned struct.
66
- pub fn set_metadata ( & self ) -> SetQueueMetadataBuilder {
67
- SetQueueMetadataBuilder :: new ( self )
79
+ /// Sets or clears the queue metadata.
80
+ ///
81
+ /// Keep in mind that keys present on Azure but not included in the passed
82
+ /// metadata parameter will be deleted. If you want to keep the preexisting
83
+ /// key-value pairs, retrieve them with GetMetadata first and then
84
+ /// update/add to the received Metadata struct. Then pass the Metadata back
85
+ /// to SetQueueMetadata. If you just want to clear the metadata, just pass
86
+ /// an empty Metadata struct.
87
+ pub fn set_metadata ( & self , metadata : Metadata ) -> SetQueueMetadataBuilder {
88
+ SetQueueMetadataBuilder :: new ( self . clone ( ) , metadata)
68
89
}
69
90
70
91
/// Get the queue metadata.
92
+
71
93
pub fn get_metadata ( & self ) -> GetQueueMetadataBuilder {
72
- GetQueueMetadataBuilder :: new ( self )
94
+ GetQueueMetadataBuilder :: new ( self . clone ( ) )
73
95
}
74
96
75
97
/// Get the queue ACL. This call returns
76
98
/// all the stored access policies associated
77
99
/// to the current queue.
78
100
pub fn get_acl ( & self ) -> GetQueueACLBuilder {
79
- GetQueueACLBuilder :: new ( self )
101
+ GetQueueACLBuilder :: new ( self . clone ( ) )
80
102
}
81
103
82
- /// Set the queue ACL. You can call this function
83
- /// to change or remove already existing stored
84
- /// access policies by modifying the list returned
104
+ /// Set the queue ACL. You can call this function to change or remove
105
+ /// already existing stored access policies by modifying the list returned
85
106
/// by `get_acl`.
86
- pub fn set_acl ( & self ) -> SetQueueACLBuilder {
87
- SetQueueACLBuilder :: new ( self )
107
+ ///
108
+ /// While this SDK does not enforce any limit, keep in mind Azure supports a
109
+ /// limited number of stored access policies for each queue. More info here
110
+ /// [https://docs.microsoft.com/rest/api/storageservices/set-queue-acl#remarks](https://docs.microsoft.com/rest/api/storageservices/set-queue-acl#remarks).
111
+ pub fn set_acl ( & self , policies : Vec < QueueStoredAccessPolicy > ) -> SetQueueACLBuilder {
112
+ SetQueueACLBuilder :: new ( self . clone ( ) , policies)
88
113
}
89
114
90
115
/// Puts a message in the queue. The body will be passed
91
116
/// to the `execute` function of the returned struct.
92
- pub fn put_message ( & self ) -> PutMessageBuilder {
93
- PutMessageBuilder :: new ( self )
117
+ pub fn put_message < S : Into < String > > ( & self , message : S ) -> PutMessageBuilder {
118
+ PutMessageBuilder :: new ( self . clone ( ) , message . into ( ) )
94
119
}
95
120
96
121
/// Peeks, without removing, one or more messages.
97
122
pub fn peek_messages ( & self ) -> PeekMessagesBuilder {
98
- PeekMessagesBuilder :: new ( self )
123
+ PeekMessagesBuilder :: new ( self . clone ( ) )
99
124
}
100
125
101
126
/// Gets, shadowing them, one or more messages.
102
127
pub fn get_messages ( & self ) -> GetMessagesBuilder {
103
- GetMessagesBuilder :: new ( self )
128
+ GetMessagesBuilder :: new ( self . clone ( ) )
104
129
}
105
130
106
131
/// Removes all messages from the queue.
107
132
pub fn clear_messages ( & self ) -> ClearMessagesBuilder {
108
- ClearMessagesBuilder :: new ( self )
133
+ ClearMessagesBuilder :: new ( self . clone ( ) )
109
134
}
110
135
}
111
136
112
137
#[ cfg( test) ]
113
138
#[ cfg( feature = "test_integration" ) ]
114
139
mod integration_tests {
115
140
use super :: * ;
116
- use crate :: core:: prelude:: * ;
117
- use crate :: queue:: clients:: AsQueueClient ;
141
+ use crate :: { core:: prelude:: * , queue:: clients:: AsQueueClient } ;
118
142
119
143
fn get_emulator_client ( queue_name : & str ) -> Arc < QueueClient > {
120
144
let storage_account = StorageAccountClient :: new_emulator_default ( ) . storage_client ( ) ;
0 commit comments