@@ -21,6 +21,12 @@ use s3::creds::Credentials;
21
21
22
22
use url:: Url ;
23
23
24
+ #[ derive( Clone , Debug ) ]
25
+ pub struct AliasMap {
26
+ pub target : String ,
27
+ pub versions : Vec < String > ,
28
+ }
29
+
24
30
#[ derive( Clone , Debug ) ]
25
31
pub struct RouteConfig {
26
32
pub s3_public : Option < String > ,
@@ -31,6 +37,7 @@ pub struct RouteConfig {
31
37
pub s3_key : Option < String > ,
32
38
pub s3_secret : Option < String > ,
33
39
pub s3_prefix : Option < String > ,
40
+ pub version_alias_maps : Vec < AliasMap > ,
34
41
}
35
42
36
43
#[ derive( Clone , Debug , Eq ) ]
@@ -128,6 +135,7 @@ impl RouteConfig {
128
135
s3_key : None ,
129
136
s3_secret : None ,
130
137
s3_prefix : None ,
138
+ version_alias_maps : Vec :: new ( ) ,
131
139
}
132
140
}
133
141
@@ -151,9 +159,39 @@ impl RouteConfig {
151
159
// optional env vars
152
160
self . s3_prefix = read_from_env ( "S3_PREFIX" , false ) ?;
153
161
self . s3_public = read_from_env ( "S3_PUBLIC" , false ) ?;
162
+
154
163
let cache_ttl = read_from_env ( "CACHE_TTL" , false ) ?;
155
164
self . cache_ttl = cache_ttl. unwrap_or ( "900" . to_string ( ) ) . parse :: < u64 > ( ) ?;
156
165
166
+ // parse any version aliases
167
+ let version_alias_raw = match read_from_env ( "VERSION_ALIASES" , false ) ? {
168
+ Some ( raw) => raw,
169
+ None => "" . to_string ( ) ,
170
+ } ;
171
+ for field in version_alias_raw. split ( ';' ) {
172
+ let alias = field. to_string ( ) ;
173
+ if alias. contains ( ":" ) {
174
+ let mut alias_maj_fields = alias. split ( ':' ) . into_iter ( ) ;
175
+ let target = match alias_maj_fields. next ( ) {
176
+ Some ( t) => t. to_string ( ) ,
177
+ None => "" . to_string ( ) ,
178
+ } ;
179
+ let aliases_raw = match alias_maj_fields. next ( ) {
180
+ Some ( r) => r. to_string ( ) ,
181
+ None => "" . to_string ( ) ,
182
+ } ;
183
+ let mut aliases: Vec < String > = Vec :: new ( ) ;
184
+ for minor in aliases_raw. split ( ',' ) {
185
+ aliases. push ( minor. to_string ( ) )
186
+ }
187
+ let map = AliasMap {
188
+ target : target. to_string ( ) ,
189
+ versions : aliases,
190
+ } ;
191
+ self . version_alias_maps . push ( map) ;
192
+ }
193
+ }
194
+
157
195
return Ok ( ( ) ) ;
158
196
}
159
197
@@ -314,9 +352,17 @@ impl RouteCache {
314
352
return self . version_latest ( branch, arch) ;
315
353
}
316
354
355
+ let mut actual_version = version. clone ( ) ;
356
+ // First, we check for known aliases...
357
+ for alias in self . config . version_alias_maps . iter ( ) {
358
+ if alias. versions . contains ( & version) {
359
+ actual_version = alias. target . clone ( ) ;
360
+ }
361
+ }
362
+
317
363
// Otherwise just return requested version.
318
364
for route in self . routes . iter ( ) {
319
- if route. branch == branch && route. arch == arch && route. version == version {
365
+ if route. branch == branch && route. arch == arch && route. version == actual_version {
320
366
return Some ( route. clone ( ) ) ;
321
367
}
322
368
}
0 commit comments