@@ -16,7 +16,6 @@ import (
1616
1717 "github.com/ARM-software/embedded-development-services-client-utils/utils/api"
1818 paginationUtils "github.com/ARM-software/embedded-development-services-client-utils/utils/pagination"
19- "github.com/ARM-software/embedded-development-services-client/client"
2019 "github.com/ARM-software/golang-utils/utils/collection/pagination"
2120 "github.com/ARM-software/golang-utils/utils/commonerrors"
2221 "github.com/ARM-software/golang-utils/utils/filesystem"
@@ -29,17 +28,17 @@ const relativePathKey = "Relative Path"
2928
3029type (
3130 // GetArtefactManagersFirstPageFunc defines the function which can retrieve the first page of artefact managers.
32- GetArtefactManagersFirstPageFunc = func (ctx context.Context , job string ) (* client. ArtefactManagerCollection , * http.Response , error )
31+ GetArtefactManagersFirstPageFunc [ D LinkData , L Links [ D ], C Collection [ D , L ]] = func (ctx context.Context , job string ) (C , * http.Response , error )
3332 // FollowLinkToArtefactManagersPageFunc is a function able to follow a link to an artefact manager page.
34- FollowLinkToArtefactManagersPageFunc = func (ctx context.Context , link * client. HalLinkData ) (* client. ArtefactManagerCollection , * http.Response , error )
33+ FollowLinkToArtefactManagersPageFunc [ D LinkData , L Links [ D ], C Collection [ D , L ]] = func (ctx context.Context , link D ) (C , * http.Response , error )
3534 // GetArtefactManagerFunc is a function which retrieves information about an artefact manager.
36- GetArtefactManagerFunc = func (ctx context.Context , job , artefact string ) (* client. ArtefactManagerItem , * http.Response , error )
35+ GetArtefactManagerFunc [ M Manager ] = func (ctx context.Context , job , artefact string ) (M , * http.Response , error )
3736 // GetArtefactContentFunc is a function able to return the content of any artefact managers.
3837 GetArtefactContentFunc = func (ctx context.Context , job , artefactID string ) (* os.File , * http.Response , error )
3938)
4039
41- func determineArtefactDestination (outputDir string , maintainTree bool , item * client. ArtefactManagerItem ) (artefactFileName string , destinationDir string , err error ) {
42- if item == nil {
40+ func determineArtefactDestination [ M Manager ] (outputDir string , maintainTree bool , item M ) (artefactFileName string , destinationDir string , err error ) {
41+ if any ( item ) == nil {
4342 err = fmt .Errorf ("%w: missing artefact item" , commonerrors .ErrUndefined )
4443 return
4544 }
@@ -76,27 +75,41 @@ func determineArtefactDestination(outputDir string, maintainTree bool, item *cli
7675 return
7776}
7877
79- type ArtefactManager struct {
80- getArtefactManagerFunc GetArtefactManagerFunc
78+ type ArtefactManager [
79+ M Manager ,
80+ D LinkData ,
81+ L Links [D ],
82+ C Collection [D , L ],
83+ ] struct {
84+ getArtefactManagerFunc GetArtefactManagerFunc [M ]
8185 getArtefactContentFunc GetArtefactContentFunc
82- getArtefactManagersFirstPageFunc GetArtefactManagersFirstPageFunc
83- getArtefactManagersFollowLinkFunc FollowLinkToArtefactManagersPageFunc
86+ getArtefactManagersFirstPageFunc GetArtefactManagersFirstPageFunc [ D , L , C ]
87+ getArtefactManagersFollowLinkFunc FollowLinkToArtefactManagersPageFunc [ D , L , C ]
8488}
8589
8690// NewArtefactManager returns an artefact manager.
87- func NewArtefactManager (getArtefactManagersFirstPage GetArtefactManagersFirstPageFunc , getArtefactsManagersPage FollowLinkToArtefactManagersPageFunc , getArtefactManager GetArtefactManagerFunc , getOutputArtefact GetArtefactContentFunc ) IArtefactManager {
88- return & ArtefactManager {
91+ func NewArtefactManager [
92+ M Manager ,
93+ D LinkData ,
94+ L Links [D ],
95+ C Collection [D , L ],
96+ ](
97+ getArtefactManagersFirstPage GetArtefactManagersFirstPageFunc [D , L , C ],
98+ getArtefactsManagersPage FollowLinkToArtefactManagersPageFunc [D , L , C ],
99+ getArtefactManager GetArtefactManagerFunc [M ],
100+ getOutputArtefact GetArtefactContentFunc ) IArtefactManager [M , D ] {
101+ return & ArtefactManager [M , D , L , C ]{
89102 getArtefactManagerFunc : getArtefactManager ,
90103 getArtefactContentFunc : getOutputArtefact ,
91104 getArtefactManagersFirstPageFunc : getArtefactManagersFirstPage ,
92105 getArtefactManagersFollowLinkFunc : getArtefactsManagersPage ,
93106 }
94107}
95- func (m * ArtefactManager ) DownloadJobArtefact (ctx context.Context , jobName string , outputDirectory string , artefactManager * client. ArtefactManagerItem ) (err error ) {
108+ func (m * ArtefactManager [ M , D , L , C ] ) DownloadJobArtefact (ctx context.Context , jobName string , outputDirectory string , artefactManager M ) (err error ) {
96109 return m .DownloadJobArtefactWithTree (ctx , jobName , false , outputDirectory , artefactManager )
97110}
98111
99- func (m * ArtefactManager ) DownloadJobArtefactWithTree (ctx context.Context , jobName string , maintainTreeLocation bool , outputDirectory string , artefactManager * client. ArtefactManagerItem ) (err error ) {
112+ func (m * ArtefactManager [ M , D , L , C ] ) DownloadJobArtefactWithTree (ctx context.Context , jobName string , maintainTreeLocation bool , outputDirectory string , artefactManager M ) (err error ) {
100113 err = parallelisation .DetermineContextError (ctx )
101114 if err != nil {
102115 return
@@ -116,7 +129,7 @@ func (m *ArtefactManager) DownloadJobArtefactWithTree(ctx context.Context, jobNa
116129 if err != nil {
117130 return
118131 }
119- if artefactManager == nil {
132+ if any ( artefactManager ) == nil {
120133 err = fmt .Errorf ("%w: missing artefact manager" , commonerrors .ErrUndefined )
121134 return
122135 }
@@ -207,11 +220,11 @@ func (m *ArtefactManager) DownloadJobArtefactWithTree(ctx context.Context, jobNa
207220 return
208221
209222}
210- func (m * ArtefactManager ) DownloadJobArtefactFromLink (ctx context.Context , jobName string , outputDirectory string , artefactManagerItemLink * client. HalLinkData ) error {
223+ func (m * ArtefactManager [ M , D , L , C ] ) DownloadJobArtefactFromLink (ctx context.Context , jobName string , outputDirectory string , artefactManagerItemLink D ) error {
211224 return m .DownloadJobArtefactFromLinkWithTree (ctx , jobName , false , outputDirectory , artefactManagerItemLink )
212225}
213226
214- func (m * ArtefactManager ) DownloadJobArtefactFromLinkWithTree (ctx context.Context , jobName string , maintainTreeLocation bool , outputDirectory string , artefactManagerItemLink * client. HalLinkData ) (err error ) {
227+ func (m * ArtefactManager [ M , D , L , C ] ) DownloadJobArtefactFromLinkWithTree (ctx context.Context , jobName string , maintainTreeLocation bool , outputDirectory string , artefactManagerItemLink D ) (err error ) {
215228 err = parallelisation .DetermineContextError (ctx )
216229 if err != nil {
217230 return
@@ -220,7 +233,7 @@ func (m *ArtefactManager) DownloadJobArtefactFromLinkWithTree(ctx context.Contex
220233 err = fmt .Errorf ("%w: function to retrieve an artefact manager was not properly defined" , commonerrors .ErrUndefined )
221234 return
222235 }
223- if artefactManagerItemLink == nil {
236+ if any ( artefactManagerItemLink ) == nil {
224237 err = fmt .Errorf ("%w: missing artefact link" , commonerrors .ErrUndefined )
225238 return
226239 }
@@ -243,7 +256,7 @@ func (m *ArtefactManager) DownloadJobArtefactFromLinkWithTree(ctx context.Contex
243256 return
244257}
245258
246- func (m * ArtefactManager ) ListJobArtefacts (ctx context.Context , jobName string ) (pagination.IPaginatorAndPageFetcher , error ) {
259+ func (m * ArtefactManager [ M , D , L , C ] ) ListJobArtefacts (ctx context.Context , jobName string ) (pagination.IPaginatorAndPageFetcher , error ) {
247260 err := parallelisation .DetermineContextError (ctx )
248261 if err != nil {
249262 return nil , err
@@ -253,7 +266,7 @@ func (m *ArtefactManager) ListJobArtefacts(ctx context.Context, jobName string)
253266 }, m .fetchJobArtefactsNextPage )
254267}
255268
256- func (m * ArtefactManager ) fetchJobArtefactsFirstPage (ctx context.Context , jobName string ) (page pagination.IStaticPage , err error ) {
269+ func (m * ArtefactManager [ M , D , L , C ] ) fetchJobArtefactsFirstPage (ctx context.Context , jobName string ) (page pagination.IStaticPage , err error ) {
257270 if m .getArtefactManagersFirstPageFunc == nil {
258271 err = fmt .Errorf ("%w: function to retrieve artefact managers was not properly defined" , commonerrors .ErrUndefined )
259272 return
@@ -269,7 +282,7 @@ func (m *ArtefactManager) fetchJobArtefactsFirstPage(ctx context.Context, jobNam
269282 return
270283}
271284
272- func (m * ArtefactManager ) fetchJobArtefactsNextPage (ctx context.Context , currentPage pagination.IStaticPage ) (nextPage pagination.IStaticPage , err error ) {
285+ func (m * ArtefactManager [ M , D , L , C ] ) fetchJobArtefactsNextPage (ctx context.Context , currentPage pagination.IStaticPage ) (nextPage pagination.IStaticPage , err error ) {
273286 err = parallelisation .DetermineContextError (ctx )
274287 if err != nil {
275288 return
@@ -286,7 +299,7 @@ func (m *ArtefactManager) fetchJobArtefactsNextPage(ctx context.Context, current
286299 err = fmt .Errorf ("%w: returned artefact managers page is empty" , commonerrors .ErrUnexpected )
287300 return
288301 }
289- page , ok := unwrappedPage .(* client. ArtefactManagerCollection )
302+ page , ok := unwrappedPage .(C )
290303 if ! ok {
291304 err = fmt .Errorf ("%w: returned artefact managers page[%T] is not of the expected type [%v]" , commonerrors .ErrUnexpected , currentPage , "*ArtefactManagerCollection" )
292305 return
@@ -300,8 +313,8 @@ func (m *ArtefactManager) fetchJobArtefactsNextPage(ctx context.Context, current
300313 err = fmt .Errorf ("%w: returned page of artefact managers has no `next` link" , commonerrors .ErrUnexpected )
301314 return
302315 }
303- link := links .GetNext ()
304- clientPage , resp , apierr := m .getArtefactManagersFollowLinkFunc (ctx , & link )
316+ link := links .GetNextP ()
317+ clientPage , resp , apierr := m .getArtefactManagersFollowLinkFunc (ctx , link )
305318 if resp != nil {
306319 _ = resp .Body .Close ()
307320 }
@@ -312,11 +325,11 @@ func (m *ArtefactManager) fetchJobArtefactsNextPage(ctx context.Context, current
312325 return
313326}
314327
315- func (m * ArtefactManager ) DownloadAllJobArtefacts (ctx context.Context , jobName string , outputDirectory string ) error {
328+ func (m * ArtefactManager [ M , D , L , C ] ) DownloadAllJobArtefacts (ctx context.Context , jobName string , outputDirectory string ) error {
316329 return m .DownloadAllJobArtefactsWithTree (ctx , jobName , false , outputDirectory )
317330}
318331
319- func (m * ArtefactManager ) DownloadAllJobArtefactsWithTree (ctx context.Context , jobName string , maintainTreeStructure bool , outputDirectory string ) (err error ) {
332+ func (m * ArtefactManager [ M , D , L , C ] ) DownloadAllJobArtefactsWithTree (ctx context.Context , jobName string , maintainTreeStructure bool , outputDirectory string ) (err error ) {
320333 err = parallelisation .DetermineContextError (ctx )
321334 if err != nil {
322335 return
@@ -341,7 +354,7 @@ func (m *ArtefactManager) DownloadAllJobArtefactsWithTree(ctx context.Context, j
341354 err = fmt .Errorf ("%w: failed getting information about job artefacts: %v" , commonerrors .ErrUnexpected , subErr .Error ())
342355 return
343356 }
344- artefactLink , ok := item .(* client. HalLinkData )
357+ artefactLink , ok := item .(D )
345358 if ok {
346359 subErr = m .DownloadJobArtefactFromLinkWithTree (ctx , jobName , maintainTreeStructure , outputDirectory , artefactLink )
347360 if subErr != nil {
@@ -350,7 +363,7 @@ func (m *ArtefactManager) DownloadAllJobArtefactsWithTree(ctx context.Context, j
350363 }
351364
352365 } else {
353- artefactManager , ok := item .(* client. ArtefactManagerItem )
366+ artefactManager , ok := item .(M )
354367 if ok {
355368 subErr = m .DownloadJobArtefactWithTree (ctx , jobName , maintainTreeStructure , outputDirectory , artefactManager )
356369 if subErr != nil {
0 commit comments