github.com/jfrog/jfrog-client-go@v1.40.2/distribution/manager.go (about)

     1  package distribution
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-client-go/config"
     5  	"github.com/jfrog/jfrog-client-go/distribution/services"
     6  	"github.com/jfrog/jfrog-client-go/http/jfroghttpclient"
     7  	clientutils "github.com/jfrog/jfrog-client-go/utils"
     8  	"github.com/jfrog/jfrog-client-go/utils/distribution"
     9  )
    10  
    11  type DistributionServicesManager struct {
    12  	client *jfroghttpclient.JfrogHttpClient
    13  	config config.Config
    14  }
    15  
    16  func New(config config.Config) (*DistributionServicesManager, error) {
    17  	details := config.GetServiceDetails()
    18  	var err error
    19  	manager := &DistributionServicesManager{config: config}
    20  	manager.client, err = jfroghttpclient.JfrogClientBuilder().
    21  		SetCertificatesPath(config.GetCertificatesPath()).
    22  		SetInsecureTls(config.IsInsecureTls()).
    23  		SetContext(config.GetContext()).
    24  		SetDialTimeout(config.GetDialTimeout()).
    25  		SetOverallRequestTimeout(config.GetOverallRequestTimeout()).
    26  		SetClientCertPath(details.GetClientCertPath()).
    27  		SetClientCertKeyPath(details.GetClientCertKeyPath()).
    28  		AppendPreRequestInterceptor(details.RunPreRequestFunctions).
    29  		SetContext(config.GetContext()).
    30  		SetRetries(config.GetHttpRetries()).
    31  		SetRetryWaitMilliSecs(config.GetHttpRetryWaitMilliSecs()).
    32  		Build()
    33  	return manager, err
    34  }
    35  
    36  func (sm *DistributionServicesManager) SetSigningKey(params services.SetSigningKeyParams) error {
    37  	setSigningKeyService := services.NewSetSigningKeyService(sm.client)
    38  	setSigningKeyService.DistDetails = sm.config.GetServiceDetails()
    39  	return setSigningKeyService.SetSigningKey(params)
    40  }
    41  
    42  func (sm *DistributionServicesManager) CreateReleaseBundle(params services.CreateReleaseBundleParams) (*clientutils.Sha256Summary, error) {
    43  	createBundleService := services.NewCreateReleaseBundleService(sm.client)
    44  	createBundleService.DistDetails = sm.config.GetServiceDetails()
    45  	createBundleService.DryRun = sm.config.IsDryRun()
    46  	return createBundleService.CreateReleaseBundle(params)
    47  }
    48  
    49  func (sm *DistributionServicesManager) UpdateReleaseBundle(params services.UpdateReleaseBundleParams) (*clientutils.Sha256Summary, error) {
    50  	createBundleService := services.NewUpdateReleaseBundleService(sm.client)
    51  	createBundleService.DistDetails = sm.config.GetServiceDetails()
    52  	createBundleService.DryRun = sm.config.IsDryRun()
    53  	return createBundleService.UpdateReleaseBundle(params)
    54  }
    55  
    56  func (sm *DistributionServicesManager) SignReleaseBundle(params services.SignBundleParams) (*clientutils.Sha256Summary, error) {
    57  	signBundleService := services.NewSignBundleService(sm.client)
    58  	signBundleService.DistDetails = sm.config.GetServiceDetails()
    59  	return signBundleService.SignReleaseBundle(params)
    60  }
    61  
    62  func (sm *DistributionServicesManager) DistributeReleaseBundle(params distribution.DistributionParams, autoCreateRepo bool) error {
    63  	distributeBundleService := services.NewDistributeReleaseBundleV1Service(sm.client)
    64  	distributeBundleService.DistDetails = sm.config.GetServiceDetails()
    65  	distributeBundleService.DryRun = sm.config.IsDryRun()
    66  	distributeBundleService.AutoCreateRepo = autoCreateRepo
    67  	distributeBundleService.DistributeParams = params
    68  	return distributeBundleService.Distribute()
    69  }
    70  
    71  func (sm *DistributionServicesManager) DistributeReleaseBundleSync(params distribution.DistributionParams, maxWaitMinutes int, autoCreateRepo bool) error {
    72  	distributeBundleService := services.NewDistributeReleaseBundleV1Service(sm.client)
    73  	distributeBundleService.DistDetails = sm.config.GetServiceDetails()
    74  	distributeBundleService.DryRun = sm.config.IsDryRun()
    75  	distributeBundleService.MaxWaitMinutes = maxWaitMinutes
    76  	distributeBundleService.Sync = true
    77  	distributeBundleService.AutoCreateRepo = autoCreateRepo
    78  	distributeBundleService.DistributeParams = params
    79  	return distributeBundleService.Distribute()
    80  }
    81  
    82  func (sm *DistributionServicesManager) GetDistributionStatus(params services.DistributionStatusParams) (*[]distribution.DistributionStatusResponse, error) {
    83  	distributeBundleService := services.NewDistributionStatusService(sm.client)
    84  	distributeBundleService.DistDetails = sm.config.GetServiceDetails()
    85  	return distributeBundleService.GetStatus(params)
    86  }
    87  
    88  func (sm *DistributionServicesManager) DeleteReleaseBundle(params services.DeleteDistributionParams) error {
    89  	deleteBundleService := services.NewDeleteReleaseBundleService(sm.client)
    90  	deleteBundleService.DistDetails = sm.config.GetServiceDetails()
    91  	deleteBundleService.DryRun = sm.config.IsDryRun()
    92  	return deleteBundleService.DeleteDistribution(params)
    93  }
    94  
    95  func (sm *DistributionServicesManager) DeleteLocalReleaseBundle(params services.DeleteDistributionParams) error {
    96  	deleteLocalBundleService := services.NewDeleteLocalDistributionService(sm.client)
    97  	deleteLocalBundleService.DistDetails = sm.config.GetServiceDetails()
    98  	deleteLocalBundleService.DryRun = sm.config.IsDryRun()
    99  	return deleteLocalBundleService.DeleteDistribution(params)
   100  }
   101  
   102  func (sm *DistributionServicesManager) Client() *jfroghttpclient.JfrogHttpClient {
   103  	return sm.client
   104  }
   105  
   106  func (sm *DistributionServicesManager) Config() config.Config {
   107  	return sm.config
   108  }
   109  
   110  func (sm *DistributionServicesManager) GetDistributionVersion() (string, error) {
   111  	versionService := services.NewVersionService(sm.client)
   112  	versionService.DistDetails = sm.config.GetServiceDetails()
   113  	return versionService.GetDistributionVersion()
   114  }