github.com/mondo192/jfrog-client-go@v1.0.0/README.md (about) 1 [![](readme_image.png)](#readme) 2 3 <div align="center"> 4 5 # JFrog Go Client 6 7 </div> 8 9 | Branch | Status | 10 |:------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| 11 | master | [![Build status](https://github.com/mondo192/jfrog-client-go/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/mondo192/jfrog-client-go/actions) [![Static Analysis](https://github.com/mondo192/jfrog-client-go/actions/workflows/analysis.yml/badge.svg?branch=master)](https://github.com/mondo192/jfrog-client-go/actions/workflows/analysis.yml) | 12 | dev | [![Build status](https://github.com/mondo192/jfrog-client-go/actions/workflows/tests.yml/badge.svg?branch=dev)](https://github.com/mondo192/jfrog-client-go/actions) [![Static Analysis](https://github.com/mondo192/jfrog-client-go/actions/workflows/analysis.yml/badge.svg?branch=dev)](https://github.com/mondo192/jfrog-client-go/actions/workflows/analysis.yml) | 13 14 ## Table of Contents 15 16 - [JFrog Go Client](#jfrog-go-client) 17 - [Table of Contents](#table-of-contents) 18 - [General](#general) 19 - [Pull Requests](#pull-requests) 20 - [Guidelines](#guidelines) 21 - [Tests](#tests) 22 - [Flags](#flags) 23 - [Test Types](#test-types) 24 - [Connection Details](#connection-details) 25 - [General APIs](#general-apis) 26 - [Setting the Logger](#setting-the-logger) 27 - [Setting the Temp Dir](#setting-the-temp-dir) 28 - [Artifactory APIs](#artifactory-apis) 29 - [Creating Artifactory Service Manager](#creating-artifactory-service-manager) 30 - [Creating Artifactory Details](#creating-artifactory-details) 31 - [Creating Artifactory Details with Custom HTTP Client](#creating-artifactory-details-with-custom-http-client) 32 - [Creating Artifactory Service Config](#creating-artifactory-service-config) 33 - [Creating New Artifactory Service Manager](#creating-new-artifactory-service-manager) 34 - [Using Artifactory Services](#using-artifactory-services) 35 - [Uploading Files to Artifactory](#uploading-files-to-artifactory) 36 - [Downloading Files from Artifactory](#downloading-files-from-artifactory) 37 - [Downloading Release Bundles from Artifactory](#downloading-release-bundles-from-artifactory) 38 - [Uploading and Downloading Files with Summary](#uploading-and-downloading-files-with-summary) 39 - [Copying Files in Artifactory](#copying-files-in-artifactory) 40 - [Moving Files in Artifactory](#moving-files-in-artifactory) 41 - [Deleting Files from Artifactory](#deleting-files-from-artifactory) 42 - [Searching Files in Artifactory](#searching-files-in-artifactory) 43 - [Setting Properties on Files in Artifactory](#setting-properties-on-files-in-artifactory) 44 - [Deleting Properties from Files in Artifactory](#deleting-properties-from-files-in-artifactory) 45 - [Getting Properties from Files in Artifactory](#getting-properties-from-files-in-artifactory) 46 - [Publishing Build Info to Artifactory](#publishing-build-info-to-artifactory) 47 - [Fetching Build Info from Artifactory](#fetching-build-info-from-artifactory) 48 - [Promoting Published Builds in Artifactory](#promoting-published-builds-in-artifactory) 49 - [Promoting a Docker Image in Artifactory](#promoting-a-docker-image-in-artifactory) 50 - [Triggering Build Scanning with JFrog Xray](#triggering-build-scanning-with-jfrog-xray) 51 - [Discarding Old Builds](#discarding-old-builds) 52 - [Cleaning Unreferenced Git LFS Files from Artifactory](#cleaning-unreferenced-git-lfs-files-from-artifactory) 53 - [Executing AQLs](#executing-aqls) 54 - [Reading Files in Artifactory](#reading-files-in-artifactory) 55 - [Creating an Access Token](#creating-an-access-token) 56 - [Fetching Access Tokens](#fetching-access-tokens) 57 - [Fetching Access Tokens of a User](#fetching-access-tokens-of-a-user) 58 - [Refreshing an Access Token](#refreshing-an-access-token) 59 - [Revoking an Access Token](#revoking-an-access-token) 60 - [Create API Key](#create-api-key) 61 - [Regenerate API Key](#regenerate-api-key) 62 - [Get API Key](#get-api-key) 63 - [Creating and Updating Local Repository](#creating-and-updating-local-repository) 64 - [Creating and Updating Remote Repository](#creating-and-updating-remote-repository) 65 - [Creating and Updating Virtual Repository](#creating-and-updating-virtual-repository) 66 - [Creating and Updating Federated Repository](#creating-and-updating-federated-repository) 67 - [Removing a Repository](#removing-a-repository) 68 - [Getting Repository Details](#getting-repository-details) 69 - [Getting All Repositories](#getting-all-repositories) 70 - [Check if Repository Exists](#check-if-repository-exists) 71 - [Creating and Updating Repository Replications](#creating-and-updating-repository-replications) 72 - [Getting a Repository Replication](#getting-a-repository-replication) 73 - [Removing a Repository Replication](#removing-a-repository-replication) 74 - [Converting a Local Repository to a Federated Repository](#converting-a-local-repository-to-a-federated-repository) 75 - [Triggering a Full Federated Repository Synchronisation](#triggering-a-full-federated-repository-synchronisation) 76 - [Creating and Updating Permission Targets](#creating-and-updating-permission-targets) 77 - [Removing a Permission Target](#removing-a-permission-target) 78 - [Fetching a Permission Target](#fetching-a-permission-target) 79 - [Fetching Artifactory's Version](#fetching-artifactorys-version) 80 - [Fetching Running Artifactory Nodes in a Cluster](#fetching-running-artifactory-nodes-in-a-cluster) 81 - [Fetching Artifactory's Service ID](#fetching-artifactorys-service-id) 82 - [Fetching Artifactory's Config Descriptor](#fetching-artifactorys-config-descriptor) 83 - [Activating Artifactory's Key Encryption](#activating-artifactorys-key-encryption) 84 - [Deactivating Artifactory's Key Encryption](#deactivating-artifactorys-key-encryption) 85 - [Fetching Users Details](#fetching-users-details) 86 - [Fetching All Users Details](#fetching-all-users-details) 87 - [Creating Inviting and Updating a User](#creating-inviting-and-updating-a-user) 88 - [Deleting a User](#deleting-a-user) 89 - [Fetching All Groups](#fetching-all-groups) 90 - [Fetching Group Details](#fetching-group-details) 91 - [Creating and Updating a Group](#creating-and-updating-a-group) 92 - [Deleting a Group](#deleting-a-group) 93 - [Generating Full System Export](#generating-full-system-export) 94 - [Getting Info of a Folder in Artifactory](#getting-info-of-a-folder-in-artifactory) 95 - [Getting a listing of files and folders within a folder in Artifactory](#getting-a-listing-of-files-and-folders-within-a-folder-in-artifactory) 96 - [Getting Storage Summary Info of Artifactory](#getting-storage-summary-info-of-artifactory) 97 - [Triggerring Storage Info Recalculation in Artifactory](#triggerring-storage-info-recalculation-in-artifactory) 98 - [Access APIs](#access-apis) 99 - [Creating Access Service Manager](#creating-access-service-manager) 100 - [Creating Access Details](#creating-access-details) 101 - [Creating Access Service Config](#creating-access-service-config) 102 - [Creating New Access Service Manager](#creating-new-access-service-manager) 103 - [Using Access Services](#using-access-services) 104 - [Creating a New Project](#creating-a-new-project) 105 - [Updating a Project](#updating-a-project) 106 - [Deleting a Project](#deleting-a-project) 107 - [Getting a Project](#getting-a-project) 108 - [Getting all Projects](#getting-all-projects) 109 - [Assigning Repository to Project](#assigning-repository-to-project) 110 - [Unassigned Repository from Project](#unassigning-repository-from-project) 111 - [Get all groups assigned to a project](#get-all-groups-assigned-to-a-project) 112 - [Get a specific group assigned to a project](#get-a-specific-group-assigned-to-a-project) 113 - [Add or update a group assigned to a project](#add-or-update-a-group-assigned-to-a-project) 114 - [Remove a group from a project](#remove-a-group-from-a-project) 115 - [Distribution APIs](#distribution-apis) 116 - [Creating Distribution Service Manager](#creating-distribution-service-manager) 117 - [Creating Distribution Details](#creating-distribution-details) 118 - [Creating Distribution Service Config](#creating-distribution-service-config) 119 - [Creating New Distribution Service Manager](#creating-new-distribution-service-manager) 120 - [Using Distribution Services](#using-distribution-services) 121 - [Setting Distribution Signing Key](#setting-distribution-signing-key) 122 - [Creating a Release Bundle](#creating-a-release-bundle) 123 - [Updating a Release Bundle](#updating-a-release-bundle) 124 - [Signing a Release Bundle](#signing-a-release-bundle) 125 - [Async Distributing a Release Bundle](#async-distributing-a-release-bundle) 126 - [Sync Distributing a Release Bundle](#sync-distributing-a-release-bundle) 127 - [Getting Distribution Status](#getting-distribution-status) 128 - [Deleting a Remote Release Bundle](#deleting-a-remote-release-bundle) 129 - [Deleting a Local Release Bundle](#deleting-a-local-release-bundle) 130 - [Using ContentReader](#using-contentreader) 131 - [Xray APIs](#xray-apis) 132 - [Creating Xray Service Manager](#creating-xray-service-manager) 133 - [Creating Xray Details](#creating-xray-details) 134 - [Creating Xray Service Config](#creating-xray-service-config) 135 - [Creating New Xray Service Manager](#creating-new-xray-service-manager) 136 - [Using Xray Services](#using-xray-services) 137 - [Fetching Xray's Version](#fetching-xrays-version) 138 - [Creating an Xray Watch](#creating-an-xray-watch) 139 - [Get an Xray Watch](#get-an-xray-watch) 140 - [Update an Xray Watch](#update-an-xray-watch) 141 - [Delete an Xray Watch](#delete-an-xray-watch) 142 - [Creating a Security Xray Policy](#creating-a-security-xray-policy) 143 - [Creating a License Xray Policy](#creating-a-license-xray-policy) 144 - [Get an Xray Policy](#get-an-xray-policy) 145 - [Update an Xray Policy](#update-an-xray-policy) 146 - [Delete an Xray Policy](#delete-an-xray-policy) 147 - [Add Builds to Indexing Configuration](#add-builds-to-indexing-configuration) 148 - [Request Graph Scan](#request-graph-scan) 149 - [Retrieve the Graph Scan Results](#retrieve-the-graph-scan-results) 150 - [Generate Vulnerabilities Report](#generate-vulnerabilities-report) 151 - [Get Vulnerabilities Report Details](#get-vulnerabilities-report-details) 152 - [Get Vulnerabilities Report Content](#get-vulnerabilities-report-content) 153 - [Delete Vulnerabilities Report](#delete-vulnerabilities-report) 154 - [Get Artifact Summary](#get-artifact-summary) 155 - [Pipelines APIs](#pipelines-apis) 156 - [Creating Pipelines Service Manager](#creating-pipelines-service-manager) 157 - [Creating Pipelines Details](#creating-pipelines-details) 158 - [Creating Pipelines Service Config](#creating-pipelines-service-config) 159 - [Creating New Pipelines Service Manager](#creating-new-pipelines-service-manager) 160 - [Using Pipelines Services](#using-pipelines-services) 161 - [Fetching Pipelines' System Info](#fetching-pipelines-system-info) 162 - [Creating GitHub Integration](#creating-github-integration) 163 - [Creating GitHub Enterprise Integration](#creating-github-enterprise-integration) 164 - [Creating Bitbucket Integration](#creating-bitbucket-integration) 165 - [Creating Bitbucket Server Integration](#creating-bitbucket-server-integration) 166 - [Creating Gitlab Integration](#creating-gitlab-integration) 167 - [Creating Artifactory Integration](#creating-artifactory-integration) 168 - [Get Integration by Id](#get-integration-by-id) 169 - [Get Integration by Name](#get-integration-by-name) 170 - [Get All Integrations](#get-all-integrations) 171 - [Delete Integration](#delete-integration) 172 - [Add Pipeline Source](#add-pipeline-source) 173 - [Get Recent Pipeline Run Status](#get-recent-pipeline-run-status) 174 - [Trigger Pipeline Run](#trigger-pipeline-run) 175 - [Trigger Pipeline Sync](#trigger-pipeline-sync) 176 - [Get Pipeline Sync Status](#get-pipeline-sync-status) 177 - [Cancel The Run](#cancel-run) 178 179 ## General 180 181 _jfrog-client-go_ is a library which provides Go APIs to performs actions on JFrog Artifactory, Xray and Distribution 182 from your Go application. 183 The project is still relatively new, and its APIs may therefore change frequently between releases. 184 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 185 at [JFrog CLI](https://github.com/jfrog/jfrog-cli-go)' 186 s [go.mod](https://github.com/jfrog/jfrog-cli-go/blob/master/go.mod) file, which uses this library as a dependency. 187 188 ## Pull Requests 189 190 We welcome pull requests from the community. 191 192 ### Guidelines 193 194 - If the existing tests do not already cover your changes, please add tests. 195 - Pull requests should be created on the **dev** branch. 196 - Please use gofmt for formatting the code before submitting the pull request. 197 198 ## Tests 199 200 To run the tests on the source code, you'll need a running JFrog instance. See the _Prerequisites_ column in the _Test 201 Types_ section below for more information. 202 203 Use the following command with the below options to run the tests. 204 205 ```sh 206 go test -v github.com/mondo192/jfrog-client-go/tests -timeout 0 [test-types] [flags] 207 ``` 208 209 If you'd like to run a specific test, add the test function name using the `-run` flag. For example: 210 211 ```sh 212 go test -v github.com/mondo192/jfrog-client-go/tests -timeout 0 -run TestGetArtifactoryVersionWithCustomHttpClient -test.artifactory -rt.url=http://127.0.0.1:8081/artifactory -rt.user=admin -rt.password=password 213 ``` 214 215 **Note:** The tests create an Artifactory repository named _jfrog-client-tests-repo1_. Once the tests are completed, the 216 content of this repository is deleted. 217 218 ### Flags 219 220 #### Test Types 221 222 | Type | Description | Prerequisites | 223 |----------------------|--------------------|-------------------------------| 224 | `-test.artifactory` | Artifactory tests | Artifactory Pro | 225 | `-test.distribution` | Distribution tests | Artifactory with Distribution | 226 | `-test.xray` | Xray tests | Artifactory with Xray | 227 | `-test.pipelines` | Pipelines tests | JFrog Pipelines | 228 | `-test.access` | Access tests | Artifactory Pro | 229 | `-test.repositories` | Access tests | Artifactory Pro | 230 231 #### Connection Details 232 233 | Flag | Description | 234 |---------------------|--------------------------------------------------------------------------------------------------------| 235 | `-rt.url` | [Default: http://localhost:8081/artifactory] Artifactory URL. | 236 | `-ds.url` | [Optional] JFrog Distribution URL. | 237 | `-xr.url` | [Optional] JFrog Xray URL. | 238 | `-pipe.url` | [Optional] JFrog Pipelines URL. | 239 | `-access.url` | [Optional] JFrog Access URL. | 240 | `-rt.user` | [Default: admin] Artifactory username. | 241 | `-rt.password` | [Default: password] Artifactory password. | 242 | `-rt.apikey` | [Optional] Artifactory API key. | 243 | `-rt.sshKeyPath` | [Optional] Ssh key file path. Should be used only if the Artifactory URL format is ssh://[domain]:port | 244 | `-rt.sshPassphrase` | [Optional] Ssh key passphrase. | 245 | `-pipe.accessToken` | [Optional] Pipelines access token. | 246 | `-pipe.vcsToken` | [Optional] Vcs token for Pipelines tests (should have admin permissions). | 247 | `-pipe.vcsRepo` | [Optional] Vcs full repo path for Pipelines tests (ex: "domain/myrepo"). | 248 | `-pipe.vcsBranch` | [Optional] Vcs branch for Pipelines tests (ex: "main"). | 249 | `-access.token` | [Optional] Access access token. | 250 | `-ci.runId` | [Optional] A unique identifier used as a suffix to create repositories in the tests. | 251 252 ## General APIs 253 254 ### Setting the Logger 255 256 Default logger: 257 258 ```go 259 log.SetLogger(log.NewLogger(log.INFO, nil)) 260 ``` 261 262 You may also log to a file, and/or add log prefixes as shown below: 263 264 ```go 265 var file *os.File 266 // Log flags as described in https://pkg.go.dev/log#pkg-constants. 267 logFlags := Ldate | Ltime 268 ... 269 log.SetLogger(log.NewLoggerWithFlags(log.DEBUG, file, logFlags)) 270 ``` 271 272 ### Setting the Temp Dir 273 274 The default temp dir used is 'os.TempDir()'. Use the following API to set a new temp dir: 275 276 ```go 277 fileutils.SetTempDirBase(filepath.Join("my", "temp", "path")) 278 ``` 279 280 ## Artifactory APIs 281 282 ### Creating Artifactory Service Manager 283 284 #### Creating Artifactory Details 285 286 ```go 287 rtDetails := auth.NewArtifactoryDetails() 288 rtDetails.SetUrl("http://localhost:8081/artifactory") 289 rtDetails.SetSshKeyPath("path/to/.ssh/") 290 rtDetails.SetApiKey("apikey") 291 rtDetails.SetUser("user") 292 rtDetails.SetPassword("password") 293 rtDetails.SetAccessToken("accesstoken") 294 // if client certificates are required 295 rtDetails.SetClientCertPath("path/to/.cer") 296 rtDetails.SetClientCertKeyPath("path/to/.key") 297 ``` 298 299 #### Creating Artifactory Details with Custom HTTP Client 300 301 ```go 302 proxyUrl, err := url.Parse("http://proxyIp:proxyPort") 303 myCustomClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxyUrl)}} 304 305 rtDetails := auth.NewArtifactoryDetails() 306 rtDetails.SetUrl("http://localhost:8081/artifactory") 307 rtDetails.SetSshKeysPath("path/to/.ssh/") 308 rtDetails.SetApiKey("apikey") 309 rtDetails.SetUser("user") 310 rtDetails.SetPassword("password") 311 rtDetails.SetAccessToken("accesstoken") 312 serviceConfig, err := config.NewConfigBuilder(). 313 SetServiceDetails(rtDetails). 314 SetDryRun(false). 315 SetHttpClient(myCustomClient). 316 Build() 317 ``` 318 319 #### Creating Artifactory Service Config 320 321 ```go 322 serviceConfig, err := config.NewConfigBuilder(). 323 SetServiceDetails(rtDetails). 324 SetCertificatesPath(certPath). 325 SetThreads(threads). 326 SetDryRun(false). 327 // Add [Context](https://golang.org/pkg/context/) 328 SetContext(ctx). 329 // Optionally overwrite the default HTTP timeout, which is set to 30 seconds. 330 SetHttpTimeout(180 * time.Second). 331 // Optionally overwrite the default HTTP retries, which is set to 3. 332 SetHttpRetries(8). 333 Build() 334 ``` 335 336 #### Creating New Artifactory Service Manager 337 338 ```go 339 rtManager, err := artifactory.New(serviceConfig) 340 ``` 341 342 ### Using Artifactory Services 343 344 #### Uploading Files to Artifactory 345 346 Using the `UploadFiles()` function, we can upload files and get the general statistics of the action (The actual number 347 of successful and failed uploads), and the error value if it occurred. 348 349 ```go 350 params := services.NewUploadParams() 351 params.Pattern = "repo/*/*.zip" 352 params.Target = "repo/path/" 353 params.AddVcsProps = false 354 params.BuildProps = "build.name=buildName;build.number=17;build.timestamp=1600856623553" 355 params.Recursive = true 356 params.Regexp = false 357 params.IncludeDirs = false 358 params.Flat = true 359 params.ExplodeArchive = false 360 params.Archive = "zip" 361 params.Deb = "" 362 params.Symlink = false 363 params.Exclusions = "(.*)a.zip" 364 // Retries default value: 3 365 params.Retries = 5 366 // The min file size in bytes for "checksum deploy". 367 // "Checksum deploy" is the action of calculating the file checksum locally, before 368 // the upload, and skipping the actual file transfer if the file already 369 // exists in Artifactory. 370 // MinChecksumDeploy default value: 10400 371 params.MinChecksumDeploy = 15360 372 // Set to false to disable all checksum calculation, including "checksum deploy". 373 // ChecksumsCalcEnabled default value: true 374 params.ChecksumsCalcEnabled = false 375 // Attach properties to the uploaded files 376 targetProps := utils.NewProperties() 377 targetProps.AddProperty("key1", "val1") 378 params.TargetProps = targetProps 379 380 totalUploaded, totalFailed, err := rtManager.UploadFiles(params) 381 ``` 382 383 #### Downloading Files from Artifactory 384 385 Using the `DownloadFiles()` function, we can download files and get the general statistics of the action (The actual 386 number of files downloaded, and the number of files we expected to download). In addition, we get the error value if it 387 occurred. 388 389 ```go 390 params := services.NewDownloadParams() 391 params.Pattern = "repo/*/*.zip" 392 params.Target = "target/path/" 393 // Filter the downloaded files by properties. 394 params.Props = "key1=val1;key2=val2" 395 params.Recursive = true 396 params.IncludeDirs = false 397 params.Flat = false 398 params.Explode = false 399 params.Symlink = true 400 params.ValidateSymlink = false 401 params.Exclusions = "(.*)a.zip" 402 // Retries default value: 3 403 params.Retries = 5 404 // SplitCount default value: 3 405 params.SplitCount = 2 406 // MinSplitSize default value: 5120 407 params.MinSplitSize = 7168 408 409 totalDownloaded, totalFailed, err := rtManager.DownloadFiles(params) 410 ``` 411 412 #### Downloading Release Bundles from Artifactory 413 414 Using the `DownloadFiles()` function, we can download release bundles and get the general statistics of the action (The 415 actual number of files downloaded, and the number of files we expected to download). In addition, we get the error value 416 if it occurred. 417 418 It is possible to validate the downloaded release bundle's files by providing a local path to a GPG public key file (the 419 public GPG key should of course correspond to the private GPG key which was used to sign the release bundle). 420 421 ```go 422 params := services.NewDownloadParams() 423 // Path on the local file system to which the files should be downloaded. 424 params.Target = "target/path/" 425 // Bundle's name and version should be separated with "/". 426 params.Bundle = "bundleName/10" 427 // Optional GPG validation 428 params.PublicGpgKey = "public/key/file/path" 429 totalDownloaded, totalFailed, err := rtManager.DownloadFiles(params) 430 ``` 431 432 Read more about GPG signing release bundles [here](https://www.jfrog.com/confluence/display/JFROG/GPG+Signing). 433 434 #### Uploading and Downloading Files with Summary 435 436 The methods `UploadFilesWithSummary()` and `DownloadFilesWithSummary()` are similar to `UploadFlies()` 437 and `DownloadFlies()`, but return an OperationSummary struct, which allows iterating over the details of the 438 uploaded/downloaded files.<br> 439 The OperationSummary struct contains: 440 441 - TotalSucceeded - the number of successful uploads/downloads 442 - TotalFailed - the number of failed uploads/downloads 443 - TransferDetailsReader - a ContentReader of FileTransferDetails structs, with a struct for each successful transfer of 444 file 445 - ArtifactsDetailsReader - a ContentReader of ArtifactDetails structs, with a struct for each artifact in Artifactory 446 that was uploaded/downloaded successfully 447 448 The ContentReaders can be closed separately by calling `Close()` on each of them, or they both can be closed at once by 449 calling `Close()` on the OperationSummary struct. 450 451 ```go 452 params := services.NewUploadParams() 453 params.Pattern = "repo/*/*.zip" 454 params.Target = "repo/path/" 455 456 summary, err := rtManager.UploadFilesWithSummary(params) 457 defer summary.Close() 458 reader, totalDownloaded, totalExpected, err := rtManager.DownloadFilesWithResultReader(params) 459 460 // Iterate over each file 461 for currentFileInfo := new(utils.FileInfo); reader.NextRecord(currentFileInfo) == nil; currentFileInfo = new(utils.FileInfo) { 462 fmt.Printf("File path: %s\n", currentFileInfo.LocalPath) 463 } 464 465 if err := reader.GetError(); err != nil { 466 return err 467 } 468 ``` 469 470 Read more about [ContentReader](#using-contentReader). 471 472 #### Copying Files in Artifactory 473 474 ```go 475 params := services.NewMoveCopyParams() 476 params.Pattern = "repo/*/*.zip" 477 params.Target = "target/path/" 478 // Filter the files by properties. 479 params.Props = "key1=val1;key2=val2" 480 params.Recursive = true 481 params.Flat = false 482 483 rtManager.Copy(params) 484 ``` 485 486 #### Moving Files in Artifactory 487 488 ```go 489 params := services.NewMoveCopyParams() 490 params.Pattern = "repo/*/*.zip" 491 params.Target = "target/path/" 492 // Filter the files by properties. 493 params.Props = "key1=val1;key2=val2" 494 params.Recursive = true 495 params.Flat = false 496 497 rtManager.Move(params) 498 ``` 499 500 #### Deleting Files from Artifactory 501 502 ```go 503 params := services.NewDeleteParams() 504 params.Pattern = "repo/*/*.zip" 505 // Filter the files by properties. 506 params.Props = "key1=val1;key2=val2" 507 params.Recursive = true 508 509 pathsToDelete, err := rtManager.GetPathsToDelete(params) 510 if err != nil { 511 return err 512 } 513 defer pathsToDelete.Close() 514 rtManager.DeleteFiles(pathsToDelete) 515 ``` 516 517 Read more about [ContentReader](#using-contentReader). 518 519 #### Searching Files in Artifactory 520 521 ```go 522 params := services.NewSearchParams() 523 params.Pattern = "repo/*/*.zip" 524 // Filter the files by properties. 525 params.Props = "key1=val1;key2=val2" 526 params.Recursive = true 527 528 reader, err := rtManager.SearchFiles(params) 529 if err != nil { 530 return err 531 } 532 defer reader.Close() 533 ``` 534 535 Read more about [ContentReader](#using-contentReader). 536 537 #### Setting Properties on Files in Artifactory 538 539 ```go 540 searchParams = services.NewSearchParams() 541 searchParams.Recursive = true 542 searchParams.IncludeDirs = false 543 544 reader, err = rtManager.SearchFiles(searchParams) 545 if err != nil { 546 return err 547 } 548 defer reader.Close() 549 propsParams = services.NewPropsParams() 550 propsParams.Pattern = "repo/*/*.zip" 551 propsParams.Reader = reader 552 // Filter the files by properties. 553 propsParams.Props = "key=value" 554 555 rtManager.SetProps(propsParams) 556 ``` 557 558 Read more about [ContentReader](#using-contentReader). 559 560 #### Deleting Properties from Files in Artifactory 561 562 ```go 563 searchParams = services.NewSearchParams() 564 searchParams.Recursive = true 565 searchParams.IncludeDirs = false 566 567 resultItems, err = rtManager.SearchFiles(searchParams) 568 if err != nil { 569 return err 570 } 571 defer reader.Close() 572 propsParams = services.NewPropsParams() 573 propsParams.Pattern = "repo/*/*.zip" 574 propsParams.Reader = reader 575 // Filter the files by properties. 576 propsParams.Props = "key=value" 577 578 rtManager.DeleteProps(propsParams) 579 ``` 580 581 #### Getting Properties from Files in Artifactory 582 583 ```go 584 rtManager.GetItemProperties("repo/path/file") 585 ``` 586 587 Read more about [ContentReader](#using-contentReader). 588 589 #### Publishing Build Info to Artifactory 590 591 ```go 592 buildInfo := &buildinfo.BuildInfo{} 593 // Optional Artifactory project key 594 projectKey := "my-project-key" 595 ... 596 rtManager.PublishBuildInfo(buildInfo, projectKey) 597 ``` 598 599 #### Fetching Build Info from Artifactory 600 601 ```go 602 buildInfoParams := services.NewBuildInfoParams{} 603 buildInfoParams.BuildName = "buildName" 604 buildInfoParams.BuildNumber = "LATEST" 605 // Optional Artifactory project key 606 buildInfoParams.ProjectKey = "my-project-key" 607 608 rtManager.GetBuildInfo(buildInfoParams) 609 ``` 610 611 #### Promoting Published Builds in Artifactory 612 613 ```go 614 params := services.NewPromotionParams() 615 params.BuildName = "buildName" 616 params.BuildNumber = "10" 617 params.TargetRepo = "target-repo" 618 params.Status = "status" 619 params.Comment = "comment" 620 params.Copy = &trueValue 621 params.FailFast = true 622 params.IncludeDependencies = &falseValue 623 params.SourceRepo = "source-repo" 624 // Optional Artifactory project key 625 params.ProjectKey = "my-project-key" 626 627 rtManager.PromoteBuild(params) 628 ``` 629 630 #### Promoting a Docker Image in Artifactory 631 632 ```go 633 sourceDockerImage := "hello-world" 634 sourceRepo := "docker-local-1" 635 targetRepo := "docker-local-2" 636 params := services.NewDockerPromoteParams(sourceDockerImage, sourceRepo, targetRepo) 637 638 // Optional parameters: 639 params.TargetDockerImage = "target-docker-image" 640 params.SourceTag = "42" 641 params.TargetTag = "43" 642 params.Copy = true 643 644 rtManager.PromoteDocker(params) 645 ``` 646 647 #### Triggering Build Scanning with JFrog Xray 648 649 ```go 650 params := services.NewXrayScanParams() 651 params.BuildName = buildName 652 params.BuildNumber = buildNumber 653 654 rtManager.XrayScanBuild(params) 655 ``` 656 657 #### Discarding Old Builds 658 659 ```go 660 params := services.NewDiscardBuildsParams() 661 params.BuildName = "buildName" 662 params.MaxDays = "max-days" 663 params.MaxBuilds = "max-builds" 664 params.ExcludeBuilds = "1,2" 665 params.DeleteArtifacts = false 666 params.Async = false 667 // Optional Artifactory project key 668 projectKey := "my-project-key" 669 670 rtManager.DiscardBuilds(params) 671 ``` 672 673 #### Cleaning Unreferenced Git LFS Files from Artifactory 674 675 ```go 676 params := services.NewGitLfsCleanParams() 677 params.Refs = "refs/remotes/*" 678 params.Repo = "my-project-lfs" 679 params.GitPath = "path/to/git" 680 681 reader,err := rtManager.GetUnreferencedGitLfsFiles(params) 682 683 defer reader.Close() 684 rtManager.DeleteFiles(reader) 685 ``` 686 687 #### Executing AQLs 688 689 ```go 690 rtManager.Aql(aql string) 691 ``` 692 693 #### Reading Files in Artifactory 694 695 ```go 696 rtManager.ReadRemoteFile(FilePath string) 697 ``` 698 699 #### Creating an Access Token 700 701 ```go 702 params := services.NewCreateTokenParams() 703 params.Scope = "api:* member-of-groups:readers" 704 params.Username = "user" 705 params.ExpiresIn = 3600 // default -1 (use server default) 706 params.GrantType = "client_credentials" 707 params.Refreshable = true 708 params.Audience = "jfrt@<serviceID1> jfrt@<serviceID2>" 709 710 results, err := rtManager.CreateToken(params) 711 ``` 712 713 #### Fetching Access Tokens 714 715 ```go 716 results, err := rtManager.GetTokens() 717 ``` 718 719 #### Fetching Access Tokens of a User 720 721 ```g 722 results, err := rtManager.GetUserTokens(username) 723 ``` 724 725 #### Refreshing an Access Token 726 727 ```go 728 params := services.NewRefreshTokenParams() 729 params.AccessToken = "<access token>" 730 params.RefreshToken = "<refresh token>" 731 params.Token.Scope = "api:*" 732 params.Token.ExpiresIn = 3600 733 results, err := rtManager.RefreshToken(params) 734 ``` 735 736 #### Revoking an Access Token 737 738 ```go 739 params := services.NewRevokeTokenParams() 740 741 // Provide either TokenId or Token 742 params.TokenId = "<token id>" 743 // params.Token = "access token" 744 745 err := rtManager.RevokeToken(params) 746 ``` 747 748 #### Create API Key 749 750 ```go 751 // Returns an error if API key already exists - use RegenerateAPIKey instead. 752 apiKey, err := rtManager.CreateAPIKey() 753 ``` 754 755 #### Regenerate API Key 756 757 ```go 758 apiKey, err := rtManager.RegenerateAPIKey() 759 ``` 760 761 #### Get API Key 762 763 ```go 764 apiKey, err := rtManager.GetAPIKey() 765 ``` 766 767 #### Creating and Updating Local Repository 768 769 You can create and update a local repository for the following package types: 770 771 Alpine, Bower, Cran, Cargo, Chef, Cocoapods, Composer, Conan, Conda, Debian, Docker, Gems, Generic, Gitlfs, Go, Gradle, 772 Helm, Ivy, Maven, Npm, Nuget, Opkg, Puppet, Pypi, Rpm, Sbt, Swift, Vagrant, and Yum. 773 774 Each package type has its own parameters struct, can be created using the method 775 `New<packageType>LocalRepositoryParams()`. 776 777 Example for creating local Generic repository: 778 779 ```go 780 params := services.NewGenericLocalRepositoryParams() 781 params.Key = "generic-repo" 782 params.Description = "This is a public description for generic-repo" 783 params.Notes = "These are internal notes for generic-repo" 784 params.RepoLayoutRef = "simple-default" 785 params.ArchiveBrowsingEnabled = true 786 params.XrayIndex = true 787 params.IncludesPattern = "**/*" 788 params.ExcludesPattern = "excludedDir/*" 789 params.DownloadRedirect = true 790 791 err = servicesManager.CreateLocalRepository().Generic(params) 792 ``` 793 794 You can also create a local repository with basic local params: 795 796 ```go 797 params := services.NewLocalRepositoryBaseParams() 798 params.Key = "generic-repo" 799 params.PackageType = "generic" 800 params.Description = "This is a public description for generic-repo" 801 err := servicesManager.CreateLocalRepository(params) 802 ``` 803 804 Updating local Generic repository: 805 806 ```go 807 err = servicesManager.UpdateLocalRepository().Generic(params) 808 ``` 809 810 #### Creating and Updating Remote Repository 811 812 You can create and update a remote repository for the following package types: 813 814 Alpine, Bower, Cran, Cargo, Chef, Cocoapods, Composer, Conan, Conda, Debian, Docker, Gems, Generic, Gitlfs, Go, Gradle, 815 Helm, Ivy, Maven, Npm, Nuget, Opkg, P2, Puppet, Pypi, Rpm, Sbt, Swift, Vcs, and Yum. 816 817 Each package type has its own parameters struct, can be created using the method 818 `New<packageType>RemoteRepositoryParams()`. 819 820 Example for creating remote Maven repository: 821 822 ```go 823 params := services.NewMavenRemoteRepositoryParams() 824 params.Key = "maven-central-remote" 825 params.Url = "https://repo.maven.apache.org" 826 params.RepoLayoutRef = "maven-2-default" 827 params.Description = "A caching proxy repository for Maven central" 828 params.HandleSnapshot = false 829 params.HandleReleases = true 830 params.FetchJarsEagerly = true 831 params.XrayIndex = true 832 params.AssumedOfflinePeriodSecs = 600 833 params.SuppressPomConsistencyChecks = true 834 params.RemoteRepoChecksumPolicyType = "pass-thru" 835 836 err = servicesManager.CreateRemoteRepository().Maven(params) 837 ``` 838 839 Updating remote Maven repository: 840 841 ```go 842 err = servicesManager.UpdateRemoteRepository().Maven(params) 843 ``` 844 845 You can also create a remote repository with basic remote params: 846 847 ```go 848 params := services.NewRemoteRepositoryBaseParams() 849 params.Key = "remote-repo" 850 params.Url = "https://repo.maven.apache.org" 851 err := servicesManager.CreateRemoteRepository(params) 852 ``` 853 854 #### Creating and Updating Virtual Repository 855 856 You can create and update a virtual repository for the following package types: 857 858 Alpine, Bower, Cran, Chef, Conan, Conda, Debian, Docker, Gems, Generic, Gitlfs, Go, Gradle, Helm, Ivy, Maven, Npm, 859 Nuget, P2, Puppet, Pypi, Rpm, Sbt, Swift and Yum. 860 861 Each package type has its own parameters struct, can be created using the method 862 `New<packageType>VirtualRepositoryParams()`. 863 864 Example for creating virtual Go repository: 865 866 ```go 867 params := services.NewGoVirtualRepositoryParams() 868 params.Description = "This is an aggregated repository for several go repositories" 869 params.RepoLayoutRef = "go-default" 870 params.Repositories = {"gocenter-remote", "go-local"} 871 params.DefaultDeploymentRepo = "go-local" 872 params.ExternalDependenciesEnabled = true 873 params.ExternalDependenciesPatterns = {"**/github.com/**", "**/golang.org/**", "**/gopkg.in/**"} 874 params.ArtifactoryRequestsCanRetrieveRemoteArtifacts = true 875 876 err = servicesManager.CreateVirtualRepository().Go(params) 877 ``` 878 879 You can also create a virtual repository with basic virtual params: 880 881 ```go 882 params := services.NewVirtualRepositoryBaseParams() 883 params.Key = "generic-repo" 884 params.PackageType = "generic" 885 params.Description = "This is a public description for generic-repo" 886 params.Repositories = string[]{"remote-repo","local-repo"} 887 err := servicesManager.CreateVirtualRepository(params) 888 ``` 889 890 Updating virtual Go repository: 891 892 ```go 893 err = servicesManager.UpdateVirtualRepository().Go(params) 894 ``` 895 896 #### Creating and Updating Federated Repository 897 898 You can create and update a federated repository for the following package types: 899 900 Alpine, Bower, Cran, Cargo, Chef, Cocoapods, Composer, Conan, Conda, Debian, Docker, Gems, Generic, Gitlfs, Go, Gradle, 901 Helm, Ivy, Maven, Npm, Nuget, Opkg, Puppet, Pypi, Rpm, Sbt, Swift Vagrant and Yum 902 903 Each package type has its own parameters struct, can be created using the method 904 `New<packageType>FederatedRepositoryParams()`. 905 906 Example for creating federated Generic repository: 907 908 ```go 909 params := services.NewGenericFederatedRepositoryParams() 910 params.Key = "generic-repo" 911 params.Description = "This is a public description for generic-repo" 912 params.Notes = "These are internal notes for generic-repo" 913 params.RepoLayoutRef = "simple-default" 914 params.ArchiveBrowsingEnabled = true 915 params.XrayIndex = true 916 params.IncludesPattern = "**/*" 917 params.ExcludesPattern = "excludedDir/*" 918 params.DownloadRedirect = true 919 params.Members = []services.FederatedRepositoryMemberParams{ 920 {Url: "http://targetartifactory/artifactory/federatedRepositoryName", Enabled: true}, 921 } 922 err = servicesManager.CreateFederatedRepository().Generic(params) 923 ``` 924 925 You can also create a federated repository with basic federated params: 926 927 ```go 928 params := services.NewFederatedRepositoryBaseParams() 929 params.Key = "generic-repo" 930 params.PackageType = "generic" 931 params.Description = "This is a public description for generic-repo" 932 params.Members = []services.FederatedRepositoryMemberParams{ 933 {Url: "http://targetartifactory/artifactory/federatedRepositoryName", Enabled: true}, 934 } 935 err := servicesManager.CreateFederatedRepository(params) 936 ``` 937 938 Updating federated Generic repository: 939 940 ```go 941 err = servicesManager.UpdateFederatedRepository().Generic(params) 942 ``` 943 944 #### Removing a Repository 945 946 You can remove a repository from Artifactory using its key: 947 948 ```go 949 servicesManager.DeleteRepository("generic-repo") 950 ``` 951 952 #### Getting Repository Details 953 954 You can get repository details from Artifactory using its key, and the desired params struct. 955 The function expects to get the repo key (name) and a pointer to a param struct that will be filled up. 956 The param struct should contain the desired params fields corresponded to the Artifactory REST API: 957 958 ```go 959 repoDetails = services.RepositoryDetails{} 960 err := servicesManager.GetRepository("maven-repo", &repoDetails) 961 ``` 962 963 ```go 964 repoDetails = services.LocalRepositoryBaseParams{} 965 err := servicesManager.GetRepository("maven-repo", &repoDetails) 966 ``` 967 968 ```go 969 repoDetails = services.MavenLocalRepositoryParams{} 970 err := servicesManager.GetRepository("maven-repo", &repoDetails) 971 ``` 972 973 services.RepositoryDetails 974 975 #### Getting All Repositories 976 977 You can get all repositories from Artifactory: 978 979 ```go 980 servicesManager.GetAllRepositories() 981 ``` 982 983 You can get all repositories from Artifactory filtered according to theirs type and/or theirs package type: 984 985 ```go 986 params := services.NewRepositoriesFilterParams() 987 params.RepoType = "remote" 988 params.PackageType = "maven" 989 err := servicesManager.GetAllRepositoriesFiltered(params) 990 ``` 991 992 #### Check if Repository Exists 993 994 You can check whether a repository exists in Artifactory: 995 996 ```go 997 exists, err := servicesManager.IsRepoExists() 998 ``` 999 1000 #### Creating and Updating Repository Replications 1001 1002 Example of creating a repository replication: 1003 1004 ```go 1005 params := services.NewCreateReplicationParams() 1006 // Source replication repository. 1007 params.RepoKey = "my-repository" 1008 params.CronExp = "0 0 12 * * ?" 1009 params.Username = "admin" 1010 params.Password = "password" 1011 params.Url = "http://localhost:8081/artifactory/remote-repo" 1012 params.Enabled = true 1013 params.SocketTimeoutMillis = 15000 1014 params.EnableEventReplication = true 1015 params.SyncDeletes = true 1016 params.SyncProperties = true 1017 params.SyncStatistics = true 1018 params.PathPrefix = "/path/to/repo" 1019 1020 err = servicesManager.CreateReplication(params) 1021 ``` 1022 1023 Example of updating a local repository replication: 1024 1025 ```go 1026 params := services.NewUpdateReplicationParams() 1027 // Source replication repository. 1028 params.RepoKey = "my-repository" 1029 params.CronExp = "0 0 12 * * ?" 1030 params.Enabled = true 1031 params.SocketTimeoutMillis = 15000 1032 params.EnableEventReplication = true 1033 params.SyncDeletes = true 1034 params.SyncProperties = true 1035 params.SyncStatistics = true 1036 params.PathPrefix = "/path/to/repo" 1037 1038 err = servicesManager.UpdateReplication(params) 1039 ``` 1040 1041 #### Getting a Repository Replication 1042 1043 You can get a repository replication configuration from Artifactory using its key: 1044 1045 ```go 1046 replicationConfiguration, err := servicesManager.GetReplication("my-repository") 1047 ``` 1048 1049 #### Removing a Repository Replication 1050 1051 You can remove a repository replication configuration from Artifactory using its key: 1052 1053 ```go 1054 err := servicesManager.DeleteReplication("my-repository") 1055 ``` 1056 1057 #### Converting a Local Repository to a Federated Repository 1058 1059 You can convert a local repository to a federated repository using its key: 1060 1061 ```go 1062 err := servicesManager.ConvertLocalToFederatedRepository("my-repository") 1063 ``` 1064 1065 #### Triggering a Full Federated Repository Synchronisation 1066 1067 You can trigger a full federated repository synchronisation for all members using its key: 1068 1069 ```go 1070 err := servicesManager.TriggerFederatedRepositoryFullSyncAll("my-repository") 1071 ``` 1072 1073 You can also trigger a full federated repository synchronisation for a specific member using its key and the members URL 1074 1075 ```go 1076 err := servicesManager.TriggerFederatedRepositoryFullSyncMirror("my-repository", "http://localhost:8081/artifactory/my-repository") 1077 ``` 1078 1079 #### Creating and Updating Permission Targets 1080 1081 You can create or update a permission target in Artifactory. 1082 Permissions are set according to the following conventions: 1083 `read, write, annotate, delete, manage, managedXrayMeta, distribute` 1084 For repositories You can specify the name `"ANY"` in order to apply to all repositories, `"ANY REMOTE"` for all remote 1085 repositories or `"ANY LOCAL"` for all local repositories. 1086 1087 Creating a new permission target : 1088 1089 ```go 1090 params := services.NewPermissionTargetParams() 1091 params.Name = "java-developers" 1092 params.Repo = &services.PermissionTargetSection{} 1093 params.Repo.Repositories = []string{"ANY REMOTE", "local-repo1", "local-repo2"} 1094 params.Repo.ExcludePatterns = []string{"dir/*"} 1095 params.Repo.Actions = &services.Actions{} 1096 params.Repo.Actions.Users = map[string][]string{ 1097 "user1": {"read", "write"}, 1098 "user2": {"write", "annotate", "read"}, 1099 } 1100 params.Repo.Actions.Groups = map[string][]string{ 1101 "group1": {"manage", "read", "annotate"}, 1102 } 1103 // This is the default value that cannot be changed 1104 params.Build = &services.PermissionTargetSection{} 1105 params.Build.Repositories = []string{"artifactory-build-info"} 1106 params.Build.Actions = &services.Actions{} 1107 params.Build.Actions.Groups = map[string][]string{ 1108 "group1": {"manage", "read", "write", "annotate", "delete"}, 1109 "group2": {"read"}, 1110 } 1111 1112 err := testsPermissionTargetService.Create(params) 1113 ``` 1114 1115 Updating an existing permission target : 1116 1117 ```go 1118 err = servicesManager.UpdatePermissionTarget(params) 1119 ``` 1120 1121 #### Removing a Permission Target 1122 1123 You can remove a permission target from Artifactory using its name: 1124 1125 ```go 1126 err = servicesManager.DeletePermissionTarget("java-developers") 1127 ``` 1128 1129 #### Fetching a Permission Target 1130 1131 You can fetch a permission target from Artifactory using its name: 1132 1133 ```go 1134 permissionTargetParams, err = servicesManager.GetPermissionTarget("java-developers") 1135 ``` 1136 1137 If the requested permission target does not exist, a nil value is returned for the _permissionTargetParams_ param, with 1138 a nil error value 1139 1140 #### Fetching Artifactory's Version 1141 1142 ```go 1143 version, err := servicesManager.GetVersion() 1144 ``` 1145 1146 #### Fetching Running Artifactory Nodes in a Cluster 1147 1148 ```go 1149 runningNodes, err := servicesManager.GetRunningNodes() 1150 ``` 1151 1152 #### Fetching Artifactory's Service ID 1153 1154 ```go 1155 serviceId, err := servicesManager.GetServiceId() 1156 ``` 1157 1158 #### Fetching Artifactory's Config Descriptor 1159 1160 Notice: This API is enabled only on self-hosted Artifactory servers 1161 1162 ```go 1163 serviceId, err := servicesManager.GetConfigDescriptor() 1164 ``` 1165 1166 #### Activating Artifactory's Key Encryption 1167 1168 Notice: This API is enabled only on self-hosted Artifactory servers 1169 1170 ```go 1171 err := servicesManager.ActivateKeyEncryption() 1172 ``` 1173 1174 #### Deactivating Artifactory's Key Encryption 1175 1176 Notice: This API is enabled only on self-hosted Artifactory servers 1177 1178 ```go 1179 wasEncrypted, err := servicesManager.DeactivateKeyEncryption() 1180 ``` 1181 1182 #### Fetching Users Details 1183 1184 ```go 1185 params := services.NewUserParams() 1186 params.UserDetails.Name = "myUserName" 1187 1188 user, err := serviceManager.GetUser(params) 1189 ``` 1190 1191 If the requested user does not exist, a nil value is returned for the _User_ param, with a nil error value 1192 1193 #### Fetching All Users Details 1194 1195 You can get all users from Artifactory: 1196 1197 ```go 1198 users, err := servicesManager.GetAllUsers() 1199 ``` 1200 1201 #### Creating Inviting and Updating a User 1202 1203 ```go 1204 params := services.NewUserParams() 1205 params.UserDetails.Name = "myUserName" 1206 params.UserDetails.Email = "myUser@jfrog.com" 1207 params.UserDetails.Password = "Password1" 1208 params.UserDetails.Admin = &falseValue 1209 params.UserDetails.Realm = "internal" 1210 params.UserDetails.ProfileUpdatable = &trueValue 1211 params.UserDetails.DisableUIAccess = &falseValue 1212 params.UserDetails.InternalPasswordDisabled = &falseValue 1213 params.UserDetails.groups = []string{"GroupA", "GroupB"} 1214 // Set to true to replace existing user with the same name. 1215 params.ReplaceIfExists = false 1216 err := serviceManager.CreateUser(params) 1217 1218 // Inviting user to the platform. 1219 param.UserDetails.ShouldInvite = &trueValue 1220 param.UserDetails.Source = "cli" 1221 err := serviceManager.CreateUser(params) 1222 1223 params.UserDetails.groups = []string{"GroupA", "GroupB", "GroupC"} 1224 err := serviceManager.UpdateUser(params) 1225 1226 // Set to true to remove a user from every group. 1227 params.UserDetails.ClearGroups = true 1228 err := serviceManager.UpdateUser(params) 1229 ``` 1230 1231 #### Deleting a User 1232 1233 ```go 1234 err := serviceManager.DeleteUser("myUserName") 1235 ``` 1236 1237 #### Fetching Locked Out Users 1238 1239 ```go 1240 lockedUsers, err := serviceManager.GetLockedUsers() 1241 ``` 1242 1243 #### Unlock Locked Out User 1244 1245 Unlocks a locked out user. This function succeeds even if the user doesn't exist or not locked. 1246 1247 ```go 1248 err := serviceManager.UnlockUser("userToUnlock") 1249 ``` 1250 1251 #### Fetching All Groups 1252 1253 You can get all groups from Artifactory 1254 1255 ```go 1256 groups, err := serviceManager.GetAllGroups() 1257 ``` 1258 1259 #### Fetching Group Details 1260 1261 ```go 1262 params := services.NewGroupParams() 1263 params.GroupDetails.Name = "myGroupName" 1264 // Set this param to true to receive the usernames associated with this group 1265 params.IncludeUsers = true 1266 1267 group, err := serviceManager.GetGroup(params) 1268 ``` 1269 1270 If the requested group does not exist, a nil value is returned for the _Group_ param, with a nil error value 1271 1272 #### Creating and Updating a Group 1273 1274 ```go 1275 params := services.NewGroupParams() 1276 params.GroupDetails.Name = "myGroupName" 1277 params.GroupDetails.Description = "Description" 1278 params.GroupDetails.AutoJoin = &falseValue 1279 params.GroupDetails.AdminPrivileges = &trueValue 1280 params.GroupDetails.Realm = "internal" 1281 params.GroupDetails.UsersNames = [2]string{"UserA", "UserB"} 1282 // Set to true in order to replace exist group with the same name 1283 params.ReplaceIfExists = false 1284 err := serviceManager.CreateGroup(params) 1285 1286 params.GroupDetails.Description = "Newer Description" 1287 // Will add UserC to the group (in addition to existing UserA and UserB) 1288 params.GroupDetails.UsersNames = [1]string{"UserC"} 1289 1290 err := serviceManager.UpdateGroup(params) 1291 ``` 1292 1293 #### Deleting a Group 1294 1295 ```go 1296 err := serviceManager.DeleteGroup("myGroupName") 1297 ``` 1298 1299 #### Generating Full System Export 1300 1301 ```go 1302 params := services.NewExportParams("/tmp/") 1303 err := serviceManager.Export(params) 1304 ``` 1305 1306 #### Getting Info of a Folder in Artifactory 1307 1308 ```go 1309 serviceManager.FolderInfo("repo/path/") 1310 ``` 1311 1312 #### Getting a listing of files and folders within a folder in Artifactory 1313 1314 ```go 1315 optionalParams := servicesutils.NewFileListParams() 1316 optionalParams.Deep= true 1317 optionalParams.Depth= 2 1318 optionalParams.ListFolders= true 1319 optionalParams.MetadataTimestamps= true 1320 optionalParams.IncludeRootPath= true 1321 serviceManager.FileList("repo/path/", optionalParams) 1322 ``` 1323 1324 #### Getting Storage Summary Info of Artifactory 1325 1326 ```go 1327 storageInfo, err := serviceManager.GetStorageInfo() 1328 ``` 1329 1330 #### Triggerring Storage Info Recalculation in Artifactory 1331 1332 ```go 1333 err := serviceManager.CalculateStorageInfo() 1334 ``` 1335 1336 ## Access APIs 1337 1338 ### Creating Access Service Manager 1339 1340 #### Creating Access Details 1341 1342 ```go 1343 accessDetails := accessAuth.NewAccessDetails() 1344 accessDetails.SetUrl("http://localhost:8081/access/") 1345 accessDetails.SetSshKeyPath("path/to/.ssh/") 1346 accessDetails.SetApiKey("apikey") 1347 accessDetails.SetUser("user") 1348 accessDetails.SetPassword("password") 1349 accessDetails.SetAccessToken("accesstoken") 1350 // if client certificates are required 1351 accessDetails.SetClientCertPath("path/to/.cer") 1352 accessDetails.SetClientCertKeyPath("path/to/.key") 1353 ``` 1354 1355 #### Creating Access Service Config 1356 1357 ```go 1358 serviceConfig, err := clientConfig.NewConfigBuilder(). 1359 SetServiceDetails(accessAuth). 1360 SetCertificatesPath(certsPath). 1361 SetInsecureTls(accessDetails.InsecureTls). 1362 SetDryRun(isDryRun). 1363 Build() 1364 ``` 1365 1366 #### Creating New Access Service Manager 1367 1368 ```go 1369 accessManager, err := access.New(serviceConfig) 1370 ``` 1371 1372 ### Using Access Services 1373 1374 #### Creating a New Project 1375 1376 ```go 1377 adminPriviligies := accessServices.AdminPrivileges{ 1378 ManageMembers: &trueValue, 1379 ManageResources: &trueValue, 1380 IndexResources: &trueValue, 1381 } 1382 projectDetails := accessServices.Project{ 1383 DisplayName: "testProject", 1384 Description: "My Test Project", 1385 AdminPrivileges: &adminPriviligies, 1386 SoftLimit: &falseValue, 1387 StorageQuotaBytes: 1073741825, // needs to be higher than 1073741824 1388 ProjectKey: "tstprj", 1389 } 1390 projectParams = accessServices.NewProjectParams() 1391 projectParams.ProjectDetails = projectDetails 1392 err = accessManager.CreateProject(projectParams) 1393 ``` 1394 1395 #### Updating a Project 1396 1397 ```go 1398 adminPriviligies := accessServices.AdminPrivileges{ 1399 ManageMembers: true, 1400 ManageResources: true, 1401 IndexResources: true, 1402 } 1403 projectDetails := accessServices.Project{ 1404 DisplayName: "testProject", 1405 Description: "My Test Project", 1406 AdminPrivileges: &adminPriviligies, 1407 SoftLimit: &falseValue, 1408 StorageQuotaBytes: 1073741825, // needs to be higher than 1073741824 1409 ProjectKey: "tstprj", 1410 } 1411 projectParams = accessServices.NewProjectParams() 1412 projectParams.ProjectDetails = projectDetails 1413 err = accessManager.UpdateProject(projectParams) 1414 ``` 1415 1416 #### Deleting a Project 1417 1418 ```go 1419 err = accessManager.DeleteProject("tstprj") 1420 ``` 1421 1422 #### Getting a Project 1423 1424 ```go 1425 err = accessManager.GetProject("tstprj") 1426 ``` 1427 1428 #### Getting all Projects 1429 1430 ```go 1431 err = accessManager.GetAllProjects() 1432 ``` 1433 1434 #### Assigning Repository to Project 1435 1436 ```go 1437 // Params: (repositoryName, projectKey string, isForce bool) 1438 err = accessManager.AssignRepoToProject("repoName", "tstprj", true) 1439 ``` 1440 1441 #### Unassigning Repository from Project 1442 1443 ```go 1444 err = accessManager.AssignRepoToProject("repoName") 1445 ``` 1446 1447 #### Get all groups assigned to a project 1448 1449 ```go 1450 err = accessManager.GetProjectsGroups("tstprj") 1451 ``` 1452 1453 #### Get a specific group assigned to a project 1454 1455 ```go 1456 err = accessManager.GetProjectsGroup("tstprj", "tstgroup") 1457 ``` 1458 1459 #### Add or update a group assigned to a project 1460 1461 ```go 1462 projectGroup := accessServices.ProjectGroup{ 1463 Name: "tstgroup", 1464 Roles: []string{"Contributor","Release Manager"}, 1465 } 1466 err = accessManager.UpdateGroupInProject("tstprj", "tstgroup", projectGroup) 1467 ``` 1468 1469 #### Remove a group from a project 1470 1471 ```go 1472 err = accessManager.DeleteExistingProjectGroup("tstprj", "tstgroup") 1473 ``` 1474 1475 ## Distribution APIs 1476 1477 ### Creating Distribution Service Manager 1478 1479 #### Creating Distribution Details 1480 1481 ```go 1482 distDetails := auth.NewDistributionDetails() 1483 distDetails.SetUrl("http://localhost:8081/distribution") 1484 distDetails.SetSshKeyPath("path/to/.ssh/") 1485 distDetails.SetApiKey("apikey") 1486 distDetails.SetUser("user") 1487 distDetails.SetPassword("password") 1488 distDetails.SetAccessToken("accesstoken") 1489 // if client certificates are required 1490 distDetails.SetClientCertPath("path/to/.cer") 1491 distDetails.SetClientCertKeyPath("path/to/.key") 1492 ``` 1493 1494 #### Creating Distribution Service Config 1495 1496 ```go 1497 serviceConfig, err := config.NewConfigBuilder(). 1498 SetServiceDetails(rtDetails). 1499 SetCertificatesPath(certPath). 1500 SetThreads(threads). 1501 SetDryRun(false). 1502 // Add [Context](https://golang.org/pkg/context/) 1503 SetContext(ctx). 1504 // Optionally overwrite the default HTTP retries, which is set to 3. 1505 SetHttpRetries(8). 1506 Build() 1507 ``` 1508 1509 #### Creating New Distribution Service Manager 1510 1511 ```go 1512 distManager, err := distribution.New(serviceConfig) 1513 ``` 1514 1515 ### Using Distribution Services 1516 1517 #### Setting Distribution Signing Key 1518 1519 ```go 1520 params := services.NewSetSigningKeyParams("private-gpg-key", "public-gpg-key") 1521 1522 err := distManager.SetSigningKey(params) 1523 ``` 1524 1525 #### Creating a Release Bundle 1526 1527 ```go 1528 params := services.NewCreateReleaseBundleParams("bundle-name", "1") 1529 params.Description = "Description" 1530 params.ReleaseNotes = "Release notes" 1531 params.ReleaseNotesSyntax = "plain_text" 1532 targetProps := utils.NewProperties() 1533 targetProps.AddProperty("key1", "val1") 1534 params.SpecFiles = []*utils.CommonParams{{Pattern: "repo/*/*.zip", TargetProps: targetProps}} 1535 1536 // Be default, artifacts that are distributed as part of a release bundle, have the same path in their destination server 1537 // (the edge node) as the path they had on the distributing Artifactory server. 1538 // You have however the option for modifying the target path on edge node. You do this by defining the Target property as shown below. 1539 // The Pattern property is a wildcard based pattern. Any wildcards enclosed in parentheses in the pattern (source) 1540 // path can be matched with a corresponding placeholder in the target path, to determine the path and name 1541 // of the artifact, once distributed to the edge node. 1542 // In the following example, the path in the edge node is similar to the path in the source Artifactory server, except for the additional "dir" level at the root of the repository. 1543 // Pattern: my-repo/(*)/a.zip 1544 // Target: my-repo/dir/{1}/a.zip 1545 pathMappingSpec := &utils.CommonParams{Pattern: "source-repo/(a)/(*.zip)", Target: "target-repo/{1}-{2}"} 1546 params.SpecFiles = append(params.SpecFiles, pathMappingSpec) 1547 1548 // In case: params.SignImmediately == true, the summary contain the release bundle details. Otherwise, summary is nil. 1549 summary, err := distManager.CreateReleaseBundle(params) 1550 ``` 1551 1552 #### Updating a Release Bundle 1553 1554 ```go 1555 params := services.NewUpdateReleaseBundleParams("bundle-name", "1") 1556 params.Description = "New Description" 1557 params.ReleaseNotes = "New Release notes" 1558 params.ReleaseNotesSyntax = "plain_text" 1559 targetProps := utils.NewProperties() 1560 targetProps.AddProperty("key1", "val1") 1561 params.SpecFiles = []*utils.CommonParams{{Pattern: "repo/*/*.zip", TargetProps: targetProps}} 1562 1563 // The Target property defines the target path in the edge node, and can include replaceable in the form of {1}, {2}, ... 1564 // Read more about it in the above "Creating a Release Bundle" section. 1565 pathMappingSpec := &utils.CommonParams{Pattern: "source-repo/(a)/(*.zip)", Target: "target-repo/{1}-{2}"} 1566 params.SpecFiles = append(params.SpecFiles, pathMappingSpec) 1567 1568 // In case: params.SignImmediately == true, the summary contain the release bundle details. Otherwise, summary is nil. 1569 summary, err := distManager.UpdateReleaseBundle(params) 1570 ``` 1571 1572 #### Signing a Release Bundle 1573 1574 ```go 1575 params := services.NewSignBundleParams("bundle-name", "1") 1576 params.GpgPassphrase = "123456" 1577 1578 summary, err := distManager.SignReleaseBundle(params) 1579 ``` 1580 1581 #### Async Distributing a Release Bundle 1582 1583 ```go 1584 params := services.NewDistributeReleaseBundleParams("bundle-name", "1") 1585 distributionRules := utils.DistributionCommonParams{SiteName: "Swamp-1", "CityName": "Tel-Aviv", "CountryCodes": []string{"123"}}} 1586 params.DistributionRules = []*utils.DistributionCommonParams{distributionRules} 1587 // Auto-creating repository if it does not exist 1588 autoCreateRepo := true 1589 err := distManager.DistributeReleaseBundle(params, autoCreateRepo) 1590 ``` 1591 1592 #### Sync Distributing a Release Bundle 1593 1594 ```go 1595 params := services.NewDistributeReleaseBundleParams("bundle-name", "1") 1596 distributionRules := utils.DistributionCommonParams{SiteName: "Swamp-1", "CityName": "Tel-Aviv", "CountryCodes": []string{"123"}}} 1597 params.DistributionRules = []*utils.DistributionCommonParams{distributionRules} 1598 // Auto-creating repository if it does not exist 1599 autoCreateRepo := true 1600 // Wait up to 120 minutes for the release bundle distribution 1601 err := distManager.DistributeReleaseBundleSync(params, 120, autoCreateRepo) 1602 ``` 1603 1604 #### Getting Distribution Status 1605 1606 ```go 1607 params := services.NewDistributionStatusParams() 1608 // Optional parameters: 1609 // If missing, get status for all distributions 1610 params.Name = "bundle-name" 1611 // If missing, get status for all versions of "bundle-name" 1612 params.Version = "1" 1613 // If missing, get status for all "bundle-name" with version "1" 1614 params.TrackerId = "123456789" 1615 1616 status, err := distributeBundleService.GetStatus(params) 1617 ``` 1618 1619 #### Deleting a Remote Release Bundle 1620 1621 ```go 1622 params := services.NewDeleteReleaseBundleParams("bundle-name", "1") 1623 params.DeleteFromDistribution = true 1624 distributionRules := utils.DistributionCommonParams{SiteName: "Swamp-1", "CityName": "Tel-Aviv", "CountryCodes": []string{"123"}}} 1625 params.DistributionRules = []*utils.DistributionCommonParams{distributionRules} 1626 // Set to true to enable sync deletion (the command execution will end when the deletion process ends). 1627 param.Sync = true 1628 // Max minutes to wait for sync deletion. 1629 param.MaxWaitMinutes = 10 1630 err := distManager.DeleteReleaseBundle(params) 1631 ``` 1632 1633 #### Deleting a Local Release Bundle 1634 1635 ```go 1636 params := services.NewDeleteReleaseBundleParams("bundle-name", "1") 1637 1638 err := distManager.DeleteLocalReleaseBundle(params) 1639 ``` 1640 1641 ## Using ContentReader 1642 1643 Some APIs return a `content.ContentReader` struct, which allows reading the API's output. `content.ContentReader` 1644 provides access to large amounts of data safely, without loading all of it into the memory. 1645 Here's an example for how `content.ContentReader` should be used: 1646 1647 ````go 1648 reader, err := servicesManager.SearchFiles(searchParams) 1649 if err != nil { 1650 return err 1651 } 1652 1653 // Remove the data file used by the reader. 1654 defer func() { 1655 if reader != nil { 1656 err = reader.Close() 1657 } 1658 }() 1659 1660 // Iterate over the results. 1661 for currentResult := new(utils.ResultItem); reader.NextRecord(currentResult) == nil; currentResult = new(utils.ResultItem) { 1662 fmt.Printf("Found artifact: %s of type: %s\n", currentResult.Name, currentResult.Type) 1663 } 1664 if err := resultReader.GetError(); err != nil { 1665 return err 1666 } 1667 1668 // Resets the reader pointer back to the beginning of the output. Make sure not to call this method after the reader had been closed using ```reader.Close()``` 1669 reader.Reset() 1670 ```` 1671 1672 - `reader.NextRecord(currentResult)` reads the next record from the reader into `currentResult` of type `utils.ResultItem`. 1673 1674 - `reader.Close()` removes the file used by the reader after it is used (preferably using `defer`). 1675 1676 - `reader.GetError()` returns any error that might have occurred during `NextRecord()`. 1677 1678 - `reader.Reset()` resets the reader back to the beginning of the output. 1679 1680 ## Xray APIs 1681 1682 ### Creating Xray Service Manager 1683 1684 #### Creating Xray Details 1685 1686 ```go 1687 xrayDetails := auth.NewXrayDetails() 1688 xrayDetails.SetUrl("http://localhost:8081/xray") 1689 xrayDetails.SetSshKeyPath("path/to/.ssh/") 1690 xrayDetails.SetApiKey("apikey") 1691 xrayDetails.SetUser("user") 1692 xrayDetails.SetPassword("password") 1693 xrayDetails.SetAccessToken("accesstoken") 1694 // if client certificates are required 1695 xrayDetails.SetClientCertPath("path/to/.cer") 1696 xrayDetails.SetClientCertKeyPath("path/to/.key") 1697 ``` 1698 1699 #### Creating Xray Service Config 1700 1701 ```go 1702 serviceConfig, err := config.NewConfigBuilder(). 1703 SetServiceDetails(xrayDetails). 1704 SetCertificatesPath(certPath). 1705 // Optionally overwrite the default HTTP retries, which is set to 3. 1706 SetHttpRetries(8). 1707 Build() 1708 ``` 1709 1710 #### Creating New Xray Service Manager 1711 1712 ```go 1713 xrayManager, err := xray.New(serviceConfig) 1714 ``` 1715 1716 ### Using Xray Services 1717 1718 #### Fetching Xray's Version 1719 1720 ```go 1721 version, err := xrayManager.GetVersion() 1722 ``` 1723 1724 #### Creating an Xray Watch 1725 1726 This uses API version 2. 1727 1728 You are able to configure repositories and builds on a watch. 1729 However, bundles are not supported. 1730 1731 ```go 1732 params := utils.NewWatchParams() 1733 params.Name = "example-watch-all" 1734 params.Description = "All Repos" 1735 params.Active = true 1736 1737 params.Repositories.Type = utils.WatchRepositoriesAll 1738 params.Repositories.All.Filters.PackageTypes = []string{"Npm", "maven"} 1739 params.Repositories.ExcludePatterns = []string{"excludePath1", "excludePath2"} 1740 params.Repositories.IncludePatterns = []string{"includePath1", "includePath2"} 1741 1742 params.Builds.Type = utils.WatchBuildAll 1743 params.Builds.All.Bin_Mgr_ID = "default" 1744 1745 params.Policies = []utils.AssignedPolicy{ 1746 { 1747 Name: policy1Name, 1748 Type: "security", 1749 }, 1750 { 1751 Name: policy2Name, 1752 Type: "security", 1753 }, 1754 } 1755 1756 err := xrayManager.CreateWatch(*params) 1757 ``` 1758 1759 #### Get an Xray Watch 1760 1761 ```go 1762 watch, err := xrayManager.GetWatch("example-watch-all") 1763 ``` 1764 1765 #### Update an Xray Watch 1766 1767 ```go 1768 watch, err := xrayManager.GetWatch("example-watch-all") 1769 watch.Description = "Updated description" 1770 1771 err := xrayManager.UpdateWatch(*watch) 1772 ``` 1773 1774 #### Delete an Xray Watch 1775 1776 ```go 1777 err := xrayManager.DeleteWatch("example-watch-all") 1778 ``` 1779 1780 #### Creating a Security Xray Policy 1781 1782 ```go 1783 params := utils.NewPolicyParams() 1784 params.Name = "example-security-policy" 1785 params.Type = utils.Security 1786 params.Description = "Security policy with 2 rules" 1787 params.Rules = []utils.PolicyRule{ 1788 params.Rules = []utils.PolicyRule{ 1789 { 1790 Name: "min-severity-rule", 1791 Criteria: *utils.CreateSeverityPolicyCriteria(utils.Low), 1792 Priority: 1, 1793 }, 1794 { 1795 Name: "cvss-range-rule", 1796 Criteria: *utils.CreateCvssRangePolicyCriteria(5.7, 8.9), 1797 Priority: 2, 1798 Actions: &utils.PolicyAction{ 1799 Webhooks: []string{"sec_webhook"}, 1800 BlockDownload: utils.PolicyBlockDownload{ 1801 Active: &trueValue, 1802 Unscanned: &falseValue, 1803 }, 1804 BlockReleaseBundleDistribution: &falseValue, 1805 FailBuild: &trueValue, 1806 NotifyDeployer: &falseValue, 1807 NotifyWatchRecipients: &trueValue, 1808 CustomSeverity: utils.Medium, 1809 }, 1810 }, 1811 } 1812 err := xrayManager.CreatePolicy(params) 1813 ``` 1814 1815 #### Creating a License Xray Policy 1816 1817 ```go 1818 params := utils.NewPolicyParams() 1819 params.Name = "example-licence-policy" 1820 params.Type = utils.License 1821 params.Description = "License policy with 2 rules" 1822 params.Rules = []utils.PolicyRule{ 1823 { 1824 Name: "allowed-licenses", 1825 Criteria: *utils.CreateLicensePolicyCriteria(true, true, false, "MIT", "Apache-2.0"), 1826 Priority: 1, 1827 }, 1828 { 1829 Name: "baned-licenses", 1830 Criteria: *utils.CreateLicensePolicyCriteria(false, true, false, "GPL"), 1831 Priority: 2, 1832 }, 1833 } 1834 err := xrayManager.CreatePolicy(params) 1835 ``` 1836 1837 #### Get an Xray Policy 1838 1839 ```go 1840 policy, err := xrayManager.GetPolicy("example-policy") 1841 ``` 1842 1843 #### Update an Xray Policy 1844 1845 ```go 1846 policy, err := xrayManager.GetPolicy("example-policy") 1847 policy.Description = "Updated description" 1848 1849 err := xrayManager.UpdatePolicy(*policy) 1850 ``` 1851 1852 #### Delete an Xray Policy 1853 1854 ```go 1855 err := xrayManager.DeletePolicy("example-policy") 1856 ``` 1857 1858 #### Add Builds to Indexing Configuration 1859 1860 ```go 1861 buildsToIndex := []string{"buildName1", "buildName2"} 1862 err := xrayManager.AddBuildsToIndexing(buildsToIndex) 1863 ``` 1864 1865 #### Request Graph Scan 1866 1867 ```go 1868 graphScanParams := &XrayGraphScanParams{} 1869 // Dependency tree. Each node must have a component identifier, see https://www.jfrog.com/confluence/display/JFROG/Xray+REST+API#XrayRESTAPI-ComponentIdentifiers. 1870 graphScanParams.Graph = &GraphNode{ 1871 Id: "gav://org.jfrog.buildinfo:build-info-extractor-gradle:4.24.5", 1872 Nodes: []*GraphNode{{Id: "gav://junit:junit:4.13.2"}, {Id: "gav://commons-lang:commons-lang:2.6"}}} 1873 scanId, err := xrayManager.ScanGraph(graphScanParams) 1874 ``` 1875 1876 #### Retrieve the Graph Scan Results 1877 1878 ```go 1879 // scanId should be received from xrayManager.ScanGraph(graphScanParams) request. 1880 scanResults, err := xrayManager.GetScanGraphResults(scanId) 1881 ``` 1882 1883 #### Generate Vulnerabilities Report 1884 1885 ```go 1886 reportRequest := services.ReportRequestParams{ 1887 Name: "example-report", 1888 Filters: services.Filter{ 1889 HasRemediation: &trueValue, 1890 Severity: []string{ "High" }, 1891 }, 1892 Resources: services.Resource{ 1893 IncludePathPatterns: []string{ "/example-sub-dir/**" }, 1894 Repositories: []services.Repository{ 1895 { 1896 Name: "example-repository", 1897 }, 1898 }, 1899 }, 1900 } 1901 1902 // The reportRequestResponse will contain the report ID to use in subsequent requests 1903 reportRequestResponse, err := xrayManager.GenerateVulnerabilitiesReport(reportRequest) 1904 ``` 1905 1906 #### Get Vulnerabilities Report Details 1907 1908 ```go 1909 // The reportId argument value is returned as part of the xrayManager.GenerateVulnerabilitiesReport API response. 1910 reportDetails, err := xrayManager.ReportDetails(reportId) 1911 ``` 1912 1913 #### Get Vulnerabilities Report Content 1914 1915 ```go 1916 // The ReportId value is returned as part of the xrayManager.GenerateVulnerabilitiesReport API response. 1917 reportContentRequest := services.ReportContentRequestParams{ 1918 ReportId: "example-report-id", 1919 Direction: "asc", 1920 PageNum: 0, 1921 NumRows: 0, 1922 OrderBy: "severity", 1923 } 1924 reportContent, err := xrayManager.ReportContent(reportContentRequest) 1925 ``` 1926 1927 #### Delete Vulnerabilities Report 1928 1929 ```go 1930 // The reportId argument value is returned as part of the xrayManager.GenerateVulnerabilitiesReport API response. 1931 err := xrayManager.DeleteReport(reportId) 1932 ``` 1933 1934 #### Get Artifact Summary 1935 1936 ```go 1937 artifactSummaryRequest := services.ArtifactSummaryParams{ 1938 Checksums: []string{"a96370b18b3d7e70b7b34d49dcb621a805c15cf71217ee8c77be5a98cc793fd3"}, 1939 Paths: []string{"default/example-repository/example-folder/example-artifact"}, 1940 } 1941 artifactSummary, err := xrayManager.ArtifactSummary(artifactSummaryRequest) 1942 ``` 1943 1944 ## Pipelines APIs 1945 1946 ### Creating Pipelines Service Manager 1947 1948 #### Creating Pipelines Details 1949 1950 ```go 1951 pipelinesDetails := auth.NewPipelinesDetails() 1952 pipelinesDetails.SetUrl("http://localhost:8081/pipelines") 1953 pipelinesDetails.SetAccessToken("accesstoken") 1954 // if client certificates are required 1955 pipelinesDetails.SetClientCertPath("path/to/.cer") 1956 pipelinesDetails.SetClientCertKeyPath("path/to/.key") 1957 ``` 1958 1959 #### Creating Pipelines Service Config 1960 1961 ```go 1962 serviceConfig, err := config.NewConfigBuilder(). 1963 SetServiceDetails(pipelinesDetails). 1964 SetCertificatesPath(pipelinesDetails.GetClientCertPath()). 1965 // Optionally overwrite the default HTTP retries, which is set to 3. 1966 SetHttpRetries(8). 1967 Build() 1968 ``` 1969 1970 #### Creating New Pipelines Service Manager 1971 1972 ```go 1973 pipelinesManager, err := pipelines.New(serviceConfig) 1974 ``` 1975 1976 ### Using Pipelines Services 1977 1978 #### Fetching Pipelines' System Info 1979 1980 ```go 1981 systemInfo, err := pipelinesManager.GetSystemInfo() 1982 ``` 1983 1984 #### Creating GitHub Integration 1985 1986 ```go 1987 id, err := pipelinesManager.CreateGithubIntegration("integrationName", "token") 1988 ``` 1989 1990 #### Creating GitHub Enterprise Integration 1991 1992 ```go 1993 id, err := pipelinesManager.CreateGithubEnterpriseIntegration("integrationName", "url", "token") 1994 ``` 1995 1996 #### Creating Bitbucket Integration 1997 1998 ```go 1999 id, err := pipelinesManager.CreateBitbucketIntegration("integrationName", "username", "token") 2000 ``` 2001 2002 #### Creating Bitbucket Server Integration 2003 2004 ```go 2005 id, err := pipelinesManager.CreateBitbucketServerIntegration("integrationName", "url", "username", "passwordOrToken") 2006 ``` 2007 2008 #### Creating Gitlab Integration 2009 2010 ```go 2011 id, err := pipelinesManager.CreateGitlabIntegration("integrationName", "url", "token") 2012 ``` 2013 2014 #### Creating Artifactory Integration 2015 2016 ```go 2017 id, err := pipelinesManager.CreateArtifactoryIntegration("integrationName", "url", "username", "apikey") 2018 ``` 2019 2020 #### Get Integration by Id 2021 2022 ```go 2023 integrationId := 1234 2024 integration, err := pipelinesManager.GetIntegrationById(integrationId) 2025 ``` 2026 2027 #### Get Integration by Name 2028 2029 ```go 2030 integration, err := pipelinesManager.GetIntegrationByName("integrationName") 2031 ``` 2032 2033 #### Get All Integrations 2034 2035 ```go 2036 integrations, err := pipelinesManager.GetAllIntegrations() 2037 ``` 2038 2039 #### Delete Integration 2040 2041 ```go 2042 integrationId := 1234 2043 err := pipelinesManager.DeleteIntegration(integrationId) 2044 ``` 2045 2046 #### Add Pipeline Source 2047 2048 ```go 2049 projectIntegrationId := 1234 2050 err := pipelinesManager.AddSource(projectIntegrationId, "domain/repo", "master", "pipelines.yml", "pipelineSourceName") 2051 ``` 2052 2053 #### Get Recent Pipeline Run Status 2054 2055 ```go 2056 branch := "master" 2057 pipeline := "pipeline_name" 2058 response, err := pipelinesManager.GetPipelineRunStatusByBranch(branch, pipeline) 2059 ``` 2060 2061 #### Trigger Pipeline Run 2062 2063 ```go 2064 branch := "master" 2065 pipeline := "pipeline_name" 2066 status, err := pipelinesManager.TriggerPipelineRun(branch, pipeline) 2067 ``` 2068 2069 #### Trigger Pipeline Sync 2070 2071 ```go 2072 branch := "master" 2073 repoName := "jfrog/pipelines" // repository full path 2074 err := pipelinesManager.SyncPipelineResource(branch, repoFullName) 2075 ``` 2076 2077 #### Get Pipeline Sync Status 2078 2079 ```go 2080 branch := "master" 2081 repoName := "jfrog/pipelines" // repository full path 2082 err := pipelinesManager.GetSyncStatusForPipelineResource(branch, repoFullName) 2083 ``` 2084 2085 #### Cancel Run 2086 2087 ```go 2088 runID := 234 // run id of pipeline 2089 err := pipelinesManager.CancelRun(runID) 2090 ```