17
17
* under the License.
18
18
*/
19
19
20
+ using System ;
20
21
using System . Collections . Generic ;
21
22
using System . Text ;
23
+ using System . Text . RegularExpressions ;
22
24
23
25
using Aliyun . Acs . Core . Auth ;
24
26
using Aliyun . Acs . Core . Http ;
@@ -36,12 +38,15 @@ public abstract class AcsRequest<T> : HttpRequest
36
38
37
39
private Dictionary < string , string > domainParameters = new Dictionary < string , string > ( ) ;
38
40
39
- public string ProductNetwork = "public" ;
41
+ private string productNetwork = "public" ;
42
+
43
+ private string productSuffix ;
40
44
41
45
private ProtocolType protocol = ProtocolType . HTTP ;
42
46
43
47
private Dictionary < string , string > queryParameters = new Dictionary < string , string > ( ) ;
44
48
49
+ private string regionId ;
45
50
46
51
public string StringToSign ;
47
52
private UserAgent userAgentConfig ;
@@ -56,13 +61,62 @@ public AcsRequest(string product) : base(null)
56
61
public virtual string Product { get ; set ; }
57
62
public virtual string Version { get ; set ; }
58
63
public virtual string ActionName { get ; set ; }
59
- public virtual string RegionId { get ; set ; }
64
+ public virtual string RegionId
65
+ {
66
+ get
67
+ {
68
+ return regionId ;
69
+ }
70
+ set
71
+ {
72
+ var match = Regex . Match ( value , "^[a-zA-Z0-9_-]*$" ) ;
73
+ if ( ! match . Success )
74
+ {
75
+ throw new ArgumentException ( "regionId is invalid" , "regionId" ) ;
76
+ }
77
+ regionId = value ;
78
+ }
79
+ }
60
80
public virtual string SecurityToken { get ; set ; }
61
81
public ISignatureComposer Composer { get ; set ; }
62
82
public string LocationProduct { get ; set ; }
63
83
public string LocationEndpointType { get ; set ; }
64
84
public ProductDomain ProductDomain { get ; set ; }
65
85
86
+ public string ProductNetwork
87
+ {
88
+ get
89
+ {
90
+ return productNetwork ;
91
+ }
92
+ set
93
+ {
94
+ var match = Regex . Match ( value , "^[a-zA-Z0-9_-]+$" ) ;
95
+ if ( ! match . Success )
96
+ {
97
+ throw new ArgumentException ( "productNetwork is invalid" , "productNetwork" ) ;
98
+ }
99
+ productNetwork = value ;
100
+ }
101
+ }
102
+
103
+ public string ProductSuffix
104
+ {
105
+ get
106
+ {
107
+ return productSuffix ;
108
+ }
109
+ set
110
+ {
111
+ var match = Regex . Match ( value , "^[a-zA-Z0-9_-]+$" ) ;
112
+ if ( ! match . Success )
113
+ {
114
+ throw new ArgumentException ( "productSuffix is invalid" , "productSuffix" ) ;
115
+ }
116
+ productSuffix = value ;
117
+ }
118
+ }
119
+
66
120
public virtual FormatType AcceptFormat
67
121
{
68
122
get { return acceptFormat ; }
@@ -110,13 +164,13 @@ public void SetProductDomain(string endpoint = "")
110
164
111
165
if ( endpoint != "" && ProductDomain == null )
112
166
{
113
- ProductDomain = new ProductDomain { ProductName = Product , DomainName = endpoint } ;
167
+ ProductDomain = new ProductDomain { ProductName = Product , DomainName = endpoint } ;
114
168
}
115
169
}
116
170
117
171
public void SetEndpoint ( string endpoint )
118
172
{
119
- ProductDomain = new ProductDomain { ProductName = Product , DomainName = endpoint } ;
173
+ ProductDomain = new ProductDomain { ProductName = Product , DomainName = endpoint } ;
120
174
}
121
175
122
176
public string GetProductEndpoint ( )
@@ -137,24 +191,33 @@ public string GetProductEndpoint()
137
191
var endpoint = "" ;
138
192
if ( ProductEndpointType == "central" )
139
193
{
140
- endpoint = "<product_id><network>.aliyuncs.com" ;
194
+ endpoint = "<product_id><suffix>< network>.aliyuncs.com" ;
141
195
}
142
196
else if ( ProductEndpointType == "regional" )
143
197
{
144
- endpoint = "<product_id><network>.<region_id>.aliyuncs.com" ;
198
+ endpoint = "<product_id><suffix>< network>.<region_id>.aliyuncs.com" ;
145
199
endpoint = endpoint . Replace ( "<region_id>" , RegionId ) ;
146
200
}
147
201
202
+ if ( string . IsNullOrWhiteSpace ( ProductSuffix ) )
203
+ {
204
+ endpoint = endpoint . Replace ( "<suffix>" , string . Empty ) ;
205
+ }
206
+ else
207
+ {
208
+ endpoint = endpoint . Replace ( "<suffix>" , ProductSuffix ) ;
209
+ }
210
+
148
211
if ( endpoint == "" )
149
212
{
150
213
return "" ;
151
214
}
152
215
153
216
endpoint = endpoint . Replace ( "<product_id>" , Product . ToLower ( ) ) ;
154
217
155
- endpoint = ProductNetwork == "public"
156
- ? endpoint . Replace ( "<network>" , "" )
157
- : endpoint . Replace ( "<network>" , "-" + ProductNetwork ) ;
218
+ endpoint = ProductNetwork == "public" ?
219
+ endpoint . Replace ( "<network>" , "" ) :
220
+ endpoint . Replace ( "<network>" , "-" + ProductNetwork ) ;
158
221
159
222
return endpoint ;
160
223
}
0 commit comments