@@ -2,8 +2,6 @@ import { ConfigService, useConfigService } from "@services/useConfigService.ts";
2
2
import {
3
3
createAuthOptions ,
4
4
createEndpoint ,
5
- createHeaders ,
6
- createOptions ,
7
5
httpDelete ,
8
6
httpGet ,
9
7
httpPostWithReturn ,
@@ -71,42 +69,40 @@ export interface ClientGeneration {
71
69
72
70
const createArtifact = async ( config : ConfigService , auth : AuthService , data : CreateArtifactData ) : Promise < ArtifactMetaData > => {
73
71
const baseHref : string = config . artifactsUrl ( ) ;
74
- const token : string | undefined = await auth . getToken ( ) ;
75
72
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts" , { groupId : data . groupId } ) ;
76
73
const options = await createAuthOptions ( auth ) ;
77
74
78
- const headers : any = createHeaders ( token ) ;
79
75
if ( data . id ) {
80
76
options . headers = {
81
77
...options . headers ,
82
78
"X-Registry-ArtifactId" : data . id
83
- }
79
+ } ;
84
80
}
85
81
if ( data . type ) {
86
82
options . headers = {
87
83
...options . headers ,
88
84
"X-Registry-ArtifactType" : data . type
89
- }
85
+ } ;
90
86
}
91
87
if ( data . sha ) {
92
88
options . headers = {
93
89
...options . headers ,
94
90
"X-Registry-Hash-Algorithm" : "SHA256" ,
95
91
"X-Registry-Content-Hash" : data . sha
96
- }
92
+ } ;
97
93
}
98
94
99
95
if ( data . fromURL ) {
100
96
options . headers = {
101
97
...options . headers ,
102
98
"Content-Type" : "application/create.extended+json"
103
- }
99
+ } ;
104
100
data . content = `{ "content": "${ data . fromURL } " }` ;
105
101
} else {
106
102
options . headers = {
107
103
...options . headers ,
108
104
"Content-Type" : contentType ( data . type , data . content ? data . content : "" )
109
- }
105
+ } ;
110
106
}
111
107
112
108
return httpPostWithReturn < any , ArtifactMetaData > ( endpoint , data . content , options ) ;
@@ -122,12 +118,12 @@ const createArtifactVersion = async (config: ConfigService, auth: AuthService, g
122
118
options . headers = {
123
119
...options . headers ,
124
120
"X-Registry-ArtifactType" : data . type
125
- }
121
+ } ;
126
122
}
127
123
options . headers = {
128
124
...options . headers ,
129
125
"Content-Type" : contentType ( data . type , data . content )
130
- }
126
+ } ;
131
127
return httpPostWithReturn < any , VersionMetaData > ( endpoint , data . content , options ) ;
132
128
} ;
133
129
@@ -236,7 +232,7 @@ const getArtifactVersionContent = async (config: ConfigService, auth: AuthServic
236
232
options . headers = {
237
233
...options . headers ,
238
234
"Accept" : "*"
239
- }
235
+ } ;
240
236
options . maxContentLength = 5242880 ; // TODO 5MB hard-coded, make this configurable?
241
237
options . responseType = "text" ;
242
238
options . transformResponse = ( data : any ) => data ;
@@ -263,9 +259,8 @@ const getArtifactRules = async (config: ConfigService, auth: AuthService, groupI
263
259
264
260
console . info ( "[GroupsService] Getting the list of rules for artifact: " , groupId , artifactId ) ;
265
261
const baseHref : string = config . artifactsUrl ( ) ;
266
- const token : string | undefined = await auth . getToken ( ) ;
267
262
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts/:artifactId/rules" , { groupId, artifactId } ) ;
268
- const options = createOptions ( createHeaders ( token ) ) ;
263
+ const options = await createAuthOptions ( auth ) ;
269
264
return httpGet < string [ ] > ( endpoint , options ) . then ( ruleTypes => {
270
265
return Promise . all ( ruleTypes . map ( rt => getArtifactRule ( config , auth , groupId , artifactId , rt ) ) ) ;
271
266
} ) ;
@@ -275,13 +270,12 @@ const getArtifactRule = async (config: ConfigService, auth: AuthService, groupId
275
270
groupId = normalizeGroupId ( groupId ) ;
276
271
277
272
const baseHref : string = config . artifactsUrl ( ) ;
278
- const token : string | undefined = await auth . getToken ( ) ;
279
273
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts/:artifactId/rules/:rule" , {
280
274
groupId,
281
275
artifactId,
282
276
rule : type
283
277
} ) ;
284
- const options = createOptions ( createHeaders ( token ) ) ;
278
+ const options = await createAuthOptions ( auth ) ;
285
279
return httpGet < Rule > ( endpoint , options ) ;
286
280
} ;
287
281
@@ -291,13 +285,12 @@ const createArtifactRule = async (config: ConfigService, auth: AuthService, grou
291
285
console . info ( "[GroupsService] Creating rule:" , type ) ;
292
286
293
287
const baseHref : string = config . artifactsUrl ( ) ;
294
- const token : string | undefined = await auth . getToken ( ) ;
295
288
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts/:artifactId/rules" , { groupId, artifactId } ) ;
296
289
const body : Rule = {
297
290
config : configValue ,
298
291
type
299
292
} ;
300
- const options = createOptions ( createHeaders ( token ) ) ;
293
+ const options = await createAuthOptions ( auth ) ;
301
294
return httpPostWithReturn ( endpoint , body , options ) ;
302
295
} ;
303
296
@@ -306,14 +299,13 @@ const updateArtifactRule = async (config: ConfigService, auth: AuthService, grou
306
299
307
300
console . info ( "[GroupsService] Updating rule:" , type ) ;
308
301
const baseHref : string = config . artifactsUrl ( ) ;
309
- const token : string | undefined = await auth . getToken ( ) ;
310
302
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts/:artifactId/rules/:rule" , {
311
303
groupId,
312
304
artifactId,
313
305
"rule" : type
314
306
} ) ;
315
307
const body : Rule = { config : configValue , type } ;
316
- const options = createOptions ( createHeaders ( token ) ) ;
308
+ const options = await createAuthOptions ( auth ) ;
317
309
return httpPutWithReturn < Rule , Rule > ( endpoint , body , options ) ;
318
310
} ;
319
311
@@ -322,13 +314,12 @@ const deleteArtifactRule = async (config: ConfigService, auth: AuthService, grou
322
314
323
315
console . info ( "[GroupsService] Deleting rule:" , type ) ;
324
316
const baseHref : string = config . artifactsUrl ( ) ;
325
- const token : string | undefined = await auth . getToken ( ) ;
326
317
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts/:artifactId/rules/:rule" , {
327
318
groupId,
328
319
artifactId,
329
320
"rule" : type
330
321
} ) ;
331
- const options = createOptions ( createHeaders ( token ) ) ;
322
+ const options = await createAuthOptions ( auth ) ;
332
323
return httpDelete ( endpoint , options ) ;
333
324
} ;
334
325
@@ -337,9 +328,8 @@ const deleteArtifact = async (config: ConfigService, auth: AuthService, groupId:
337
328
338
329
console . info ( "[GroupsService] Deleting artifact:" , groupId , artifactId ) ;
339
330
const baseHref : string = config . artifactsUrl ( ) ;
340
- const token : string | undefined = await auth . getToken ( ) ;
341
331
const endpoint : string = createEndpoint ( baseHref , "/groups/:groupId/artifacts/:artifactId" , { groupId, artifactId } ) ;
342
- const options = createOptions ( createHeaders ( token ) ) ;
332
+ const options = await createAuthOptions ( auth ) ;
343
333
return httpDelete ( endpoint , options ) ;
344
334
} ;
345
335
0 commit comments