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

     1  package services
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  	"net/http"
     7  
     8  	rthttpclient "github.com/cobalt77/jfrog-client-go/artifactory/httpclient"
     9  	"github.com/cobalt77/jfrog-client-go/artifactory/services/utils"
    10  	"github.com/cobalt77/jfrog-client-go/auth"
    11  	clientutils "github.com/cobalt77/jfrog-client-go/utils"
    12  	"github.com/cobalt77/jfrog-client-go/utils/errorutils"
    13  	"github.com/cobalt77/jfrog-client-go/utils/log"
    14  )
    15  
    16  type LocalRepositoryService struct {
    17  	isUpdate   bool
    18  	client     *rthttpclient.ArtifactoryHttpClient
    19  	ArtDetails auth.ServiceDetails
    20  }
    21  
    22  func NewLocalRepositoryService(client *rthttpclient.ArtifactoryHttpClient, isUpdate bool) *LocalRepositoryService {
    23  	return &LocalRepositoryService{client: client, isUpdate: isUpdate}
    24  }
    25  
    26  func (lrs *LocalRepositoryService) GetJfrogHttpClient() *rthttpclient.ArtifactoryHttpClient {
    27  	return lrs.client
    28  }
    29  
    30  func (lrs *LocalRepositoryService) performRequest(params interface{}, repoKey string) error {
    31  	content, err := json.Marshal(params)
    32  	if errorutils.CheckError(err) != nil {
    33  		return err
    34  	}
    35  	httpClientsDetails := lrs.ArtDetails.CreateHttpClientDetails()
    36  	utils.SetContentType("application/vnd.org.jfrog.artifactory.repositories.LocalRepositoryConfiguration+json", &httpClientsDetails.Headers)
    37  	var url = lrs.ArtDetails.GetUrl() + "api/repositories/" + repoKey
    38  	var operationString string
    39  	var resp *http.Response
    40  	var body []byte
    41  	if lrs.isUpdate {
    42  		log.Info("Updating local repository...")
    43  		operationString = "updating"
    44  		resp, body, err = lrs.client.SendPost(url, content, &httpClientsDetails)
    45  	} else {
    46  		log.Info("Creating local repository...")
    47  		operationString = "creating"
    48  		resp, body, err = lrs.client.SendPut(url, content, &httpClientsDetails)
    49  	}
    50  	if err != nil {
    51  		return err
    52  	}
    53  	if resp.StatusCode != http.StatusOK {
    54  		return errorutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + clientutils.IndentJson(body)))
    55  	}
    56  
    57  	log.Debug("Artifactory response:", resp.Status)
    58  	log.Info("Done " + operationString + " repository.")
    59  	return nil
    60  }
    61  
    62  func (lrs *LocalRepositoryService) Maven(params MavenLocalRepositoryParams) error {
    63  	return lrs.performRequest(params, params.Key)
    64  }
    65  
    66  func (lrs *LocalRepositoryService) Gradle(params GradleLocalRepositoryParams) error {
    67  	return lrs.performRequest(params, params.Key)
    68  }
    69  
    70  func (lrs *LocalRepositoryService) Rpm(params RpmLocalRepositoryParams) error {
    71  	return lrs.performRequest(params, params.Key)
    72  }
    73  
    74  func (lrs *LocalRepositoryService) Nuget(params NugetLocalRepositoryParams) error {
    75  	return lrs.performRequest(params, params.Key)
    76  }
    77  
    78  func (lrs *LocalRepositoryService) Debian(params DebianLocalRepositoryParams) error {
    79  	return lrs.performRequest(params, params.Key)
    80  }
    81  
    82  func (lrs *LocalRepositoryService) Docker(params DockerLocalRepositoryParams) error {
    83  	return lrs.performRequest(params, params.Key)
    84  }
    85  
    86  func (lrs *LocalRepositoryService) Ivy(params IvyLocalRepositoryParams) error {
    87  	return lrs.performRequest(params, params.Key)
    88  }
    89  
    90  func (lrs *LocalRepositoryService) Sbt(params SbtLocalRepositoryParams) error {
    91  	return lrs.performRequest(params, params.Key)
    92  }
    93  
    94  func (lrs *LocalRepositoryService) Helm(params HelmLocalRepositoryParams) error {
    95  	return lrs.performRequest(params, params.Key)
    96  }
    97  
    98  func (lrs *LocalRepositoryService) Cocoapods(params CocoapodsLocalRepositoryParams) error {
    99  	return lrs.performRequest(params, params.Key)
   100  }
   101  
   102  func (lrs *LocalRepositoryService) Opkg(params OpkgLocalRepositoryParams) error {
   103  	return lrs.performRequest(params, params.Key)
   104  }
   105  
   106  func (lrs *LocalRepositoryService) Cran(params CranLocalRepositoryParams) error {
   107  	return lrs.performRequest(params, params.Key)
   108  }
   109  
   110  func (lrs *LocalRepositoryService) Gems(params GemsLocalRepositoryParams) error {
   111  	return lrs.performRequest(params, params.Key)
   112  }
   113  
   114  func (lrs *LocalRepositoryService) Npm(params NpmLocalRepositoryParams) error {
   115  	return lrs.performRequest(params, params.Key)
   116  }
   117  
   118  func (lrs *LocalRepositoryService) Bower(params BowerLocalRepositoryParams) error {
   119  	return lrs.performRequest(params, params.Key)
   120  }
   121  
   122  func (lrs *LocalRepositoryService) Composer(params ComposerLocalRepositoryParams) error {
   123  	return lrs.performRequest(params, params.Key)
   124  }
   125  
   126  func (lrs *LocalRepositoryService) Pypi(params PypiLocalRepositoryParams) error {
   127  	return lrs.performRequest(params, params.Key)
   128  }
   129  
   130  func (lrs *LocalRepositoryService) Vagrant(params VagrantLocalRepositoryParams) error {
   131  	return lrs.performRequest(params, params.Key)
   132  }
   133  
   134  func (lrs *LocalRepositoryService) Gitlfs(params GitlfsLocalRepositoryParams) error {
   135  	return lrs.performRequest(params, params.Key)
   136  }
   137  
   138  func (lrs *LocalRepositoryService) Go(params GoLocalRepositoryParams) error {
   139  	return lrs.performRequest(params, params.Key)
   140  }
   141  
   142  func (lrs *LocalRepositoryService) Yum(params YumLocalRepositoryParams) error {
   143  	return lrs.performRequest(params, params.Key)
   144  }
   145  
   146  func (lrs *LocalRepositoryService) Conan(params ConanLocalRepositoryParams) error {
   147  	return lrs.performRequest(params, params.Key)
   148  }
   149  
   150  func (lrs *LocalRepositoryService) Chef(params ChefLocalRepositoryParams) error {
   151  	return lrs.performRequest(params, params.Key)
   152  }
   153  
   154  func (lrs *LocalRepositoryService) Puppet(params PuppetLocalRepositoryParams) error {
   155  	return lrs.performRequest(params, params.Key)
   156  }
   157  
   158  func (lrs *LocalRepositoryService) Generic(params GenericLocalRepositoryParams) error {
   159  	return lrs.performRequest(params, params.Key)
   160  }
   161  
   162  type LocalRepositoryBaseParams struct {
   163  	Key                             string   `json:"key,omitempty"`
   164  	Rclass                          string   `json:"rclass"`
   165  	PackageType                     string   `json:"packageType,omitempty"`
   166  	Description                     string   `json:"description,omitempty"`
   167  	Notes                           string   `json:"notes,omitempty"`
   168  	IncludesPattern                 string   `json:"includesPattern,omitempty"`
   169  	ExcludesPattern                 string   `json:"excludesPattern,omitempty"`
   170  	RepoLayoutRef                   string   `json:"repoLayoutRef,omitempty"`
   171  	BlackedOut                      *bool    `json:"blackedOut,omitempty"`
   172  	XrayIndex                       *bool    `json:"xrayIndex,omitempty"`
   173  	PropertySets                    []string `json:"propertySets,omitempty"`
   174  	ArchiveBrowsingEnabled          *bool    `json:"archiveBrowsingEnabled,omitempty"`
   175  	OptionalIndexCompressionFormats []string `json:"optionalIndexCompressionFormats,omitempty"`
   176  	DownloadRedirect                *bool    `json:"downloadRedirect,omitempty"`
   177  	BlockPushingSchema1             *bool    `json:"blockPushingSchema1,omitempty"`
   178  }
   179  
   180  type CommonMavenGradleLocalRepositoryParams struct {
   181  	MaxUniqueSnapshots           int    `json:"maxUniqueSnapshots,omitempty"`
   182  	HandleReleases               *bool  `json:"handleReleases,omitempty"`
   183  	HandleSnapshots              *bool  `json:"handleSnapshots,omitempty"`
   184  	SuppressPomConsistencyChecks *bool  `json:"suppressPomConsistencyChecks,omitempty"`
   185  	SnapshotVersionBehavior      string `json:"snapshotVersionBehavior,omitempty"`
   186  	ChecksumPolicyType           string `json:"checksumPolicyType,omitempty"`
   187  }
   188  
   189  type MavenLocalRepositoryParams struct {
   190  	LocalRepositoryBaseParams
   191  	CommonMavenGradleLocalRepositoryParams
   192  }
   193  
   194  func NewMavenLocalRepositoryParams() MavenLocalRepositoryParams {
   195  	return MavenLocalRepositoryParams{LocalRepositoryBaseParams: LocalRepositoryBaseParams{Rclass: "local", PackageType: "maven"}}
   196  }
   197  
   198  type GradleLocalRepositoryParams struct {
   199  	LocalRepositoryBaseParams
   200  	CommonMavenGradleLocalRepositoryParams
   201  }
   202  
   203  func NewGradleLocalRepositoryParams() GradleLocalRepositoryParams {
   204  	return GradleLocalRepositoryParams{LocalRepositoryBaseParams: LocalRepositoryBaseParams{Rclass: "local", PackageType: "gradle"}}
   205  }
   206  
   207  type RpmLocalRepositoryParams struct {
   208  	LocalRepositoryBaseParams
   209  	YumRootDepth            int   `json:"yumRootDepth,omitempty"`
   210  	CalculateYumMetadata    *bool `json:"calculateYumMetadata,omitempty"`
   211  	EnableFileListsIndexing *bool `json:"enableFileListsIndexing,omitempty"`
   212  }
   213  
   214  func NewRpmLocalRepositoryParams() RpmLocalRepositoryParams {
   215  	return RpmLocalRepositoryParams{LocalRepositoryBaseParams: LocalRepositoryBaseParams{Rclass: "local", PackageType: "rpm"}}
   216  }
   217  
   218  type NugetLocalRepositoryParams struct {
   219  	LocalRepositoryBaseParams
   220  	MaxUniqueSnapshots       int   `json:"maxUniqueSnapshots,omitempty"`
   221  	ForceNugetAuthentication *bool `json:"forceNugetAuthentication,omitempty"`
   222  }
   223  
   224  func NewNugetLocalRepositoryParams() NugetLocalRepositoryParams {
   225  	return NugetLocalRepositoryParams{LocalRepositoryBaseParams: LocalRepositoryBaseParams{Rclass: "local", PackageType: "nuget"}}
   226  }
   227  
   228  type DebianLocalRepositoryParams struct {
   229  	LocalRepositoryBaseParams
   230  	DebianTrivialLayout *bool `json:"debianTrivialLayout,omitempty"`
   231  }
   232  
   233  func NewDebianLocalRepositoryParams() DebianLocalRepositoryParams {
   234  	return DebianLocalRepositoryParams{LocalRepositoryBaseParams: LocalRepositoryBaseParams{Rclass: "local", PackageType: "debian"}}
   235  }
   236  
   237  type DockerLocalRepositoryParams struct {
   238  	LocalRepositoryBaseParams
   239  	MaxUniqueTags    int    `json:"maxUniqueTags,omitempty"`
   240  	DockerApiVersion string `json:"dockerApiVersion,omitempty"`
   241  }
   242  
   243  func NewDockerLocalRepositoryParams() DockerLocalRepositoryParams {
   244  	return DockerLocalRepositoryParams{LocalRepositoryBaseParams: LocalRepositoryBaseParams{Rclass: "local", PackageType: "docker"}}
   245  }
   246  
   247  type IvyLocalRepositoryParams struct {
   248  	LocalRepositoryBaseParams
   249  }
   250  
   251  func NewIvyLocalRepositoryParams() IvyLocalRepositoryParams {
   252  	return IvyLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "ivy"}}
   253  }
   254  
   255  type SbtLocalRepositoryParams struct {
   256  	LocalRepositoryBaseParams
   257  }
   258  
   259  func NewSbtLocalRepositoryParams() SbtLocalRepositoryParams {
   260  	return SbtLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "sbt"}}
   261  }
   262  
   263  type HelmLocalRepositoryParams struct {
   264  	LocalRepositoryBaseParams
   265  }
   266  
   267  func NewHelmLocalRepositoryParams() HelmLocalRepositoryParams {
   268  	return HelmLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "helm"}}
   269  }
   270  
   271  type CocoapodsLocalRepositoryParams struct {
   272  	LocalRepositoryBaseParams
   273  }
   274  
   275  func NewCocoapodsLocalRepositoryParams() CocoapodsLocalRepositoryParams {
   276  	return CocoapodsLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "cocoapods"}}
   277  }
   278  
   279  type OpkgLocalRepositoryParams struct {
   280  	LocalRepositoryBaseParams
   281  }
   282  
   283  func NewOpkgLocalRepositoryParams() OpkgLocalRepositoryParams {
   284  	return OpkgLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "opkg"}}
   285  }
   286  
   287  type CranLocalRepositoryParams struct {
   288  	LocalRepositoryBaseParams
   289  }
   290  
   291  func NewCranLocalRepositoryParams() CranLocalRepositoryParams {
   292  	return CranLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "cran"}}
   293  }
   294  
   295  type GemsLocalRepositoryParams struct {
   296  	LocalRepositoryBaseParams
   297  }
   298  
   299  func NewGemsLocalRepositoryParams() GemsLocalRepositoryParams {
   300  	return GemsLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "gems"}}
   301  }
   302  
   303  type NpmLocalRepositoryParams struct {
   304  	LocalRepositoryBaseParams
   305  }
   306  
   307  func NewNpmLocalRepositoryParams() NpmLocalRepositoryParams {
   308  	return NpmLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "npm"}}
   309  }
   310  
   311  type BowerLocalRepositoryParams struct {
   312  	LocalRepositoryBaseParams
   313  }
   314  
   315  func NewBowerLocalRepositoryParams() BowerLocalRepositoryParams {
   316  	return BowerLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "bower"}}
   317  }
   318  
   319  type ComposerLocalRepositoryParams struct {
   320  	LocalRepositoryBaseParams
   321  }
   322  
   323  func NewComposerLocalRepositoryParams() ComposerLocalRepositoryParams {
   324  	return ComposerLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "composer"}}
   325  }
   326  
   327  type PypiLocalRepositoryParams struct {
   328  	LocalRepositoryBaseParams
   329  }
   330  
   331  func NewPypiLocalRepositoryParams() PypiLocalRepositoryParams {
   332  	return PypiLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "pypi"}}
   333  }
   334  
   335  type VagrantLocalRepositoryParams struct {
   336  	LocalRepositoryBaseParams
   337  }
   338  
   339  func NewVagrantLocalRepositoryParams() VagrantLocalRepositoryParams {
   340  	return VagrantLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "vagrant"}}
   341  }
   342  
   343  type GitlfsLocalRepositoryParams struct {
   344  	LocalRepositoryBaseParams
   345  }
   346  
   347  func NewGitlfsLocalRepositoryParams() GitlfsLocalRepositoryParams {
   348  	return GitlfsLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "gitlfs"}}
   349  }
   350  
   351  type GoLocalRepositoryParams struct {
   352  	LocalRepositoryBaseParams
   353  }
   354  
   355  func NewGoLocalRepositoryParams() GoLocalRepositoryParams {
   356  	return GoLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "go"}}
   357  }
   358  
   359  type YumLocalRepositoryParams struct {
   360  	LocalRepositoryBaseParams
   361  }
   362  
   363  func NewYumLocalRepositoryParams() YumLocalRepositoryParams {
   364  	return YumLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "yum"}}
   365  }
   366  
   367  type ConanLocalRepositoryParams struct {
   368  	LocalRepositoryBaseParams
   369  }
   370  
   371  func NewConanLocalRepositoryParams() ConanLocalRepositoryParams {
   372  	return ConanLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "conan"}}
   373  }
   374  
   375  type ChefLocalRepositoryParams struct {
   376  	LocalRepositoryBaseParams
   377  }
   378  
   379  func NewChefLocalRepositoryParams() ChefLocalRepositoryParams {
   380  	return ChefLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "chef"}}
   381  }
   382  
   383  type PuppetLocalRepositoryParams struct {
   384  	LocalRepositoryBaseParams
   385  }
   386  
   387  func NewPuppetLocalRepositoryParams() PuppetLocalRepositoryParams {
   388  	return PuppetLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "puppet"}}
   389  }
   390  
   391  type GenericLocalRepositoryParams struct {
   392  	LocalRepositoryBaseParams
   393  }
   394  
   395  func NewGenericLocalRepositoryParams() GenericLocalRepositoryParams {
   396  	return GenericLocalRepositoryParams{LocalRepositoryBaseParams{Rclass: "local", PackageType: "generic"}}
   397  }