github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/pkg/abap/aakaas/aakUtils.go (about) 1 package aakaas 2 3 import ( 4 "time" 5 6 abapbuild "github.com/SAP/jenkins-library/pkg/abap/build" 7 "github.com/SAP/jenkins-library/pkg/abaputils" 8 "github.com/SAP/jenkins-library/pkg/command" 9 piperhttp "github.com/SAP/jenkins-library/pkg/http" 10 "github.com/SAP/jenkins-library/pkg/log" 11 "github.com/SAP/jenkins-library/pkg/piperutils" 12 ) 13 14 type AakUtils interface { 15 command.ExecRunner 16 abapbuild.HTTPSendLoader 17 piperutils.FileUtils 18 ReadAddonDescriptor(FileName string) (abaputils.AddonDescriptor, error) 19 GetMaxRuntime() time.Duration 20 GetPollingInterval() time.Duration 21 } 22 23 type AakBundle struct { 24 *command.Command 25 *piperhttp.Client 26 *piperutils.Files 27 maxRuntime time.Duration 28 pollingInterval time.Duration 29 } 30 31 func (bundle *AakBundle) GetMaxRuntime() time.Duration { 32 return bundle.maxRuntime 33 } 34 35 func (bundle *AakBundle) GetPollingInterval() time.Duration { 36 return bundle.pollingInterval 37 } 38 39 func (bundle *AakBundle) ReadAddonDescriptor(FileName string) (abaputils.AddonDescriptor, error) { 40 return abaputils.ReadAddonDescriptor(FileName) 41 } 42 43 func NewAakBundleWithTime(maxRuntime time.Duration, pollingInterval time.Duration) AakUtils { 44 utils := AakBundle{ 45 Command: &command.Command{}, 46 Client: &piperhttp.Client{}, 47 maxRuntime: maxRuntime * time.Minute, 48 pollingInterval: pollingInterval * time.Second, 49 } 50 // Reroute command output to logging framework 51 utils.Stdout(log.Writer()) 52 utils.Stderr(log.Writer()) 53 return &utils 54 } 55 56 func NewAakBundle() AakUtils { 57 utils := AakBundle{ 58 Command: &command.Command{}, 59 Client: &piperhttp.Client{}, 60 Files: &piperutils.Files{}, 61 } 62 // Reroute command output to logging framework 63 utils.Stdout(log.Writer()) 64 utils.Stderr(log.Writer()) 65 return &utils 66 }