github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/manager.go (about)

     1  package artifactory
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/cobalt77/jfrog-client-go/artifactory/buildinfo"
     7  	rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient"
     8  	"github.com/cobalt77/jfrog-client-go/artifactory/services"
     9  	_go "github.com/cobalt77/jfrog-client-go/artifactory/services/go"
    10  	"github.com/cobalt77/jfrog-client-go/artifactory/services/utils"
    11  	"github.com/cobalt77/jfrog-client-go/auth"
    12  	"github.com/cobalt77/jfrog-client-go/config"
    13  	ioutils "github.com/cobalt77/jfrog-client-go/utils/io"
    14  	"github.com/cobalt77/jfrog-client-go/utils/io/content"
    15  )
    16  
    17  type ArtifactoryServicesManagerImp struct {
    18  	client   *rthttpclient.ArtifactoryHttpClient
    19  	config   config.Config
    20  	progress ioutils.Progress
    21  }
    22  
    23  func New(artDetails *auth.ServiceDetails, config config.Config) (ArtifactoryServicesManager, error) {
    24  	return NewWithProgress(artDetails, config, nil)
    25  }
    26  
    27  func NewWithProgress(artDetails *auth.ServiceDetails, config config.Config, progress ioutils.Progress) (ArtifactoryServicesManager, error) {
    28  	err := (*artDetails).InitSsh()
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  	manager := &ArtifactoryServicesManagerImp{config: config, progress: progress}
    33  	manager.client, err = rthttpclient.ArtifactoryClientBuilder().
    34  		SetCertificatesPath(config.GetCertificatesPath()).
    35  		SetInsecureTls(config.IsInsecureTls()).
    36  		SetServiceDetails(artDetails).
    37  		Build()
    38  	if err != nil {
    39  		return nil, err
    40  	}
    41  	return manager, err
    42  }
    43  
    44  func (sm *ArtifactoryServicesManagerImp) CreateLocalRepository() *services.LocalRepositoryService {
    45  	repositoryService := services.NewLocalRepositoryService(sm.client, false)
    46  	repositoryService.ArtDetails = sm.config.GetServiceDetails()
    47  	return repositoryService
    48  }
    49  
    50  func (sm *ArtifactoryServicesManagerImp) CreateRemoteRepository() *services.RemoteRepositoryService {
    51  	repositoryService := services.NewRemoteRepositoryService(sm.client, false)
    52  	repositoryService.ArtDetails = sm.config.GetServiceDetails()
    53  	return repositoryService
    54  }
    55  
    56  func (sm *ArtifactoryServicesManagerImp) CreateVirtualRepository() *services.VirtualRepositoryService {
    57  	repositoryService := services.NewVirtualRepositoryService(sm.client, false)
    58  	repositoryService.ArtDetails = sm.config.GetServiceDetails()
    59  	return repositoryService
    60  }
    61  
    62  func (sm *ArtifactoryServicesManagerImp) UpdateLocalRepository() *services.LocalRepositoryService {
    63  	repositoryService := services.NewLocalRepositoryService(sm.client, true)
    64  	repositoryService.ArtDetails = sm.config.GetServiceDetails()
    65  	return repositoryService
    66  }
    67  
    68  func (sm *ArtifactoryServicesManagerImp) UpdateRemoteRepository() *services.RemoteRepositoryService {
    69  	repositoryService := services.NewRemoteRepositoryService(sm.client, true)
    70  	repositoryService.ArtDetails = sm.config.GetServiceDetails()
    71  	return repositoryService
    72  }
    73  
    74  func (sm *ArtifactoryServicesManagerImp) UpdateVirtualRepository() *services.VirtualRepositoryService {
    75  	repositoryService := services.NewVirtualRepositoryService(sm.client, true)
    76  	repositoryService.ArtDetails = sm.config.GetServiceDetails()
    77  	return repositoryService
    78  }
    79  
    80  func (sm *ArtifactoryServicesManagerImp) DeleteRepository(repoKey string) error {
    81  	deleteRepositoryService := services.NewDeleteRepositoryService(sm.client)
    82  	deleteRepositoryService.ArtDetails = sm.config.GetServiceDetails()
    83  	return deleteRepositoryService.Delete(repoKey)
    84  }
    85  
    86  func (sm *ArtifactoryServicesManagerImp) GetRepository(repoKey string) (*services.RepositoryDetails, error) {
    87  	getRepositoryService := services.NewGetRepositoryService(sm.client)
    88  	getRepositoryService.ArtDetails = sm.config.GetServiceDetails()
    89  	return getRepositoryService.Get(repoKey)
    90  }
    91  
    92  func (sm *ArtifactoryServicesManagerImp) CreatePermissionTarget(params services.PermissionTargetParams) error {
    93  	permissionTargetService := services.NewPermissionTargetService(sm.client)
    94  	permissionTargetService.ArtDetails = sm.config.GetServiceDetails()
    95  	return permissionTargetService.Create(params)
    96  }
    97  
    98  func (sm *ArtifactoryServicesManagerImp) UpdatePermissionTarget(params services.PermissionTargetParams) error {
    99  	permissionTargetService := services.NewPermissionTargetService(sm.client)
   100  	permissionTargetService.ArtDetails = sm.config.GetServiceDetails()
   101  	return permissionTargetService.Update(params)
   102  }
   103  
   104  func (sm *ArtifactoryServicesManagerImp) DeletePermissionTarget(permissionTargetName string) error {
   105  	permissionTargetService := services.NewPermissionTargetService(sm.client)
   106  	permissionTargetService.ArtDetails = sm.config.GetServiceDetails()
   107  	return permissionTargetService.Delete(permissionTargetName)
   108  }
   109  
   110  func (sm *ArtifactoryServicesManagerImp) PublishBuildInfo(build *buildinfo.BuildInfo) error {
   111  	buildInfoService := services.NewBuildInfoService(sm.client)
   112  	buildInfoService.DryRun = sm.config.IsDryRun()
   113  	buildInfoService.ArtDetails = sm.config.GetServiceDetails()
   114  	return buildInfoService.PublishBuildInfo(build)
   115  }
   116  
   117  func (sm *ArtifactoryServicesManagerImp) DistributeBuild(params services.BuildDistributionParams) error {
   118  	distributionService := services.NewDistributionService(sm.client)
   119  	distributionService.DryRun = sm.config.IsDryRun()
   120  	distributionService.ArtDetails = sm.config.GetServiceDetails()
   121  	return distributionService.BuildDistribute(params)
   122  }
   123  
   124  func (sm *ArtifactoryServicesManagerImp) PromoteBuild(params services.PromotionParams) error {
   125  	promotionService := services.NewPromotionService(sm.client)
   126  	promotionService.DryRun = sm.config.IsDryRun()
   127  	promotionService.ArtDetails = sm.config.GetServiceDetails()
   128  	return promotionService.BuildPromote(params)
   129  }
   130  
   131  func (sm *ArtifactoryServicesManagerImp) DiscardBuilds(params services.DiscardBuildsParams) error {
   132  	discardService := services.NewDiscardBuildsService(sm.client)
   133  	discardService.ArtDetails = sm.config.GetServiceDetails()
   134  	return discardService.DiscardBuilds(params)
   135  }
   136  
   137  func (sm *ArtifactoryServicesManagerImp) XrayScanBuild(params services.XrayScanParams) ([]byte, error) {
   138  	xrayScanService := services.NewXrayScanService(sm.client)
   139  	xrayScanService.ArtDetails = sm.config.GetServiceDetails()
   140  	return xrayScanService.ScanBuild(params)
   141  }
   142  
   143  func (sm *ArtifactoryServicesManagerImp) GetPathsToDelete(params services.DeleteParams) (*content.ContentReader, error) {
   144  	deleteService := services.NewDeleteService(sm.client)
   145  	deleteService.DryRun = sm.config.IsDryRun()
   146  	deleteService.ArtDetails = sm.config.GetServiceDetails()
   147  	return deleteService.GetPathsToDelete(params)
   148  }
   149  
   150  func (sm *ArtifactoryServicesManagerImp) DeleteFiles(reader *content.ContentReader) (int, error) {
   151  	deleteService := services.NewDeleteService(sm.client)
   152  	deleteService.DryRun = sm.config.IsDryRun()
   153  	deleteService.ArtDetails = sm.config.GetServiceDetails()
   154  	deleteService.Threads = sm.config.GetThreads()
   155  	return deleteService.DeleteFiles(reader)
   156  }
   157  
   158  func (sm *ArtifactoryServicesManagerImp) ReadRemoteFile(readPath string) (io.ReadCloser, error) {
   159  	readFileService := services.NewReadFileService(sm.client)
   160  	readFileService.DryRun = sm.config.IsDryRun()
   161  	readFileService.ArtDetails = sm.config.GetServiceDetails()
   162  	return readFileService.ReadRemoteFile(readPath)
   163  }
   164  
   165  func (sm *ArtifactoryServicesManagerImp) initDownloadService() *services.DownloadService {
   166  	downloadService := services.NewDownloadService(sm.client)
   167  	downloadService.DryRun = sm.config.IsDryRun()
   168  	downloadService.ArtDetails = sm.config.GetServiceDetails()
   169  	downloadService.Threads = sm.config.GetThreads()
   170  	downloadService.Progress = sm.progress
   171  	return downloadService
   172  }
   173  
   174  func (sm *ArtifactoryServicesManagerImp) DownloadFiles(params ...services.DownloadParams) (totalDownloaded, totalExpected int, err error) {
   175  	downloadService := sm.initDownloadService()
   176  	return downloadService.DownloadFiles(params...)
   177  }
   178  
   179  func (sm *ArtifactoryServicesManagerImp) DownloadFilesWithResultReader(params ...services.DownloadParams) (resultReader *content.ContentReader, totalDownloaded, totalExpected int, err error) {
   180  	downloadService := sm.initDownloadService()
   181  	rw, err := content.NewContentWriter(content.DefaultKey, true, false)
   182  	if err != nil {
   183  		return
   184  	}
   185  	downloadService.ResultWriter = rw
   186  	totalDownloaded, totalExpected, err = downloadService.DownloadFiles(params...)
   187  	if err != nil {
   188  		return
   189  	}
   190  	resultReader = content.NewContentReader(downloadService.ResultWriter.GetFilePath(), content.DefaultKey)
   191  	return
   192  }
   193  
   194  func (sm *ArtifactoryServicesManagerImp) GetUnreferencedGitLfsFiles(params services.GitLfsCleanParams) (*content.ContentReader, error) {
   195  	gitLfsCleanService := services.NewGitLfsCleanService(sm.client)
   196  	gitLfsCleanService.DryRun = sm.config.IsDryRun()
   197  	gitLfsCleanService.ArtDetails = sm.config.GetServiceDetails()
   198  	return gitLfsCleanService.GetUnreferencedGitLfsFiles(params)
   199  }
   200  
   201  func (sm *ArtifactoryServicesManagerImp) SearchFiles(params services.SearchParams) (*content.ContentReader, error) {
   202  	searchService := services.NewSearchService(sm.client)
   203  	searchService.ArtDetails = sm.config.GetServiceDetails()
   204  	return searchService.Search(params)
   205  }
   206  
   207  func (sm *ArtifactoryServicesManagerImp) Aql(aql string) (io.ReadCloser, error) {
   208  	aqlService := services.NewAqlService(sm.client)
   209  	aqlService.ArtDetails = sm.config.GetServiceDetails()
   210  	return aqlService.ExecAql(aql)
   211  }
   212  
   213  func (sm *ArtifactoryServicesManagerImp) SetProps(params services.PropsParams) (int, error) {
   214  	setPropsService := services.NewPropsService(sm.client)
   215  	setPropsService.ArtDetails = sm.config.GetServiceDetails()
   216  	setPropsService.Threads = sm.config.GetThreads()
   217  	return setPropsService.SetProps(params)
   218  }
   219  
   220  func (sm *ArtifactoryServicesManagerImp) DeleteProps(params services.PropsParams) (int, error) {
   221  	setPropsService := services.NewPropsService(sm.client)
   222  	setPropsService.ArtDetails = sm.config.GetServiceDetails()
   223  	setPropsService.Threads = sm.config.GetThreads()
   224  	return setPropsService.DeleteProps(params)
   225  }
   226  
   227  func (sm *ArtifactoryServicesManagerImp) UploadFiles(params ...services.UploadParams) (artifactsFileInfo []utils.FileInfo, totalUploaded, totalFailed int, err error) {
   228  	uploadService := services.NewUploadService(sm.client)
   229  	uploadService.Threads = sm.config.GetThreads()
   230  	uploadService.ArtDetails = sm.config.GetServiceDetails()
   231  	uploadService.DryRun = sm.config.IsDryRun()
   232  	uploadService.Progress = sm.progress
   233  	return uploadService.UploadFiles(params...)
   234  }
   235  
   236  func (sm *ArtifactoryServicesManagerImp) Copy(params services.MoveCopyParams) (successCount, failedCount int, err error) {
   237  	copyService := services.NewMoveCopyService(sm.client, services.COPY)
   238  	copyService.DryRun = sm.config.IsDryRun()
   239  	copyService.ArtDetails = sm.config.GetServiceDetails()
   240  	return copyService.MoveCopyServiceMoveFilesWrapper(params)
   241  }
   242  
   243  func (sm *ArtifactoryServicesManagerImp) Move(params services.MoveCopyParams) (successCount, failedCount int, err error) {
   244  	moveService := services.NewMoveCopyService(sm.client, services.MOVE)
   245  	moveService.DryRun = sm.config.IsDryRun()
   246  	moveService.ArtDetails = sm.config.GetServiceDetails()
   247  	return moveService.MoveCopyServiceMoveFilesWrapper(params)
   248  }
   249  
   250  func (sm *ArtifactoryServicesManagerImp) PublishGoProject(params _go.GoParams) error {
   251  	goService := _go.NewGoService(sm.client)
   252  	goService.ArtDetails = sm.config.GetServiceDetails()
   253  	return goService.PublishPackage(params)
   254  }
   255  
   256  func (sm *ArtifactoryServicesManagerImp) Ping() ([]byte, error) {
   257  	pingService := services.NewPingService(sm.client)
   258  	pingService.ArtDetails = sm.config.GetServiceDetails()
   259  	return pingService.Ping()
   260  }
   261  
   262  func (sm *ArtifactoryServicesManagerImp) GetConfig() config.Config {
   263  	return sm.config
   264  }
   265  
   266  func (sm *ArtifactoryServicesManagerImp) GetBuildInfo(params services.BuildInfoParams) (*buildinfo.BuildInfo, error) {
   267  	buildInfoService := services.NewBuildInfoService(sm.client)
   268  	buildInfoService.ArtDetails = sm.config.GetServiceDetails()
   269  	return buildInfoService.GetBuildInfo(params)
   270  }
   271  
   272  func (sm *ArtifactoryServicesManagerImp) CreateToken(params services.CreateTokenParams) (services.CreateTokenResponseData, error) {
   273  	securityService := services.NewSecurityService(sm.client)
   274  	securityService.ArtDetails = sm.config.GetServiceDetails()
   275  	return securityService.CreateToken(params)
   276  }
   277  
   278  func (sm *ArtifactoryServicesManagerImp) GetTokens() (services.GetTokensResponseData, error) {
   279  	securityService := services.NewSecurityService(sm.client)
   280  	securityService.ArtDetails = sm.config.GetServiceDetails()
   281  	return securityService.GetTokens()
   282  }
   283  
   284  func (sm *ArtifactoryServicesManagerImp) RefreshToken(params services.RefreshTokenParams) (services.CreateTokenResponseData, error) {
   285  	securityService := services.NewSecurityService(sm.client)
   286  	securityService.ArtDetails = sm.config.GetServiceDetails()
   287  	return securityService.RefreshToken(params)
   288  }
   289  
   290  func (sm *ArtifactoryServicesManagerImp) RevokeToken(params services.RevokeTokenParams) (string, error) {
   291  	securityService := services.NewSecurityService(sm.client)
   292  	securityService.ArtDetails = sm.config.GetServiceDetails()
   293  	return securityService.RevokeToken(params)
   294  }
   295  
   296  func (sm *ArtifactoryServicesManagerImp) CreateReplication(params services.CreateReplicationParams) error {
   297  	replicationService := services.NewCreateReplicationService(sm.client)
   298  	replicationService.ArtDetails = sm.config.GetServiceDetails()
   299  	return replicationService.CreateReplication(params)
   300  }
   301  
   302  func (sm *ArtifactoryServicesManagerImp) UpdateReplication(params services.UpdateReplicationParams) error {
   303  	replicationService := services.NewUpdateReplicationService(sm.client)
   304  	replicationService.ArtDetails = sm.config.GetServiceDetails()
   305  	return replicationService.UpdateReplication(params)
   306  }
   307  
   308  func (sm *ArtifactoryServicesManagerImp) DeleteReplication(repoKey string) error {
   309  	deleteReplicationService := services.NewDeleteReplicationService(sm.client)
   310  	deleteReplicationService.ArtDetails = sm.config.GetServiceDetails()
   311  	return deleteReplicationService.DeleteReplication(repoKey)
   312  }
   313  
   314  func (sm *ArtifactoryServicesManagerImp) GetReplication(repoKey string) ([]utils.ReplicationParams, error) {
   315  	getPushReplicationService := services.NewGetReplicationService(sm.client)
   316  	getPushReplicationService.ArtDetails = sm.config.GetServiceDetails()
   317  	return getPushReplicationService.GetReplication(repoKey)
   318  }
   319  
   320  func (sm *ArtifactoryServicesManagerImp) GetVersion() (string, error) {
   321  	systemService := services.NewSystemService(sm.client)
   322  	systemService.ArtDetails = sm.config.GetServiceDetails()
   323  	return systemService.GetVersion()
   324  }
   325  
   326  func (sm *ArtifactoryServicesManagerImp) GetServiceId() (string, error) {
   327  	systemService := services.NewSystemService(sm.client)
   328  	systemService.ArtDetails = sm.config.GetServiceDetails()
   329  	return systemService.GetServiceId()
   330  }
   331  
   332  func (sm *ArtifactoryServicesManagerImp) PromoteDocker(params services.DockerPromoteParams) error {
   333  	systemService := services.NewDockerPromoteService(sm.client)
   334  	systemService.ArtDetails = sm.config.GetServiceDetails()
   335  	return systemService.PromoteDocker(params)
   336  }
   337  
   338  func (sm *ArtifactoryServicesManagerImp) Client() *rthttpclient.ArtifactoryHttpClient {
   339  	return sm.client
   340  }