github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/virtualrepository.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 VirtualRepositoryService struct {
    17  	isUpdate   bool
    18  	client     *rthttpclient.ArtifactoryHttpClient
    19  	ArtDetails auth.ServiceDetails
    20  }
    21  
    22  func NewVirtualRepositoryService(client *rthttpclient.ArtifactoryHttpClient, isUpdate bool) *VirtualRepositoryService {
    23  	return &VirtualRepositoryService{client: client, isUpdate: isUpdate}
    24  }
    25  
    26  func (vrs *VirtualRepositoryService) GetJfrogHttpClient() *rthttpclient.ArtifactoryHttpClient {
    27  	return vrs.client
    28  }
    29  
    30  func (vrs *VirtualRepositoryService) performRequest(params interface{}, repoKey string) error {
    31  	content, err := json.Marshal(params)
    32  	if errorutils.CheckError(err) != nil {
    33  		return err
    34  	}
    35  	httpClientsDetails := vrs.ArtDetails.CreateHttpClientDetails()
    36  	utils.SetContentType("application/vnd.org.jfrog.artifactory.repositories.VirtualRepositoryConfiguration+json", &httpClientsDetails.Headers)
    37  	var url = vrs.ArtDetails.GetUrl() + "api/repositories/" + repoKey
    38  	var operationString string
    39  	var resp *http.Response
    40  	var body []byte
    41  	if vrs.isUpdate {
    42  		log.Info("Updating virtual repository...")
    43  		operationString = "updating"
    44  		resp, body, err = vrs.client.SendPost(url, content, &httpClientsDetails)
    45  	} else {
    46  		log.Info("Creating virtual repository...")
    47  		operationString = "creating"
    48  		resp, body, err = vrs.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 (vrs *VirtualRepositoryService) Maven(params MavenVirtualRepositoryParams) error {
    63  	return vrs.performRequest(params, params.Key)
    64  }
    65  
    66  func (vrs *VirtualRepositoryService) Gradle(params GradleVirtualRepositoryParams) error {
    67  	return vrs.performRequest(params, params.Key)
    68  }
    69  
    70  func (vrs *VirtualRepositoryService) Ivy(params IvyVirtualRepositoryParams) error {
    71  	return vrs.performRequest(params, params.Key)
    72  }
    73  
    74  func (vrs *VirtualRepositoryService) Sbt(params SbtVirtualRepositoryParams) error {
    75  	return vrs.performRequest(params, params.Key)
    76  }
    77  
    78  func (vrs *VirtualRepositoryService) Helm(params HelmVirtualRepositoryParams) error {
    79  	return vrs.performRequest(params, params.Key)
    80  }
    81  
    82  func (vrs *VirtualRepositoryService) Rpm(params RpmVirtualRepositoryParams) error {
    83  	return vrs.performRequest(params, params.Key)
    84  }
    85  
    86  func (vrs *VirtualRepositoryService) Nuget(params NugetVirtualRepositoryParams) error {
    87  	return vrs.performRequest(params, params.Key)
    88  }
    89  
    90  func (vrs *VirtualRepositoryService) Cran(params CranVirtualRepositoryParams) error {
    91  	return vrs.performRequest(params, params.Key)
    92  }
    93  
    94  func (vrs *VirtualRepositoryService) Gems(params GemsVirtualRepositoryParams) error {
    95  	return vrs.performRequest(params, params.Key)
    96  }
    97  
    98  func (vrs *VirtualRepositoryService) Npm(params NpmVirtualRepositoryParams) error {
    99  	return vrs.performRequest(params, params.Key)
   100  }
   101  
   102  func (vrs *VirtualRepositoryService) Bower(params BowerVirtualRepositoryParams) error {
   103  	return vrs.performRequest(params, params.Key)
   104  }
   105  
   106  func (vrs *VirtualRepositoryService) Debian(params DebianVirtualRepositoryParams) error {
   107  	return vrs.performRequest(params, params.Key)
   108  }
   109  
   110  func (vrs *VirtualRepositoryService) Pypi(params PypiVirtualRepositoryParams) error {
   111  	return vrs.performRequest(params, params.Key)
   112  }
   113  
   114  func (vrs *VirtualRepositoryService) Docker(params DockerVirtualRepositoryParams) error {
   115  	return vrs.performRequest(params, params.Key)
   116  }
   117  
   118  func (vrs *VirtualRepositoryService) Yum(params YumVirtualRepositoryParams) error {
   119  	return vrs.performRequest(params, params.Key)
   120  }
   121  
   122  func (vrs *VirtualRepositoryService) Go(params GoVirtualRepositoryParams) error {
   123  	return vrs.performRequest(params, params.Key)
   124  }
   125  
   126  func (vrs *VirtualRepositoryService) P2(params P2VirtualRepositoryParams) error {
   127  	return vrs.performRequest(params, params.Key)
   128  }
   129  
   130  func (vrs *VirtualRepositoryService) Chef(params ChefVirtualRepositoryParams) error {
   131  	return vrs.performRequest(params, params.Key)
   132  }
   133  
   134  func (vrs *VirtualRepositoryService) Puppet(params PuppetVirtualRepositoryParams) error {
   135  	return vrs.performRequest(params, params.Key)
   136  }
   137  
   138  func (vrs *VirtualRepositoryService) Conda(params CondaVirtualRepositoryParams) error {
   139  	return vrs.performRequest(params, params.Key)
   140  }
   141  
   142  func (vrs *VirtualRepositoryService) Conan(params ConanVirtualRepositoryParams) error {
   143  	return vrs.performRequest(params, params.Key)
   144  }
   145  
   146  func (vrs *VirtualRepositoryService) Gitlfs(params GitlfsVirtualRepositoryParams) error {
   147  	return vrs.performRequest(params, params.Key)
   148  }
   149  
   150  func (vrs *VirtualRepositoryService) Generic(params GenericVirtualRepositoryParams) error {
   151  	return vrs.performRequest(params, params.Key)
   152  }
   153  
   154  type VirtualRepositoryBaseParams struct {
   155  	Key                                           string   `json:"key,omitempty"`
   156  	Rclass                                        string   `json:"rclass"`
   157  	PackageType                                   string   `json:"packageType,omitempty"`
   158  	Description                                   string   `json:"description,omitempty"`
   159  	Notes                                         string   `json:"notes,omitempty"`
   160  	IncludesPattern                               string   `json:"includesPattern,omitempty"`
   161  	ExcludesPattern                               string   `json:"excludesPattern,omitempty"`
   162  	RepoLayoutRef                                 string   `json:"repoLayoutRef,omitempty"`
   163  	Repositories                                  []string `json:"repositories,omitempty"`
   164  	ArtifactoryRequestsCanRetrieveRemoteArtifacts *bool    `json:"artifactoryRequestsCanRetrieveRemoteArtifacts,omitempty"`
   165  	DefaultDeploymentRepo                         string   `json:"defaultDeploymentRepo,omitempty"`
   166  }
   167  
   168  type CommonMavenGradleVirtualRepositoryParams struct {
   169  	ForceMavenAuthentication             *bool  `json:"forceMavenAuthentication,omitempty"`
   170  	PomRepositoryReferencesCleanupPolicy string `json:"pomRepositoryReferencesCleanupPolicy,omitempty"`
   171  	KeyPair                              string `json:"keyPair,omitempty"`
   172  }
   173  
   174  type MavenVirtualRepositoryParams struct {
   175  	VirtualRepositoryBaseParams
   176  	CommonMavenGradleVirtualRepositoryParams
   177  }
   178  
   179  func NewMavenVirtualRepositoryParams() MavenVirtualRepositoryParams {
   180  	return MavenVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "maven"}}
   181  }
   182  
   183  type GradleVirtualRepositoryParams struct {
   184  	VirtualRepositoryBaseParams
   185  	CommonMavenGradleVirtualRepositoryParams
   186  }
   187  
   188  func NewGradleVirtualRepositoryParams() GradleVirtualRepositoryParams {
   189  	return GradleVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "gradle"}}
   190  }
   191  
   192  type NugetVirtualRepositoryParams struct {
   193  	VirtualRepositoryBaseParams
   194  	ForceNugetAuthentication *bool `json:"forceNugetAuthentication,omitempty"`
   195  }
   196  
   197  func NewNugetVirtualRepositoryParams() NugetVirtualRepositoryParams {
   198  	return NugetVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "nuget"}}
   199  }
   200  
   201  type NpmVirtualRepositoryParams struct {
   202  	VirtualRepositoryBaseParams
   203  	ExternalDependenciesEnabled     *bool    `json:"externalDependenciesEnabled,omitempty"`
   204  	ExternalDependenciesPatterns    []string `json:"externalDependenciesPatterns,omitempty"`
   205  	ExternalDependenciesRemoteRepo  string   `json:"externalDependenciesRemoteRepo,omitempty"`
   206  	VirtualRetrievalCachePeriodSecs int      `json:"virtualRetrievalCachePeriodSecs,omitempty"`
   207  }
   208  
   209  func NewNpmVirtualRepositoryParams() NpmVirtualRepositoryParams {
   210  	return NpmVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "npm"}}
   211  }
   212  
   213  type BowerVirtualRepositoryParams struct {
   214  	VirtualRepositoryBaseParams
   215  	ExternalDependenciesEnabled    *bool    `json:"externalDependenciesEnabled,omitempty"`
   216  	ExternalDependenciesPatterns   []string `json:"externalDependenciesPatterns,omitempty"`
   217  	ExternalDependenciesRemoteRepo string   `json:"externalDependenciesRemoteRepo,omitempty"`
   218  }
   219  
   220  func NewBowerVirtualRepositoryParams() BowerVirtualRepositoryParams {
   221  	return BowerVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "bower"}}
   222  }
   223  
   224  type DebianVirtualRepositoryParams struct {
   225  	VirtualRepositoryBaseParams
   226  	DebianTrivialLayout *bool `json:"debianTrivialLayout,omitempty"`
   227  }
   228  
   229  func NewDebianVirtualRepositoryParams() DebianVirtualRepositoryParams {
   230  	return DebianVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "debian"}}
   231  }
   232  
   233  type GoVirtualRepositoryParams struct {
   234  	VirtualRepositoryBaseParams
   235  	ExternalDependenciesEnabled  *bool    `json:"externalDependenciesEnabled,omitempty"`
   236  	ExternalDependenciesPatterns []string `json:"externalDependenciesPatterns,omitempty"`
   237  }
   238  
   239  func NewGoVirtualRepositoryParams() GoVirtualRepositoryParams {
   240  	return GoVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "go"}}
   241  }
   242  
   243  type ConanVirtualRepositoryParams struct {
   244  	VirtualRepositoryBaseParams
   245  	VirtualRetrievalCachePeriodSecs int `json:"virtualRetrievalCachePeriodSecs,omitempty"`
   246  }
   247  
   248  func NewConanVirtualRepositoryParams() ConanVirtualRepositoryParams {
   249  	return ConanVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "conan"}}
   250  }
   251  
   252  type HelmVirtualRepositoryParams struct {
   253  	VirtualRepositoryBaseParams
   254  	VirtualRetrievalCachePeriodSecs int `json:"virtualRetrievalCachePeriodSecs,omitempty"`
   255  }
   256  
   257  func NewHelmVirtualRepositoryParams() HelmVirtualRepositoryParams {
   258  	return HelmVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "helm"}}
   259  }
   260  
   261  type RpmVirtualRepositoryParams struct {
   262  	VirtualRepositoryBaseParams
   263  	VirtualRetrievalCachePeriodSecs int `json:"virtualRetrievalCachePeriodSecs,omitempty"`
   264  }
   265  
   266  func NewRpmVirtualRepositoryParams() RpmVirtualRepositoryParams {
   267  	return RpmVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "rpm"}}
   268  }
   269  
   270  type CranVirtualRepositoryParams struct {
   271  	VirtualRepositoryBaseParams
   272  	VirtualRetrievalCachePeriodSecs int `json:"virtualRetrievalCachePeriodSecs,omitempty"`
   273  }
   274  
   275  func NewCranVirtualRepositoryParams() CranVirtualRepositoryParams {
   276  	return CranVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "cran"}}
   277  }
   278  
   279  type ChefVirtualRepositoryParams struct {
   280  	VirtualRepositoryBaseParams
   281  	VirtualRetrievalCachePeriodSecs int `json:"virtualRetrievalCachePeriodSecs,omitempty"`
   282  }
   283  
   284  func NewChefVirtualRepositoryParams() ChefVirtualRepositoryParams {
   285  	return ChefVirtualRepositoryParams{VirtualRepositoryBaseParams: VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "chef"}}
   286  }
   287  
   288  type CondaVirtualRepositoryParams struct {
   289  	VirtualRepositoryBaseParams
   290  }
   291  
   292  func NewCondaVirtualRepositoryParams() CondaVirtualRepositoryParams {
   293  	return CondaVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "conda"}}
   294  }
   295  
   296  type GitlfsVirtualRepositoryParams struct {
   297  	VirtualRepositoryBaseParams
   298  }
   299  
   300  func NewGitlfsVirtualRepositoryParams() GitlfsVirtualRepositoryParams {
   301  	return GitlfsVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "gitlfs"}}
   302  }
   303  
   304  type P2VirtualRepositoryParams struct {
   305  	VirtualRepositoryBaseParams
   306  }
   307  
   308  func NewP2VirtualRepositoryParams() P2VirtualRepositoryParams {
   309  	return P2VirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "p2"}}
   310  }
   311  
   312  type GemsVirtualRepositoryParams struct {
   313  	VirtualRepositoryBaseParams
   314  }
   315  
   316  func NewGemsVirtualRepositoryParams() GemsVirtualRepositoryParams {
   317  	return GemsVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "gems"}}
   318  }
   319  
   320  type PypiVirtualRepositoryParams struct {
   321  	VirtualRepositoryBaseParams
   322  }
   323  
   324  func NewPypiVirtualRepositoryParams() PypiVirtualRepositoryParams {
   325  	return PypiVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "pypi"}}
   326  }
   327  
   328  type PuppetVirtualRepositoryParams struct {
   329  	VirtualRepositoryBaseParams
   330  }
   331  
   332  func NewPuppetVirtualRepositoryParams() PuppetVirtualRepositoryParams {
   333  	return PuppetVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "puppet"}}
   334  }
   335  
   336  type IvyVirtualRepositoryParams struct {
   337  	VirtualRepositoryBaseParams
   338  }
   339  
   340  func NewIvyVirtualRepositoryParams() IvyVirtualRepositoryParams {
   341  	return IvyVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "ivy"}}
   342  }
   343  
   344  type SbtVirtualRepositoryParams struct {
   345  	VirtualRepositoryBaseParams
   346  }
   347  
   348  func NewSbtVirtualRepositoryParams() SbtVirtualRepositoryParams {
   349  	return SbtVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "sbt"}}
   350  }
   351  
   352  type DockerVirtualRepositoryParams struct {
   353  	VirtualRepositoryBaseParams
   354  }
   355  
   356  func NewDockerVirtualRepositoryParams() DockerVirtualRepositoryParams {
   357  	return DockerVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "docker"}}
   358  }
   359  
   360  type YumVirtualRepositoryParams struct {
   361  	VirtualRepositoryBaseParams
   362  }
   363  
   364  func NewYumVirtualRepositoryParams() YumVirtualRepositoryParams {
   365  	return YumVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "yum"}}
   366  }
   367  
   368  type GenericVirtualRepositoryParams struct {
   369  	VirtualRepositoryBaseParams
   370  }
   371  
   372  func NewGenericVirtualRepositoryParams() GenericVirtualRepositoryParams {
   373  	return GenericVirtualRepositoryParams{VirtualRepositoryBaseParams{Rclass: "virtual", PackageType: "generic"}}
   374  }