github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/remoterepository.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 RemoteRepositoryService struct { 17 isUpdate bool 18 client *rthttpclient.ArtifactoryHttpClient 19 ArtDetails auth.ServiceDetails 20 } 21 22 func NewRemoteRepositoryService(client *rthttpclient.ArtifactoryHttpClient, isUpdate bool) *RemoteRepositoryService { 23 return &RemoteRepositoryService{client: client, isUpdate: isUpdate} 24 } 25 26 func (rrs *RemoteRepositoryService) GetJfrogHttpClient() *rthttpclient.ArtifactoryHttpClient { 27 return rrs.client 28 } 29 30 func (rrs *RemoteRepositoryService) performRequest(params interface{}, repoKey string) error { 31 content, err := json.Marshal(params) 32 if errorutils.CheckError(err) != nil { 33 return err 34 } 35 httpClientsDetails := rrs.ArtDetails.CreateHttpClientDetails() 36 utils.SetContentType("application/vnd.org.jfrog.artifactory.repositories.RemoteRepositoryConfiguration+json", &httpClientsDetails.Headers) 37 var url = rrs.ArtDetails.GetUrl() + "api/repositories/" + repoKey 38 var operationString string 39 var resp *http.Response 40 var body []byte 41 if rrs.isUpdate { 42 log.Info("Updating remote repository...") 43 operationString = "updating" 44 resp, body, err = rrs.client.SendPost(url, content, &httpClientsDetails) 45 } else { 46 log.Info("Creating remote repository...") 47 operationString = "creating" 48 resp, body, err = rrs.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 (rrs *RemoteRepositoryService) Maven(params MavenRemoteRepositoryParams) error { 63 return rrs.performRequest(params, params.Key) 64 } 65 66 func (rrs *RemoteRepositoryService) Gradle(params GradleRemoteRepositoryParams) error { 67 return rrs.performRequest(params, params.Key) 68 } 69 70 func (rrs *RemoteRepositoryService) Ivy(params IvyRemoteRepositoryParams) error { 71 return rrs.performRequest(params, params.Key) 72 } 73 74 func (rrs *RemoteRepositoryService) Sbt(params SbtRemoteRepositoryParams) error { 75 return rrs.performRequest(params, params.Key) 76 } 77 78 func (rrs *RemoteRepositoryService) Helm(params HelmRemoteRepositoryParams) error { 79 return rrs.performRequest(params, params.Key) 80 } 81 82 func (rrs *RemoteRepositoryService) Cocoapods(params CocoapodsRemoteRepositoryParams) error { 83 return rrs.performRequest(params, params.Key) 84 } 85 86 func (rrs *RemoteRepositoryService) Opkg(params OpkgRemoteRepositoryParams) error { 87 return rrs.performRequest(params, params.Key) 88 } 89 90 func (rrs *RemoteRepositoryService) Rpm(params RpmRemoteRepositoryParams) error { 91 return rrs.performRequest(params, params.Key) 92 } 93 94 func (rrs *RemoteRepositoryService) Nuget(params NugetRemoteRepositoryParams) error { 95 return rrs.performRequest(params, params.Key) 96 } 97 98 func (rrs *RemoteRepositoryService) Cran(params CranRemoteRepositoryParams) error { 99 return rrs.performRequest(params, params.Key) 100 } 101 102 func (rrs *RemoteRepositoryService) Gems(params GemsRemoteRepositoryParams) error { 103 return rrs.performRequest(params, params.Key) 104 } 105 106 func (rrs *RemoteRepositoryService) Npm(params NpmRemoteRepositoryParams) error { 107 return rrs.performRequest(params, params.Key) 108 } 109 110 func (rrs *RemoteRepositoryService) Bower(params BowerRemoteRepositoryParams) error { 111 return rrs.performRequest(params, params.Key) 112 } 113 114 func (rrs *RemoteRepositoryService) Debian(params DebianRemoteRepositoryParams) error { 115 return rrs.performRequest(params, params.Key) 116 } 117 118 func (rrs *RemoteRepositoryService) Pypi(params PypiRemoteRepositoryParams) error { 119 return rrs.performRequest(params, params.Key) 120 } 121 122 func (rrs *RemoteRepositoryService) Docker(params DockerRemoteRepositoryParams) error { 123 return rrs.performRequest(params, params.Key) 124 } 125 126 func (rrs *RemoteRepositoryService) Yum(params YumRemoteRepositoryParams) error { 127 return rrs.performRequest(params, params.Key) 128 } 129 130 func (rrs *RemoteRepositoryService) Vcs(params VcsRemoteRepositoryParams) error { 131 return rrs.performRequest(params, params.Key) 132 } 133 134 func (rrs *RemoteRepositoryService) Composer(params ComposerRemoteRepositoryParams) error { 135 return rrs.performRequest(params, params.Key) 136 } 137 138 func (rrs *RemoteRepositoryService) Go(params GoRemoteRepositoryParams) error { 139 return rrs.performRequest(params, params.Key) 140 } 141 142 func (rrs *RemoteRepositoryService) P2(params P2RemoteRepositoryParams) error { 143 return rrs.performRequest(params, params.Key) 144 } 145 146 func (rrs *RemoteRepositoryService) Chef(params ChefRemoteRepositoryParams) error { 147 return rrs.performRequest(params, params.Key) 148 } 149 150 func (rrs *RemoteRepositoryService) Puppet(params PuppetRemoteRepositoryParams) error { 151 return rrs.performRequest(params, params.Key) 152 } 153 154 func (rrs *RemoteRepositoryService) Conda(params CondaRemoteRepositoryParams) error { 155 return rrs.performRequest(params, params.Key) 156 } 157 158 func (rrs *RemoteRepositoryService) Conan(params ConanRemoteRepositoryParams) error { 159 return rrs.performRequest(params, params.Key) 160 } 161 162 func (rrs *RemoteRepositoryService) Gitlfs(params GitlfsRemoteRepositoryParams) error { 163 return rrs.performRequest(params, params.Key) 164 } 165 166 func (rrs *RemoteRepositoryService) Generic(params GenericRemoteRepositoryParams) error { 167 return rrs.performRequest(params, params.Key) 168 } 169 170 type ContentSynchronisation struct { 171 Enabled bool `json:"enables,omitempty"` 172 Statistics struct { 173 Enabled bool `json:"enables,omitempty"` 174 } `json:"statistics,omitempty"` 175 Properties struct { 176 Enabled bool `json:"enables,omitempty"` 177 } `json:"properties,omitempty"` 178 Source struct { 179 OriginAbsenceDetection bool `json:"originAbsenceDetection,omitempty"` 180 } `json:"source,omitempty"` 181 } 182 183 type RemoteRepositoryBaseParams struct { 184 Key string `json:"key,omitempty"` 185 Rclass string `json:"rclass"` 186 PackageType string `json:"packageType,omitempty"` 187 Url string `json:"url"` 188 Username string `json:"username,omitempty"` 189 Password string `json:"password,omitempty"` 190 Proxy string `json:"proxy,omitempty"` 191 Description string `json:"description,omitempty"` 192 Notes string `json:"notes,omitempty"` 193 IncludesPattern string `json:"includesPattern,omitempty"` 194 ExcludesPattern string `json:"excludesPattern,omitempty"` 195 RepoLayoutRef string `json:"repoLayoutRef,omitempty"` 196 HardFail *bool `json:"hardFail,omitempty"` 197 Offline *bool `json:"offline,omitempty"` 198 BlackedOut *bool `json:"blackedOut,omitempty"` 199 StoreArtifactsLocally *bool `json:"storeArtifactsLocally,omitempty"` 200 SocketTimeoutMillis int `json:"socketTimeoutMillis,omitempty"` 201 LocalAddress string `json:"localAddress,omitempty"` 202 RetrievalCachePeriodSecs int `json:"retrievalCachePeriodSecs,omitempty"` 203 FailedRetrievalCachePeriodSecs int `json:"failedRetrievalCachePeriodSecs,omitempty"` 204 MissedRetrievalCachePeriodSecs int `json:"missedRetrievalCachePeriodSecs,omitempty"` 205 UnusedArtifactsCleanupEnabled *bool `json:"unusedArtifactsCleanupEnabled,omitempty"` 206 UnusedArtifactsCleanupPeriodHours int `json:"unusedArtifactsCleanupPeriodHours,omitempty"` 207 AssumedOfflinePeriodSecs int `json:"assumedOfflinePeriodSecs,omitempty"` 208 ShareConfiguration *bool `json:"shareConfiguration,omitempty"` 209 SynchronizeProperties *bool `json:"synchronizeProperties,omitempty"` 210 BlockMismatchingMimeTypes *bool `json:"blockMismatchingMimeTypes,omitempty"` 211 PropertySets []string `json:"propertySets,omitempty"` 212 AllowAnyHostAuth *bool `json:"allowAnyHostAuth,omitempty"` 213 EnableCookieManagement *bool `json:"enableCookieManagement,omitempty"` 214 BypassHeadRequests *bool `json:"bypassHeadRequests,omitempty"` 215 ClientTlsCertificate string `json:"clientTlsCertificate,omitempty"` 216 BlockPushingSchema1 *bool `json:"blockPushingSchema1,omitempty"` 217 ContentSynchronisation *ContentSynchronisation `json:"contentSynchronisation,omitempty"` 218 } 219 220 type CommonMavenGradleRemoteRepositoryParams struct { 221 FetchJarsEagerly *bool `json:"fetchJarsEagerly,omitempty"` 222 FetchSourcesEagerly *bool `json:"fetchSourcesEagerly,omitempty"` 223 RemoteRepoChecksumPolicyType string `json:"remoteRepoChecksumPolicyType,omitempty"` 224 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 225 HandleReleases *bool `json:"handleReleases,omitempty"` 226 HandleSnapshots *bool `json:"handleSnapshots,omitempty"` 227 SuppressPomConsistencyChecks *bool `json:"suppressPomConsistencyChecks,omitempty"` 228 RejectInvalidJars *bool `json:"rejectInvalidJars,omitempty"` 229 } 230 231 type MavenRemoteRepositoryParams struct { 232 RemoteRepositoryBaseParams 233 CommonMavenGradleRemoteRepositoryParams 234 } 235 236 func NewMavenRemoteRepositoryParams() MavenRemoteRepositoryParams { 237 return MavenRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "maven"}} 238 } 239 240 type GradleRemoteRepositoryParams struct { 241 RemoteRepositoryBaseParams 242 CommonMavenGradleRemoteRepositoryParams 243 } 244 245 func NewGradleRemoteRepositoryParams() GradleRemoteRepositoryParams { 246 return GradleRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "gradle"}} 247 } 248 249 type CocoapodsRemoteRepositoryParams struct { 250 RemoteRepositoryBaseParams 251 PodsSpecsRepoUrl string `json:"podsSpecsRepoUrl,omitempty"` 252 } 253 254 func NewCocoapodsRemoteRepositoryParams() CocoapodsRemoteRepositoryParams { 255 return CocoapodsRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "cocoapods"}} 256 } 257 258 type OpkgRemoteRepositoryParams struct { 259 RemoteRepositoryBaseParams 260 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 261 } 262 263 func NewOpkgRemoteRepositoryParams() OpkgRemoteRepositoryParams { 264 return OpkgRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "opkg"}} 265 } 266 267 type RpmRemoteRepositoryParams struct { 268 RemoteRepositoryBaseParams 269 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 270 } 271 272 func NewRpmRemoteRepositoryParams() RpmRemoteRepositoryParams { 273 return RpmRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "rpm"}} 274 } 275 276 type NugetRemoteRepositoryParams struct { 277 RemoteRepositoryBaseParams 278 FeedContextPath string `json:"feedContextPath,omitempty"` 279 DownloadContextPath string `json:"downloadContextPath,omitempty"` 280 V3FeedUrl string `json:"v3FeedUrl,omitempty"` 281 ForceNugetAuthentication *bool `json:"forceNugetAuthentication,omitempty"` 282 } 283 284 func NewNugetRemoteRepositoryParams() NugetRemoteRepositoryParams { 285 return NugetRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "nuget"}} 286 } 287 288 type GemsRemoteRepositoryParams struct { 289 RemoteRepositoryBaseParams 290 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 291 } 292 293 func NewGemsRemoteRepositoryParams() GemsRemoteRepositoryParams { 294 return GemsRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "gems"}} 295 } 296 297 type NpmRemoteRepositoryParams struct { 298 RemoteRepositoryBaseParams 299 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 300 } 301 302 func NewNpmRemoteRepositoryParams() NpmRemoteRepositoryParams { 303 return NpmRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "npm"}} 304 } 305 306 type BowerRemoteRepositoryParams struct { 307 RemoteRepositoryBaseParams 308 BowerRegistryUrl string `json:"bowerRegistryUrl,omitempty"` 309 } 310 311 func NewBowerRemoteRepositoryParams() BowerRemoteRepositoryParams { 312 return BowerRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "bower"}} 313 } 314 315 type DebianRemoteRepositoryParams struct { 316 RemoteRepositoryBaseParams 317 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 318 } 319 320 func NewDebianRemoteRepositoryParams() DebianRemoteRepositoryParams { 321 return DebianRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "debian"}} 322 } 323 324 type ComposerRemoteRepositoryParams struct { 325 RemoteRepositoryBaseParams 326 ComposerRegistryUrl string `json:"composerRegistryUrl,omitempty"` 327 } 328 329 func NewComposerRemoteRepositoryParams() ComposerRemoteRepositoryParams { 330 return ComposerRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "composer"}} 331 } 332 333 type PypiRemoteRepositoryParams struct { 334 RemoteRepositoryBaseParams 335 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 336 PypiRegistryUrl string `json:"pypiRegistryUrl,omitempty"` 337 } 338 339 func NewPypiRemoteRepositoryParams() PypiRemoteRepositoryParams { 340 return PypiRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "pypi"}} 341 } 342 343 type DockerRemoteRepositoryParams struct { 344 RemoteRepositoryBaseParams 345 ExternalDependenciesEnabled *bool `json:"externalDependenciesEnabled,omitempty"` 346 ExternalDependenciesPatterns []string `json:"externalDependenciesPatterns,omitempty"` 347 EnableTokenAuthentication *bool `json:"enableTokenAuthentication,omitempty"` 348 } 349 350 func NewDockerRemoteRepositoryParams() DockerRemoteRepositoryParams { 351 return DockerRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "docker"}} 352 } 353 354 type GitlfsRemoteRepositoryParams struct { 355 RemoteRepositoryBaseParams 356 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 357 } 358 359 func NewGitlfsRemoteRepositoryParams() GitlfsRemoteRepositoryParams { 360 return GitlfsRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "gitlfs"}} 361 } 362 363 type VcsRemoteRepositoryParams struct { 364 RemoteRepositoryBaseParams 365 VcsGitProvider string `json:"vcsGitProvider,omitempty"` 366 VcsType string `json:"vcsType,omitempty"` 367 MaxUniqueSnapshots int `json:"maxUniqueSnapshots,omitempty"` 368 VcsGitDownloadUrl string `json:"vcsGitDownloadUrl,omitempty"` 369 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 370 } 371 372 func NewVcsRemoteRepositoryParams() VcsRemoteRepositoryParams { 373 return VcsRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "vcs"}} 374 } 375 376 type GenericRemoteRepositoryParams struct { 377 RemoteRepositoryBaseParams 378 ListRemoteFolderItems *bool `json:"listRemoteFolderItems,omitempty"` 379 } 380 381 func NewGenericRemoteRepositoryParams() GenericRemoteRepositoryParams { 382 return GenericRemoteRepositoryParams{RemoteRepositoryBaseParams: RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "generic"}} 383 } 384 385 type IvyRemoteRepositoryParams struct { 386 RemoteRepositoryBaseParams 387 } 388 389 func NewIvyRemoteRepositoryParams() IvyRemoteRepositoryParams { 390 return IvyRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "ivy"}} 391 } 392 393 type SbtRemoteRepositoryParams struct { 394 RemoteRepositoryBaseParams 395 } 396 397 func NewSbtRemoteRepositoryParams() SbtRemoteRepositoryParams { 398 return SbtRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "sbt"}} 399 } 400 401 type HelmRemoteRepositoryParams struct { 402 RemoteRepositoryBaseParams 403 } 404 405 func NewHelmRemoteRepositoryParams() HelmRemoteRepositoryParams { 406 return HelmRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "helm"}} 407 } 408 409 type CranRemoteRepositoryParams struct { 410 RemoteRepositoryBaseParams 411 } 412 413 func NewCranRemoteRepositoryParams() CranRemoteRepositoryParams { 414 return CranRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "cran"}} 415 } 416 417 type GoRemoteRepositoryParams struct { 418 RemoteRepositoryBaseParams 419 } 420 421 func NewGoRemoteRepositoryParams() GoRemoteRepositoryParams { 422 return GoRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "go"}} 423 } 424 425 type YumRemoteRepositoryParams struct { 426 RemoteRepositoryBaseParams 427 } 428 429 func NewYumRemoteRepositoryParams() YumRemoteRepositoryParams { 430 return YumRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "yum"}} 431 } 432 433 type P2RemoteRepositoryParams struct { 434 RemoteRepositoryBaseParams 435 } 436 437 func NewP2RemoteRepositoryParams() P2RemoteRepositoryParams { 438 return P2RemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "p2"}} 439 } 440 441 type ChefRemoteRepositoryParams struct { 442 RemoteRepositoryBaseParams 443 } 444 445 func NewChefRemoteRepositoryParams() ChefRemoteRepositoryParams { 446 return ChefRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "chef"}} 447 } 448 449 type PuppetRemoteRepositoryParams struct { 450 RemoteRepositoryBaseParams 451 } 452 453 func NewPuppetRemoteRepositoryParams() PuppetRemoteRepositoryParams { 454 return PuppetRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "puppet"}} 455 } 456 457 type CondaRemoteRepositoryParams struct { 458 RemoteRepositoryBaseParams 459 } 460 461 func NewCondaRemoteRepositoryParams() CondaRemoteRepositoryParams { 462 return CondaRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "conda"}} 463 } 464 465 type ConanRemoteRepositoryParams struct { 466 RemoteRepositoryBaseParams 467 } 468 469 func NewConanRemoteRepositoryParams() ConanRemoteRepositoryParams { 470 return ConanRemoteRepositoryParams{RemoteRepositoryBaseParams{Rclass: "remote", PackageType: "conan"}} 471 }