github.com/cobalt77/jfrog-client-go@v0.14.5/README.md (about) 1 # jfrog-client-go 2 3 | Branch | Status | 4 | :----: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | 5 | master | [](https://ci.appveyor.com/project/jfrog-ecosystem/jfrog-client-go/branch/master) | 6 | dev | [](https://ci.appveyor.com/project/jfrog-ecosystem/jfrog-client-go/branch/dev) | 7 8 ## Table of Contents 9 - [General](#general) 10 - [Pull Requests](#pull-requests) 11 - [Guidelines](#guidelines) 12 - [Tests](#tests) 13 - [General APIs](#general-apis) 14 - [Setting the Logger](#setting-the-logger) 15 - [Setting the Temp Dir](#setting-the-temp-dir) 16 - [Artifactory APIs](#artifactory-apis) 17 - [Creating Artifactory Service Manager](#creating-artifactory-service-manager) 18 - [Creating Artifactory Details](#creating-artifactory-details) 19 - [Creating Artifactory Service Config](#creating-artifactory-service-config) 20 - [Creating New Artifactory Service Manager](#creating-new-artifactory-service-manager) 21 - [Using Artifactory Services](#using-artifactory-services) 22 - [Uploading Files to Artifactory](#uploading-files-to-artifactory) 23 - [Downloading Files from Artifactory](#downloading-files-from-artifactory) 24 - [Copying Files in Artifactory](#copying-files-in-artifactory) 25 - [Moving Files in Artifactory](#moving-files-in-artifactory) 26 - [Deleting Files from Artifactory](#deleting-files-from-artifactory) 27 - [Searching Files in Artifactory](#searching-files-in-artifactory) 28 - [Setting Properties on Files in Artifactory](#setting-properties-on-files-in-artifactory) 29 - [Deleting Properties from Files in Artifactory](#deleting-properties-from-files-in-artifactory) 30 - [Publishing Build Info to Artifactory](#publishing-build-info-to-artifactory) 31 - [Fetching Build Info from Artifactory](#fetching-build-info-from-artifactory) 32 - [Promoting Published Builds in Artifactory](#promoting-published-builds-in-artifactory) 33 - [Promoting a Docker Image in Artifactory](#promoting-a-docker-image-in-artifactory) 34 - [Distributing Published Builds to JFrog Bintray](#distributing-published-builds-to-jFrog-bintray) 35 - [Triggering Build Scanning with JFrog Xray](#triggering-build-scanning-with-jFrog-xray) 36 - [Discarding Old Builds](#discarding-old-builds) 37 - [Cleaning Unreferenced Git LFS Files from Artifactory](#cleaning-unreferenced-git-lfs-files-from-artifactory) 38 - [Executing AQLs](#executing-aqls) 39 - [Reading Files in Artifactory](#reading-files-in-artifactory) 40 - [Creating an Access Token](#creating-an-access-token) 41 - [Fetching Access Tokens](#fetching-access-tokens) 42 - [Refreshing an Access Token](#refreshing-an-access-token) 43 - [Revoking an Access Token](#revoking-an-access-token) 44 - [Regenerate API Key](#regenerate-api-key) 45 - [Creating and Updating Local Repository](#creating-and-updating-local-repository) 46 - [Creating and Updating Remote Repository](#creating-and-updating-remote-repository) 47 - [Creating and Updating Virtual Repository](#creating-and-updating-virtual-repository) 48 - [Getting Repository Details](#getting-repository-details) 49 - [Creating and Updating Repository Replications](#creating-and-updating-repository-replications) 50 - [Getting a Repository Replication](#getting-a-repository-replication) 51 - [Removing a Repository Replication](#removing-a-repository-replication) 52 - [Creating and Updating Permission Targets](#creating-and-updating-permission-targets) 53 - [Removing a Permission Target](#removing-a-permission-target) 54 - [Fetching Artifactory's Version](#fetching-artifactorys-version) 55 - [Fetching Artifactory's Service ID](#fetching-artifactorys-service-id) 56 - [Distribution APIs](#distribution-apis) 57 - [Creating Distribution Service Manager](#creating-distribution-service-manager) 58 - [Creating Distribution Details](#creating-distribution-details) 59 - [Creating Distribution Service Config](#creating-distribution-service-config) 60 - [Creating New Distribution Service Manager](#creating-new-distribution-service-manager) 61 - [Using Distribution Services](#using-distribution-services) 62 - [Setting Distribution Signing Key](#setting-distribution-signing-key) 63 - [Creating a Release Bundle](#creating-a-release-bundle) 64 - [Updating a Release Bundle](#updating-a-release-bundle) 65 - [Signing a Release Bundle](#signing-a-release-bundle) 66 - [Async Distributing a Release Bundle](#async-distributing-a-release-bundle) 67 - [Sync Distributing a Release Bundle](#sync-distributing-a-release-bundle) 68 - [Getting Distribution Status](#getting-distribution-status) 69 - [Deleting a Remote Release Bundle](#deleting-a-remote-release-bundle) 70 - [Deleting a Local Release Bundle](#deleting-a-local-release-bundle) 71 - [Bintray APIs](#bintray-apis) 72 - [Creating Bintray Details](#creating-bintray-details) 73 - [Creating Bintray Service Manager](#creating-bintray-service-manager) 74 - [Using Bintray Services](#using-bintray-services) 75 - [Uploading a Single File to Bintray](#uploading-a-single-file-to-bintray) 76 - [Downloading a Single File from Bintray](#downloading-a-single-file-from-bintray) 77 - [Downloading Version Files from Bintray](#downloading-version-files-from-bintray) 78 - [Showing and Deleting a Bintray Package](#showing-and-deleting-a-bintray-package) 79 - [Creating and Updating a Bintray Package](#creating-and-updating-a-bintray-package) 80 - [Showing and Deleting a Bintray Version](#showing-and-deleting-a-bintray-version) 81 - [Creating and Updating a Bintray Version](#creating-and-updating-a-bintray-version) 82 - [Creating and Updating Entitlements](#creating-and-updating-entitlements) 83 - [Showing and Deleting Entitlements](#showing-and-deleting-entitlements) 84 - [Creating and Updating Access Keys](#creating-and-updating-access-keys) 85 - [Showing and Deleting Access Keys](#showing-and-deleting-access-keys) 86 - [Signing a URL](#signing-a-url) 87 - [GPG Signing a File](#gpg-signing-a-file) 88 - [GPG Signing Version Files](#gpg-signing-version-files) 89 - [Listing Logs](#listing-logs) 90 - [Downloading Logs](#downloading-logs) 91 - [Using ContentReader](#using-contentreader) 92 93 ## General 94 _jfrog-client-go_ is a library which provides Go APIs to performs actions on JFrog Artifactory or Bintray from your Go application. 95 The project is still relatively new, and its APIs may therefore change frequently between releases. 96 The library can be used as a go-module, which should be added to your project's go.mod file. As a reference you may look at [JFrog CLI](https://github.com/jfrog/jfrog-cli-go)'s [go.mod](https://github.com/jfrog/jfrog-cli-go/blob/master/go.mod) file, which uses this library as a dependency. 97 98 ## Pull Requests 99 We welcome pull requests from the community. 100 101 ### Guidelines 102 - If the existing tests do not already cover your changes, please add tests. 103 - Pull requests should be created on the **dev** branch. 104 - Please use gofmt for formatting the code before submitting the pull request. 105 106 ## Tests 107 To run tests on the source code, you'll need a running JFrog Artifactory Pro instance. 108 Use the following command with the below options to run the tests. 109 ```sh 110 go test -v github.com/cobalt77/jfrog-client-go/tests 111 ``` 112 Optional flags: 113 114 | Flag | Description | 115 | ------------------- | ------------------------------------------------------------------------------------------------------ | 116 | `-rt.url` | [Default: http://localhost:8081/artifactory] Artifactory URL. | 117 | `-rt.user` | [Default: admin] Artifactory username. | 118 | `-rt.password` | [Default: password] Artifactory password. | 119 | `-rt.distUrl` | [Optional] JFrog Distribution URL. | 120 | `-rt.apikey` | [Optional] Artifactory API key. | 121 | `-rt.sshKeyPath` | [Optional] Ssh key file path. Should be used only if the Artifactory URL format is ssh://[domain]:port | 122 | `-rt.sshPassphrase` | [Optional] Ssh key passphrase. | 123 | `-rt.accessToken` | [Optional] Artifactory access token. | 124 | `-log-level` | [Default: INFO] Sets the log level. | 125 126 - The tests create an Artifactory repository named _jfrog-client-tests-repo1_.<br/> 127 Once the tests are completed, the content of this repository is deleted. 128 129 ## General APIs 130 ### Setting the Logger 131 ```go 132 var file *os.File 133 ... 134 log.SetLogger(log.NewLogger(log.INFO, file)) 135 ``` 136 137 ### Setting the Temp Dir 138 The default temp dir used is 'os.TempDir()'. Use the following API to set a new temp dir: 139 ```go 140 fileutils.SetTempDirBase(filepath.Join("my", "temp", "path")) 141 ``` 142 143 ## Artifactory APIs 144 ### Creating Artifactory Service Manager 145 #### Creating Artifactory Details 146 ```go 147 rtDetails := auth.NewArtifactoryDetails() 148 rtDetails.SetUrl("http://localhost:8081/artifactory") 149 rtDetails.SetSshKeysPath("path/to/.ssh/") 150 rtDetails.SetApiKey("apikey") 151 rtDetails.SetUser("user") 152 rtDetails.SetPassword("password") 153 rtDetails.SetAccessToken("accesstoken") 154 // if client certificates are required 155 rtDetails.SetClientCertPath("path/to/.cer") 156 rtDetails.SetClientCertKeyPath("path/to/.key") 157 ``` 158 159 #### Creating Artifactory Service Config 160 ```go 161 serviceConfig, err := config.NewConfigBuilder(). 162 SetServiceDetails(rtDetails). 163 SetCertificatesPath(certPath). 164 SetThreads(threads). 165 SetDryRun(false). 166 Build() 167 ``` 168 169 #### Creating New Artifactory Service Manager 170 ```go 171 rtManager, err := artifactory.New(&rtDetails, serviceConfig) 172 ``` 173 174 ### Using Artifactory Services 175 #### Uploading Files to Artifactory 176 ```go 177 params := services.NewUploadParams() 178 params.Pattern = "repo/*/*.zip" 179 params.Target = "repo/path/" 180 // Attach properties to the uploaded files. 181 params.Props = "key1=val1;key2=val2" 182 params.AddVcsProps = false 183 params.BuildProps = "build.name=buildName;build.number=17;build.timestamp=1600856623553" 184 params.Recursive = true 185 params.Regexp = false 186 params.IncludeDirs = false 187 params.Flat = true 188 params.Explode = false 189 params.Deb = "" 190 params.Symlink = false 191 // Retries default value: 3 192 params.Retries = 5 193 // MinChecksumDeploy default value: 10400 194 params.MinChecksumDeploy = 15360 195 196 rtManager.UploadFiles(params) 197 ``` 198 199 #### Downloading Files from Artifactory 200 ##### Downloading Files: 201 Using the `DownloadFiles()` function, we can download files and get the general statistics of the action (The actual number of files downloaded, and the number of files we expected to download), and the error value if it occurred. 202 ```go 203 params := services.NewDownloadParams() 204 params.Pattern = "repo/*/*.zip" 205 params.Target = "target/path/" 206 // Filter the downloaded files by properties. 207 params.Props = "key1=val1;key2=val2" 208 params.Recursive = true 209 params.IncludeDirs = false 210 params.Flat = false 211 params.Explode = false 212 params.Symlink = true 213 params.ValidateSymlink = false 214 // Retries default value: 3 215 params.Retries = 5 216 // SplitCount default value: 3 217 params.SplitCount = 2 218 // MinSplitSize default value: 5120 219 params.MinSplitSize = 7168 220 221 totalDownloaded, totalExpected, err := rtManager.DownloadFiles(params) 222 ``` 223 224 ##### Downloading Files with Results Reader: 225 Similar to `DownloadFiles()`, but returns a reader, which allows iterating over the details of the downloaded files. Only files which were successfully downloaded are available by the reader. 226 ```go 227 params := services.NewDownloadParams() 228 params.Pattern = "repo/*/*.zip" 229 params.Target = "target/path/" 230 // Filter the downloaded files by properties. 231 params.Props = "key1=val1;key2=val2" 232 params.Recursive = true 233 params.IncludeDirs = false 234 params.Flat = false 235 params.Explode = false 236 params.Symlink = true 237 params.ValidateSymlink = false 238 params.Retries = 5 239 params.SplitCount = 2 240 params.MinSplitSize = 7168 241 242 reader, totalDownloaded, totalExpected, err := rtManager.DownloadFilesWithResultReader(params) 243 ``` 244 Read more about [ContentReader](#using-contentReader). 245 246 #### Copying Files in Artifactory 247 ```go 248 params := services.NewMoveCopyParams() 249 params.Pattern = "repo/*/*.zip" 250 params.Target = "target/path/" 251 // Filter the files by properties. 252 params.Props = "key1=val1;key2=val2" 253 params.Recursive = true 254 params.Flat = false 255 256 rtManager.Copy(params) 257 ``` 258 259 #### Moving Files in Artifactory 260 ```go 261 params := services.NewMoveCopyParams() 262 params.Pattern = "repo/*/*.zip" 263 params.Target = "target/path/" 264 // Filter the files by properties. 265 params.Props = "key1=val1;key2=val2" 266 params.Recursive = true 267 params.Flat = false 268 269 rtManager.Move(params) 270 ``` 271 272 #### Deleting Files from Artifactory 273 ```go 274 params := services.NewDeleteParams() 275 params.Pattern = "repo/*/*.zip" 276 // Filter the files by properties. 277 params.Props = "key1=val1;key2=val2" 278 params.Recursive = true 279 280 pathsToDelete, err := rtManager.GetPathsToDelete(params) 281 if err != nil { 282 return err 283 } 284 defer pathsToDelete.Close() 285 rtManager.DeleteFiles(pathsToDelete) 286 ``` 287 Read more about [ContentReader](#using-contentReader). 288 289 #### Searching Files in Artifactory 290 ```go 291 params := services.NewSearchParams() 292 params.Pattern = "repo/*/*.zip" 293 // Filter the files by properties. 294 params.Props = "key1=val1;key2=val2" 295 params.Recursive = true 296 297 reader, err := rtManager.SearchFiles(params) 298 if err != nil { 299 return err 300 } 301 defer reader.Close() 302 ``` 303 Read more about [ContentReader](#using-contentReader). 304 305 #### Setting Properties on Files in Artifactory 306 ```go 307 searchParams = services.NewSearchParams() 308 searchParams.Recursive = true 309 searchParams.IncludeDirs = false 310 311 reader, err = rtManager.SearchFiles(searchParams) 312 if err != nil { 313 return err 314 } 315 defer reader.Close() 316 propsParams = services.NewPropsParams() 317 propsParams.Pattern = "repo/*/*.zip" 318 propsParams.Reader = reader 319 // Filter the files by properties. 320 propsParams.Props = "key=value" 321 322 rtManager.SetProps(propsParams) 323 ``` 324 Read more about [ContentReader](#using-contentReader). 325 326 #### Deleting Properties from Files in Artifactory 327 ```go 328 searchParams = services.NewSearchParams() 329 searchParams.Recursive = true 330 searchParams.IncludeDirs = false 331 332 resultItems, err = rtManager.SearchFiles(searchParams) 333 if err != nil { 334 return err 335 } 336 defer reader.Close() 337 propsParams = services.NewPropsParams() 338 propsParams.Pattern = "repo/*/*.zip" 339 propsParams.Reader = reader 340 // Filter the files by properties. 341 propsParams.Props = "key=value" 342 343 rtManager.DeleteProps(propsParams) 344 ``` 345 Read more about [ContentReader](#using-contentReader). 346 347 #### Publishing Build Info to Artifactory 348 ```go 349 buildInfo := &buildinfo.BuildInfo{} 350 ... 351 rtManager.PublishBuildInfo(buildInfo) 352 ``` 353 354 #### Fetching Build Info from Artifactory 355 ```go 356 buildInfoParams := services.NewBuildInfoParams{} 357 buildInfoParams.BuildName = "buildName" 358 buildInfoParams.BuildNumber = "LATEST" 359 360 rtManager.GetBuildInfo(buildInfoParams) 361 ``` 362 363 #### Promoting Published Builds in Artifactory 364 ```go 365 params := services.NewPromotionParams() 366 params.BuildName = "buildName" 367 params.BuildNumber = "10" 368 params.TargetRepo = "target-repo" 369 params.Status = "status" 370 params.Comment = "comment" 371 params.Copy = true 372 params.IncludeDependencies = false 373 params.SourceRepo = "source-repo" 374 375 rtManager.DownloadFiles(params) 376 ``` 377 378 #### Promoting a Docker Image in Artifactory 379 ```go 380 sourceDockerImage := "hello-world" 381 sourceRepo := "docker-local-1" 382 targetRepo := "docker-local-2" 383 params := services.NewDockerPromoteParams(sourceDockerImage, sourceRepo, targetRepo) 384 385 // Optional parameters: 386 params.TargetDockerImage = "target-docker-image" 387 params.SourceTag = "42" 388 params.TargetTag = "43" 389 params.Copy = true 390 391 rtManager.PromoteDocker(params) 392 ``` 393 394 #### Distributing Published Builds to JFrog Bintray 395 ```go 396 params := services.NewBuildDistributionParams() 397 params.SourceRepos = "source-repo" 398 params.TargetRepo = "target-repo" 399 params.GpgPassphrase = "GpgPassphrase" 400 params.Publish = false 401 params.OverrideExistingFiles = false 402 params.Async = true 403 params.BuildName = "buildName" 404 params.BuildNumber = "10" 405 params.Pattern = "repo/*/*.zip" 406 407 rtManager.DistributeBuild(params) 408 ``` 409 410 #### Triggering Build Scanning with JFrog Xray 411 ```go 412 params := services.NewXrayScanParams() 413 params.BuildName = buildName 414 params.BuildNumber = buildNumber 415 416 rtManager.XrayScanBuild(params) 417 ``` 418 419 #### Discarding Old Builds 420 ```go 421 params := services.NewDiscardBuildsParams() 422 params.BuildName = "buildName" 423 params.MaxDays = "max-days" 424 params.MaxBuilds = "max-builds" 425 params.ExcludeBuilds = "1,2" 426 params.DeleteArtifacts = false 427 params.Async = false 428 429 rtManager.DiscardBuilds(params) 430 ``` 431 432 #### Cleaning Unreferenced Git LFS Files from Artifactory 433 ```go 434 params := services.NewGitLfsCleanParams() 435 params.Refs = "refs/remotes/*" 436 params.Repo = "my-project-lfs" 437 params.GitPath = "path/to/git" 438 439 reader,err := rtManager.GetUnreferencedGitLfsFiles(params) 440 441 defer reader.Close() 442 rtManager.DeleteFiles(reader) 443 ``` 444 445 #### Executing AQLs 446 ```go 447 rtManager.Aql(aql string) 448 ``` 449 450 #### Reading Files in Artifactory 451 ```go 452 rtManager.ReadRemoteFile(FilePath string) 453 ``` 454 455 #### Creating an Access Token 456 ```go 457 params := services.NewCreateTokenParams() 458 params.Scope = "api:* member-of-groups:readers" 459 params.Username = "user" 460 params.ExpiresIn = 3600 // default -1 (use server default) 461 params.GrantType = "client_credentials" 462 params.Refreshable = true 463 params.Audience = "jfrt@<serviceID1> jfrt@<serviceID2>" 464 465 results, err := rtManager.CreateToken(params) 466 ``` 467 468 #### Fetching Access Tokens 469 ```go 470 results, err := rtManager.GetTokens() 471 ``` 472 473 #### Refreshing an Access Token 474 ```go 475 params := services.NewRefreshTokenParams() 476 params.AccessToken = "<access token>" 477 params.RefreshToken = "<refresh token>" 478 params.Token.Scope = "api:*" 479 params.Token.ExpiresIn = 3600 480 results, err := rtManager.RefreshToken(params) 481 ``` 482 483 #### Revoking an Access Token 484 ```go 485 params := services.NewRevokeTokenParams() 486 487 // Provide either TokenId or Token 488 params.TokenId = "<token id>" 489 // params.Token = "access token" 490 491 err := rtManager.RevokeToken(params) 492 ``` 493 494 #### Regenerate API Key 495 ```go 496 apiKey, err := rtManager.RegenerateAPIKey() 497 ``` 498 499 #### Creating and Updating Local Repository 500 You can create and update a local repository for the following package types: 501 502 Maven, Gradle, Ivy, Sbt, Helm, Cocoapods, Opkg, Rpm, Nuget, Cran, Gems, Npm, Bower, Debian, Composer, Pypi, Docker, 503 Vagrant, Gitlfs, Go, Yum, Conan, Chef, Puppet and Generic. 504 505 Each package type has it's own parameters struct, can be created using the method 506 `New<packageType>LocalRepositoryParams()`. 507 508 Example for creating local Generic repository: 509 ```go 510 params := services.NewGenericLocalRepositoryParams() 511 params.Key = "generic-repo" 512 params.Description = "This is a public description for generic-repo" 513 params.Notes = "These are internal notes for generic-repo" 514 params.RepoLayoutRef = "simple-default" 515 params.ArchiveBrowsingEnabled = true 516 params.XrayIndex = true 517 params.IncludesPattern = "**/*" 518 params.ExcludesPattern = "excludedDir/*" 519 params.DownloadRedirect = true 520 521 err = servicesManager.CreateLocalRepository().Generic(params) 522 ``` 523 524 Updating local Generic repository: 525 ```go 526 err = servicesManager.UpdateLocalRepository().Generic(params) 527 ``` 528 529 #### Creating and Updating Remote Repository 530 You can create and update a remote repository for the following package types: 531 532 Maven, Gradle, Ivy, Sbt, Helm, Cocoapods, Opkg, Rpm, Nuget, Cran, Gems, Npm, Bower, Debian, Composer, Pypi, Docker, 533 Gitlfs, Go, Yum, Conan, Chef, Puppet, Conda, P2, Vcs and Generic. 534 535 Each package type has it's own parameters struct, can be created using the method 536 `New<packageType>RemoteRepositoryParams()`. 537 538 Example for creating remote Maven repository: 539 ```go 540 params := services.NewMavenRemoteRepositoryParams() 541 params.Key = "jcenter-remote" 542 params.Url = "http://jcenter.bintray.com" 543 params.RepoLayoutRef = "maven-2-default" 544 params.Description = "A caching proxy repository for a JFrog's jcenter" 545 params.HandleSnapshot = false 546 params.HandleReleases = true 547 params.FetchJarsEagerly = true 548 params.AssumedOfflinePeriodSecs = 600 549 params.SuppressPomConsistencyChecks = true 550 params.RemoteRepoChecksumPolicyType = "pass-thru" 551 552 err = servicesManager.CreateRemoteRepository().Maven(params) 553 ``` 554 555 Updating remote Maven repository: 556 ```go 557 err = servicesManager.UpdateRemoteRepository().Maven(params) 558 ``` 559 560 #### Creating and Updating Virtual Repository 561 You can create and update a virtual repository for the following package types: 562 563 Maven, Gradle, Ivy, Sbt, Helm, Rpm, Nuget, Cran, Gems, Npm, Bower, Debian, Pypi, Docker, Gitlfs, Go, Yum, Conan, 564 Chef, Puppet, Conda, P2 and Generic 565 566 Each package type has it's own parameters struct, can be created using the method 567 `New<packageType>VirtualRepositoryParams()`. 568 569 Example for creating virtual Go repository: 570 ```go 571 params := services.NewGoVirtualRepositoryParams() 572 params.Description = "This is an aggregated repository for several go repositories" 573 params.RepoLayoutRef = "go-default" 574 params.Repositories = {"gocenter-remote", "go-local"} 575 params.DefaultDeploymentRepo = "go-local" 576 params.ExternalDependenciesEnabled = true 577 params.ExternalDependenciesPatterns = {"**/github.com/**", "**/golang.org/**", "**/gopkg.in/**"} 578 params.ArtifactoryRequestsCanRetrieveRemoteArtifacts = true 579 580 err = servicesManager.CreateVirtualRepository().Go(params) 581 ``` 582 583 Updating remote Maven repository: 584 ```go 585 err = servicesManager.UpdateVirtualRepository().Go(params) 586 ``` 587 588 #### Removing a Repository 589 You can remove a repository from Artifactory using its key: 590 ```go 591 servicesManager.DeleteRepository("generic-repo") 592 ``` 593 594 #### Getting Repository Details 595 You can get repository details from Artifactory using its key: 596 ```go 597 servicesManager.GetRepository("generic-repo") 598 ``` 599 600 #### Creating and Updating Repository Replications 601 Example of creating a repository replication: 602 ```go 603 params := services.NewCreateReplicationParams() 604 // Source replication repository. 605 params.RepoKey = "my-repository" 606 params.CronExp = "0 0 12 * * ?" 607 params.Username = "admin" 608 params.Password = "password" 609 params.Url = "http://localhost:8081/artifactory/remote-repo" 610 params.Enabled = true 611 params.SocketTimeoutMillis = 15000 612 params.EnableEventReplication = true 613 params.SyncDeletes = true 614 params.SyncProperties = true 615 params.SyncStatistics = true 616 params.PathPrefix = "/path/to/repo" 617 618 err = servicesManager.CreateReplication(params) 619 ``` 620 621 Example of updating a local repository replication: 622 ```go 623 params := services.NewUpdateReplicationParams() 624 // Source replication repository. 625 params.RepoKey = "my-repository" 626 params.CronExp = "0 0 12 * * ?" 627 params.Enabled = true 628 params.SocketTimeoutMillis = 15000 629 params.EnableEventReplication = true 630 params.SyncDeletes = true 631 params.SyncProperties = true 632 params.SyncStatistics = true 633 params.PathPrefix = "/path/to/repo" 634 635 err = servicesManager.UpdateReplication(params) 636 ``` 637 638 #### Getting a Repository Replication 639 You can get a repository replication configuration from Artifactory using its key: 640 ```go 641 replicationConfiguration, err := servicesManager.GetReplication("my-repository") 642 ``` 643 644 #### Removing a Repository Replication 645 You can remove a repository replication configuration from Artifactory using its key: 646 ```go 647 err := servicesManager.DeleteReplication("my-repository") 648 ``` 649 650 #### Creating and Updating Permission Targets 651 You can create or update a permission target in Artifactory. 652 Permissions are set according to the following conventions: 653 `read, write, annotate, delete, manage, managedXrayMeta, distribute` 654 For repositories You can specify the name `"ANY"` in order to apply to all repositories, `"ANY REMOTE"` for all remote repositories or `"ANY LOCAL"` for all local repositories. 655 656 Creating a new permission target : 657 ```go 658 params := services.NewPermissionTargetParams() 659 params.Name = "java-developers" 660 params.Repo.Repositories = []string{"ANY REMOTE", "local-repo1", "local-repo2"} 661 params.Repo.ExcludePatterns = []string{"dir/*"} 662 params.Repo.Actions.Users = map[string][]string { 663 "user1" : {"read", "write"}, 664 "user2" : {"write","annotate", "read"}, 665 } 666 params.Repo.Actions.Groups = map[string][]string { 667 "group1" : {"manage","read","annotate"}, 668 } 669 // This is the default value that cannot be changed 670 params.Build.Repositories = []string{"artifactory-build-info"} 671 params.Build.Actions.Groups = map[string][]string { 672 "group1" : {"manage","read","write","annotate","delete"}, 673 "group2" : {"read"}, 674 675 } 676 677 err = servicesManager.CreatePermissionTarget(params) 678 ``` 679 Updating an existing permission target : 680 ```go 681 err = servicesManager.UpdatePermissionTarget(params) 682 ``` 683 684 #### Removing a Permission Target 685 You can remove a permission target from Artifactory using its name: 686 ```go 687 servicesManager.DeletePermissionTarget("java-developers") 688 ``` 689 690 #### Fetching Artifactory's Version 691 ```go 692 version, err := servicesManager.GetVersion() 693 ``` 694 695 #### Fetching Artifactory's Service ID 696 ```go 697 serviceId, err := servicesManager.GetServiceId() 698 ``` 699 700 ## Distribution APIs 701 ### Creating Distribution Service Manager 702 #### Creating Distribution Details 703 ```go 704 distDetails := auth.NewDistributionDetails() 705 distDetails.SetUrl("http://localhost:8081/distribution") 706 distDetails.SetSshKeysPath("path/to/.ssh/") 707 distDetails.SetApiKey("apikey") 708 distDetails.SetUser("user") 709 distDetails.SetPassword("password") 710 distDetails.SetAccessToken("accesstoken") 711 // if client certificates are required 712 distDetails.SetClientCertPath("path/to/.cer") 713 distDetails.SetClientCertKeyPath("path/to/.key") 714 ``` 715 716 #### Creating Distribution Service Config 717 ```go 718 serviceConfig, err := config.NewConfigBuilder(). 719 SetServiceDetails(rtDetails). 720 SetCertificatesPath(certPath). 721 SetThreads(threads). 722 SetDryRun(false). 723 Build() 724 ``` 725 726 #### Creating New Distribution Service Manager 727 ```go 728 distManager, err := distribution.New(&distDetails, serviceConfig) 729 ``` 730 731 ### Using Distribution Services 732 #### Setting Distribution Signing Key 733 ```go 734 params := services.NewSetSigningKeyParams("private-gpg-key", "public-gpg-key") 735 736 err := distManager.SetSigningKey(params) 737 ``` 738 739 #### Creating a Release Bundle 740 ```go 741 params := services.NewCreateReleaseBundleParams("bundle-name", "1") 742 params.SpecFiles = []*utils.ArtifactoryCommonParams{{Pattern: "repo/*/*.zip"}} 743 params.Description = "Description" 744 params.ReleaseNotes = "Release notes" 745 params.ReleaseNotesSyntax = "plain_text" 746 747 err := distManager.CreateReleaseBundle(params) 748 ``` 749 750 #### Updating a Release Bundle 751 ```go 752 params := services.NewUpdateReleaseBundleParams("bundle-name", "1") 753 params.SpecFiles = []*utils.ArtifactoryCommonParams{{Pattern: "repo/*/*.zip"}} 754 params.Description = "New Description" 755 params.ReleaseNotes = "New Release notes" 756 params.ReleaseNotesSyntax = "plain_text" 757 758 err := distManager.CreateReleaseBundle(params) 759 ``` 760 761 #### Signing a Release Bundle 762 ```go 763 params := services.NewSignBundleParams("bundle-name", "1") 764 params.GpgPassphrase = "123456" 765 766 err := distManager.SignReleaseBundle(params) 767 ``` 768 769 #### Async Distributing a Release Bundle 770 ```go 771 params := services.NewDistributeReleaseBundleParams("bundle-name", "1") 772 distributionRules := utils.DistributionCommonParams{SiteName: "Swamp-1", "CityName": "Tel-Aviv", "CountryCodes": []string{"123"}}} 773 params.DistributionRules = []*utils.DistributionCommonParams{distributionRules} 774 775 err := distManager.DistributeReleaseBundle(params) 776 ``` 777 778 #### Sync Distributing a Release Bundle 779 ```go 780 params := services.NewDistributeReleaseBundleParams("bundle-name", "1") 781 distributionRules := utils.DistributionCommonParams{SiteName: "Swamp-1", "CityName": "Tel-Aviv", "CountryCodes": []string{"123"}}} 782 params.DistributionRules = []*utils.DistributionCommonParams{distributionRules} 783 // Wait up to 120 minutes for the release bundle distribution 784 err := distManager.DistributeReleaseBundleSync(params, 120) 785 ``` 786 787 #### Getting Distribution Status 788 ```go 789 params := services.NewDistributionStatusParams() 790 // Optional parameters: 791 // If missing, get status for all distributions 792 params.Name = "bundle-name" 793 // If missing, get status for all versions of "bundle-name" 794 params.Version = "1" 795 // If missing, get status for all "bundle-name" with version "1" 796 params.TrackerId = "123456789" 797 798 status, err := distributeBundleService.GetStatus(params) 799 ``` 800 801 #### Deleting a Remote Release Bundle 802 ```go 803 params := services.NewDeleteReleaseBundleParams("bundle-name", "1") 804 params.DeleteFromDistribution = true 805 distributionRules := utils.DistributionCommonParams{SiteName: "Swamp-1", "CityName": "Tel-Aviv", "CountryCodes": []string{"123"}}} 806 params.DistributionRules = []*utils.DistributionCommonParams{distributionRules} 807 808 err := distManager.DeleteReleaseBundle(params) 809 ``` 810 811 #### Deleting a Local Release Bundle 812 ```go 813 params := services.NewDeleteReleaseBundleParams("bundle-name", "1") 814 815 err := distManager.DeleteLocalReleaseBundle(params) 816 ``` 817 818 ## Bintray APIs 819 ### Creating Bintray Details 820 ```go 821 btDetails := auth.NewBintrayDetails() 822 btDetails.SetUser("user") 823 btDetails.SetKey("key") 824 btDetails.SetDefPackageLicense("Apache 2.0") 825 ``` 826 827 ### Creating Bintray Service Manager 828 ```go 829 serviceConfig := bintray.NewConfigBuilder(). 830 SetBintrayDetails(btDetails). 831 SetDryRun(false). 832 SetThreads(threads). 833 Build() 834 835 btManager, err := bintray.New(serviceConfig) 836 ``` 837 838 ### Using Bintray Services 839 #### Uploading a Single File to Bintray 840 ```go 841 params := services.NewUploadParams() 842 params.Pattern = "*/*.zip" 843 params.Path = versions.CreatePath("subject/repo/pkg/version") 844 params.TargetPath = "path/to/files" 845 params.Deb = "distribution/component/architecture" 846 params.Recursive = true 847 params.Flat = true 848 params.Publish = false 849 params.Override = false 850 params.Explode = false 851 params.UseRegExp = false 852 params.ShowInDownloadList = false 853 854 btManager.UploadFiles(params) 855 ``` 856 857 #### Downloading a Single File from Bintray 858 ```go 859 params := services.NewDownloadFileParams() 860 params.Flat = false 861 params.IncludeUnpublished = false 862 params.PathDetails = "path/to/file" 863 params.TargetPath = "target/path/" 864 // SplitCount default value: 3 865 params.SplitCount = 2 866 // MinSplitSize default value: 5120 867 params.MinSplitSize = 7168 868 869 btManager.DownloadFile(params) 870 ``` 871 872 #### Downloading Version Files from Bintray 873 ```go 874 params := services.NewDownloadVersionParams() 875 params.Path, err = versions.CreatePath("subject/repo/pkg/version") 876 877 params.IncludeUnpublished = false 878 params.TargetPath = "target/path/" 879 880 btManager.DownloadVersion(params) 881 ``` 882 883 #### Showing and Deleting a Bintray Package 884 ```go 885 pkgPath, err := packages.CreatePath("subject/repo/pkg") 886 887 btManager.ShowPackage(pkgPath) 888 btManager.DeletePackage(pkgPath) 889 ``` 890 891 #### Creating and Updating a Bintray Package 892 ```go 893 params := packages.NewPackageParams() 894 params.Path, err = packages.CreatePath("subject/repo/pkg") 895 896 params.Desc = "description" 897 params.Labels = "labels" 898 params.Licenses = "licences" 899 params.CustomLicenses = "custum-licenses" 900 params.VcsUrl = "https://github.com/jfrog/jfrog-cli-go" 901 params.WebsiteUrl = "https://jfrog.com" 902 params.IssueTrackerUrl = "https://github.com/bintray/bintray-client-java/issues" 903 params.GithubRepo = "bintray/bintray-client-java" 904 params.GithubReleaseNotesFile = "RELEASE_1.2.3.txt" "github-rel-notes" 905 params.PublicDownloadNumbers = "true" 906 params.PublicStats = "true" 907 908 btManager.CreatePackage(params) 909 btManager.UpdatePackage(params) 910 ``` 911 912 #### Showing and Deleting a Bintray Version 913 ```go 914 versionPath, err := versions.CreatePath("subject/repo/pkg/version") 915 916 btManager.ShowVersion(versionPath) 917 btManager.DeleteVersion(versionPath) 918 ``` 919 920 #### Creating and Updating a Bintray Version 921 ```go 922 params := versions.NewVersionParams() 923 params.Path, err = versions.CreatePath("subject/repo/pkg/version") 924 925 params.Desc = "description" 926 params.VcsTag = "1.1.5" 927 params.Released = "true" 928 params.GithubReleaseNotesFile = "RELEASE_1.2.3.txt" 929 params.GithubUseTagReleaseNotes = "false" 930 931 btManager.CreateVersion(params) 932 btManager.UpdateVersion(params) 933 ``` 934 935 #### Creating and Updating Entitlements 936 ```go 937 params := entitlements.NewEntitlementsParams() 938 params.VersionPath, err = versions.CreatePath("subject/repo/pkg/version") 939 940 params.Path = "a/b/c" 941 params.Access = "rw" 942 params.Keys = "keys" 943 944 btManager.CreateEntitlement(params) 945 946 params.Id = "entitlementID" 947 btManager.UpdateEntitlement(params) 948 ``` 949 950 #### Showing and Deleting Entitlements 951 ```go 952 versionPath, err := versions.CreatePath("subject/repo/pkg/version") 953 954 btManager.ShowAllEntitlements(versionPath) 955 btManager.ShowEntitlement("entitelmentID", versionPath) 956 btManager.DeleteEntitlement("entitelmentID", versionPath) 957 ``` 958 959 #### Creating and Updating Access Keys 960 ```go 961 params := accesskeys.NewAccessKeysParams() 962 params.Password = "password" 963 params.Org = "org" 964 params.Expiry = time.Now() + time.Hour * 10 965 params.ExistenceCheckUrl = "http://callbacks.myci.org/username=:username,password=:password" 966 params.ExistenceCheckCache = 60 967 params.WhiteCidrs = "127.0.0.1/22,193.5.0.1/92" 968 params.BlackCidrs = "127.0.0.1/22,193.5.0.1/92" 969 params.ApiOnly = true 970 971 btManager.CreateAccessKey(params) 972 973 params.Id = "KeyID" 974 btManager.UpdateAccessKey(params) 975 ``` 976 977 #### Showing and Deleting Access Keys 978 ```go 979 btManager.ShowAllAccessKeys("org") 980 btManager.ShowAccessKey("org", "KeyID") 981 btManager.DeleteAccessKey("org", "KeyID") 982 ``` 983 984 #### Signing a URL 985 ```go 986 params := url.NewURLParams() 987 params.PathDetails, err = utils.CreatePathDetails("subject/repository/file-path") 988 // Check for errors 989 params.Expiry = time.Now() + time.Hour * 10 990 params.ValidFor = 60 991 params.CallbackId = "callback-id" 992 params.CallbackEmail = "callback-email" 993 params.CallbackUrl = "callback-url" 994 params.CallbackMethod = "callback-method" 995 996 btManager.SignUrl(params) 997 ``` 998 999 #### GPG Signing a File 1000 ```go 1001 path, err := utils.CreatePathDetails("subject/repository/file-path") 1002 1003 btManager.GpgSignFile(path, "passphrase") 1004 ``` 1005 1006 #### GPG Signing Version Files 1007 ```go 1008 path, err := versions.CreatePath("subject/repo/pkg/version") 1009 1010 btManager.GpgSignVersion(path, "passphrase") 1011 ``` 1012 1013 #### Listing Logs 1014 ```go 1015 path, err := versions.CreatePath("subject/repo/pkg/version") 1016 1017 btManager.LogsList(versionPath) 1018 ``` 1019 1020 #### Downloading Logs 1021 ```go 1022 path, err := versions.CreatePath("subject/repo/pkg/version") 1023 1024 btManager.DownloadLog(path, "logName") 1025 ``` 1026 1027 #### Syncing Content To Maven Central 1028 ```go 1029 params := mavensync.NewParams("user","password", false) 1030 path, err = versions.CreatePath("subject/repo/pkg/version") 1031 1032 btManager.MavenCentralContentSync(params, path) 1033 ``` 1034 1035 ## Using ContentReader 1036 Some APIs return a content.ContentReader which allow reading the API output. 1037 Here's an example for how it can be used: 1038 1039 ```go 1040 reader, err := servicesManager.SearchFiles(searchParams) 1041 if err != nil { 1042 return err 1043 } 1044 defer reader.Close() 1045 // Iterate over the results. 1046 for currentResult := new(ResultItem); reader.NextRecord(currentResult) == nil; currentResult = new(ResultItem) { 1047 fmt.Printf("Found artifact: %s of type: %s\n", searchResult.Name, searchResult.Type) 1048 } 1049 if err := resultReader.GetError(); err != nil { 1050 return err 1051 } 1052 resultReader.Reset() 1053 ``` 1054 1055 `reader.NextRecord(currentResult)` loads the next record from the reader into `currentResult` of type `ResultItem`. 1056 1057 `reader.Close()` removes the file used by the reader after it is used (preferably using `defer`). 1058 1059 `reader.GetError()` any error that may occur during `NextRecord()`, can be returned using `GetError()`. 1060 1061 `reader.Reset()` sets the reader back to the begging of the input.