@@ -24,8 +24,8 @@ export class MicrocksContainer extends GenericContainer {
2424 private snapshots : string [ ] = [ ] ;
2525 private mainArtifacts : string [ ] = [ ] ;
2626 private secondaryArtifacts : string [ ] = [ ] ;
27- private mainRemoteArtifacts : string [ ] = [ ] ;
28- private secondaryRemoteArtifacts : string [ ] = [ ] ;
27+ private mainRemoteArtifacts : RemoteArtifact [ ] = [ ] ;
28+ private secondaryRemoteArtifacts : RemoteArtifact [ ] = [ ] ;
2929 private secrets : Secret [ ] = [ ] ;
3030
3131 constructor ( image = "quay.io/microcks/microcks-uber:1.12.0" ) {
@@ -59,21 +59,21 @@ export class MicrocksContainer extends GenericContainer {
5959 /**
6060 * Provide urls of remote artifacts that will be imported as primary or main ones within the Microcks container
6161 * once it will be started and healthy.
62- * @param {[String ] } remoteArtifactUrls The urls or remote artifacts (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
62+ * @param {[RemoteArtifact ] } remoteArtifactUrls Array of URLs (strings) or objects with {url, secretName} (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
6363 * @returns this
6464 */
65- public withMainRemoteArtifacts ( remoteArtifactUrls : string [ ] ) : this {
65+ public withMainRemoteArtifacts ( remoteArtifactUrls : RemoteArtifact [ ] ) : this {
6666 this . mainRemoteArtifacts = this . mainRemoteArtifacts . concat ( remoteArtifactUrls ) ;
6767 return this ;
6868 }
6969
7070 /**
7171 * Provide urls of remote artifacts that will be imported as secondary ones within the Microcks container
7272 * once it will be started and healthy.
73- * @param {[String ] } remoteArtifactUrls The furls or remote (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
73+ * @param {[RemoteArtifact ] } remoteArtifactUrls Array of URLs (strings) or objects with {url, secretName} (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
7474 * @returns this
7575 */
76- public withSecondaryRemoteArtifacts ( remoteArtifactUrls : string [ ] ) : this {
76+ public withSecondaryRemoteArtifacts ( remoteArtifactUrls : RemoteArtifact [ ] ) : this {
7777 this . secondaryRemoteArtifacts = this . secondaryRemoteArtifacts . concat ( remoteArtifactUrls ) ;
7878 return this ;
7979 }
@@ -115,12 +115,14 @@ export class MicrocksContainer extends GenericContainer {
115115 }
116116 // Load remote artifacts before local ones.
117117 for ( let i = 0 ; i < this . mainRemoteArtifacts . length ; i ++ ) {
118- await startedContainer . downloadAsMainArtifact ( this . mainRemoteArtifacts [ i ] ) ;
118+ const { url, secretName } = this . extractArtifactInfo ( this . mainRemoteArtifacts [ i ] ) ;
119+ await startedContainer . downloadAsMainArtifact ( url , secretName ) ;
119120 }
120121 for ( let i = 0 ; i < this . secondaryRemoteArtifacts . length ; i ++ ) {
121- await startedContainer . downloadAsSecondaryArtifact ( this . secondaryRemoteArtifacts [ i ] ) ;
122+ const { url, secretName } = this . extractArtifactInfo ( this . secondaryRemoteArtifacts [ i ] ) ;
123+ await startedContainer . downloadAsSecondaryArtifact ( url , secretName ) ;
122124 }
123- // Import artifacts declared in configuration.
125+ // Import artifacts declared in configuration.
124126 for ( let i = 0 ; i < this . mainArtifacts . length ; i ++ ) {
125127 await startedContainer . importAsMainArtifact ( this . mainArtifacts [ i ] ) ;
126128 }
@@ -133,6 +135,12 @@ export class MicrocksContainer extends GenericContainer {
133135
134136 return startedContainer ;
135137 }
138+
139+ private extractArtifactInfo ( artifact : RemoteArtifact ) : { url : string ; secretName ?: string } {
140+ return typeof artifact === 'string'
141+ ? { url : artifact }
142+ : { url : artifact . url , secretName : artifact . secretName } ;
143+ }
136144}
137145
138146export enum OAuth2GrantType {
@@ -287,6 +295,11 @@ export interface DailyInvocationStatistic {
287295 minuteCount : { string : number } ;
288296}
289297
298+ export type RemoteArtifact = string | {
299+ url : string ;
300+ secretName ?: string ;
301+ }
302+
290303
291304export class StartedMicrocksContainer extends AbstractStartedContainer {
292305 private readonly httpPort : number ;
@@ -439,17 +452,17 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
439452 * @param {String } remoteArtifactUrl The URL to remote artifact (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
440453 * @returns Success or error via Promise
441454 */
442- public async downloadAsMainArtifact ( remoteArtifactUrl : string ) : Promise < void > {
443- return this . downloadArtifact ( remoteArtifactUrl , true ) ;
455+ public async downloadAsMainArtifact ( remoteArtifactUrl : string , secretName ?: string ) : Promise < void > {
456+ return this . downloadArtifact ( remoteArtifactUrl , true , secretName ) ;
444457 }
445458
446459 /**
447460 * Download a remote artifact as a secondary one within the Microcks container.
448461 * @param {String } remoteArtifactUrl The URL to remote artifact (OpenAPI, Postman collection, Protobuf, GraphQL schema, ...)
449462 * @returns Success or error via Promise
450463 */
451- public async downloadAsSecondaryArtifact ( remoteArtifactUrl : string ) : Promise < void > {
452- return this . downloadArtifact ( remoteArtifactUrl , false ) ;
464+ public async downloadAsSecondaryArtifact ( remoteArtifactUrl : string , secretName ?: string ) : Promise < void > {
465+ return this . downloadArtifact ( remoteArtifactUrl , false , secretName ) ;
453466 }
454467
455468 /**
@@ -597,7 +610,6 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
597610 return invocationStats . dailyCount ;
598611 }
599612
600-
601613 private async importArtifact ( artifactPath : string , mainArtifact : boolean ) : Promise < void > {
602614 const isFile = await this . isFile ( artifactPath ) ;
603615 if ( ! isFile ) {
@@ -613,11 +625,14 @@ export class StartedMicrocksContainer extends AbstractStartedContainer {
613625 }
614626 }
615627
616- private async downloadArtifact ( remoteArtifactUrl : string , mainArtifact : boolean ) : Promise < void > {
628+ private async downloadArtifact ( remoteArtifactUrl : string , mainArtifact : boolean , secretName ?: string ) : Promise < void > {
617629 let formBody = new URLSearchParams ( {
618630 "mainArtifact" : String ( mainArtifact ) ,
619631 "url" : remoteArtifactUrl
620632 } ) ;
633+ if ( secretName ) {
634+ formBody . append ( "secretName" , secretName ) ;
635+ }
621636
622637 // Prepare headers with content type and length.
623638 const headers : Record < string , string > = {
0 commit comments