2
2
using System ;
3
3
using System . Collections . Generic ;
4
4
using System . IO ;
5
+ using System . Linq ;
5
6
using System . Net ;
6
7
using System . Net . Http ;
7
8
using System . Text ;
@@ -21,6 +22,7 @@ internal class ImageOperations : IImageOperations
21
22
} ;
22
23
23
24
private const string RegistryAuthHeaderKey = "X-Registry-Auth" ;
25
+ private const string RegistryConfigHeaderKey = "X-Registry-Config" ;
24
26
private const string TarContentType = "application/x-tar" ;
25
27
private const string ImportFromBodySource = "-" ;
26
28
@@ -43,7 +45,7 @@ internal ImageOperations(DockerClient client)
43
45
return this . _client . JsonSerializer . DeserializeObject < ImagesListResponse [ ] > ( response . Body ) ;
44
46
}
45
47
46
- public Task < Stream > BuildImageFromDockerfileAsync ( Stream contents , ImageBuildParameters parameters , CancellationToken cancellationToken = default ( CancellationToken ) )
48
+ public Task BuildImageFromDockerfileAsync ( ImageBuildParameters parameters , Stream contents , IEnumerable < AuthConfig > authConfigs , IDictionary < string , string > headers , IProgress < JSONMessage > progress , CancellationToken cancellationToken = default ( CancellationToken ) )
47
49
{
48
50
if ( contents == null )
49
51
{
@@ -55,9 +57,34 @@ internal ImageOperations(DockerClient client)
55
57
throw new ArgumentNullException ( nameof ( parameters ) ) ;
56
58
}
57
59
60
+ HttpMethod httpMethod = HttpMethod . Post ;
61
+
58
62
var data = new BinaryRequestContent ( contents , TarContentType ) ;
63
+
59
64
IQueryString queryParameters = new QueryString < ImageBuildParameters > ( parameters ) ;
60
- return this . _client . MakeRequestForStreamAsync ( this . _client . NoErrorHandlers , HttpMethod . Post , "build" , queryParameters , data , cancellationToken ) ;
65
+
66
+ Dictionary < string , string > customHeaders = RegistryConfigHeaders ( authConfigs ) ;
67
+
68
+ if ( headers != null )
69
+ {
70
+ foreach ( string key in headers . Keys )
71
+ {
72
+ customHeaders [ key ] = headers [ key ] ;
73
+ }
74
+ }
75
+
76
+ return StreamUtil . MonitorResponseForMessagesAsync (
77
+ this . _client . MakeRequestForRawResponseAsync (
78
+ httpMethod ,
79
+ "build" ,
80
+ queryParameters ,
81
+ data ,
82
+ customHeaders ,
83
+ cancellationToken ) ,
84
+ this . _client ,
85
+ cancellationToken ,
86
+ progress
87
+ ) ;
61
88
}
62
89
63
90
public Task CreateImageAsync ( ImagesCreateParameters parameters , AuthConfig authConfig , IProgress < JSONMessage > progress , CancellationToken cancellationToken = default ( CancellationToken ) )
@@ -269,5 +296,17 @@ private Dictionary<string, string> RegistryAuthHeaders(AuthConfig authConfig)
269
296
}
270
297
} ;
271
298
}
299
+
300
+ private Dictionary < string , string > RegistryConfigHeaders ( IEnumerable < AuthConfig > authConfig )
301
+ {
302
+ var configDictionary = ( authConfig ?? new AuthConfig [ 0 ] ) . ToDictionary ( e => e . ServerAddress , e => e ) ;
303
+ return new Dictionary < string , string >
304
+ {
305
+ {
306
+ RegistryConfigHeaderKey ,
307
+ Convert . ToBase64String ( Encoding . UTF8 . GetBytes ( this . _client . JsonSerializer . SerializeObject ( configDictionary ) ) )
308
+ }
309
+ } ;
310
+ }
272
311
}
273
312
}
0 commit comments