|
| 1 | +# go-artifactory # |
| 2 | +go-artifactory is a Go client library for accessing the [Artifactory API](https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API) |
| 3 | + |
| 4 | +go-artifactory is tested on Go version 1.9 |
| 5 | + |
| 6 | +## Usage ## |
| 7 | +```go |
| 8 | +import "github.com/atlassian/go-artifactory/pkg/artifactory" |
| 9 | +``` |
| 10 | + |
| 11 | +Construct a new Artifactory client, then use the various services on the client to |
| 12 | +access different parts of the Artifactory API. For example: |
| 13 | + |
| 14 | +```go |
| 15 | +client := artifactory.NewClient("http://localhost/artifactory", nil) |
| 16 | + |
| 17 | +// list all repositories |
| 18 | +repos, resp, err := client.Repositories.List(context.Background(), nil) |
| 19 | +``` |
| 20 | + |
| 21 | +Some API methods have optional parameters that can be passed. For example: |
| 22 | + |
| 23 | +```go |
| 24 | +client := artifactroy.NewClient("http://localhost/artifactory", nil) |
| 25 | + |
| 26 | +// list all public local repositories |
| 27 | +opt := &artifactory.RepositoryListOptions{Type: "local"} |
| 28 | +client.Repositories.ListRepositories(ctx, opt) |
| 29 | +``` |
| 30 | + |
| 31 | +The services of a client divide the API into logical chunks and correspond to |
| 32 | +the structure of the Artifactory API documentation at |
| 33 | +[https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API](https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API). |
| 34 | + |
| 35 | +NOTE: Using the [context](https://godoc.org/context) package, one can easily |
| 36 | +pass cancelation signals and deadlines to various services of the client for |
| 37 | +handling a request. In case there is no context available, then `context.Background()` |
| 38 | +can be used as a starting point. |
| 39 | + |
| 40 | +### Authentication ### |
| 41 | + |
| 42 | +The go-artifactory library does not directly handle authentication. Instead, when |
| 43 | +creating a new client, pass an `http.Client` that can handle authentication for |
| 44 | +you. |
| 45 | + |
| 46 | +For API methods that require HTTP Basic Authentication, use the BasicAuthTransport or TokenTransport |
| 47 | + |
| 48 | +```go |
| 49 | +package main |
| 50 | + |
| 51 | +import ( |
| 52 | + "github.com/atlassian/go-artifactory/pkg/artifactory" |
| 53 | + "fmt" |
| 54 | + "context" |
| 55 | +) |
| 56 | + |
| 57 | +func main() { |
| 58 | + tp := artifactory.BasicAuthTransport{ |
| 59 | + Username: "<YOUR_USERNAME>", |
| 60 | + Password: "<YOUR_PASSWORD>", |
| 61 | + } |
| 62 | + |
| 63 | + client, err := artifactory.NewClient("https://localhost/artifactory", tp.Client()) |
| 64 | + if err != nil { |
| 65 | + fmt.Println(err.Error()) |
| 66 | + } |
| 67 | + |
| 68 | + repos, resp, err := client.Repositories.ListRepositories(context.Background(), nil) |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +### Creating and Updating Resources ### |
| 73 | +All structs for GitHub resources use pointer values for all non-repeated fields. |
| 74 | +This allows distinguishing between unset fields and those set to a zero-value. |
| 75 | +Helper functions have been provided to easily create these pointers for string, |
| 76 | +bool, and int values. For example: |
| 77 | + |
| 78 | +```go |
| 79 | + // create a new local repository named "lib-releases" |
| 80 | + repo := artifactory.LocalRepository{ |
| 81 | + Key: artifactory.String("lib-releases"), |
| 82 | + RClass: artifactory.String("local"), |
| 83 | + PackageType: artifactory.String("maven"), |
| 84 | + HandleSnapshots: artifactory.Bool(false); |
| 85 | + } |
| 86 | + |
| 87 | + client.Repositories.CreateLocal(context.Background(), &repo) |
| 88 | +``` |
| 89 | + |
| 90 | +Users who have worked with protocol buffers should find this pattern familiar. |
| 91 | + |
| 92 | +## Roadmap ## |
| 93 | + |
| 94 | +This library is being initially developed for an internal application at |
| 95 | +Atlassian, so API methods will likely be implemented in the order that they are |
| 96 | +needed by that application. Eventually, it would be ideal to cover the entire |
| 97 | +Artifactory API, so contributions are of course always welcome. The |
| 98 | +calling pattern is pretty well established, so adding new methods is relatively |
| 99 | +straightforward. |
| 100 | + |
| 101 | +## Versioning ## |
| 102 | + |
| 103 | +In general, go-artifactory follows [semver](https://semver.org/) as closely as we |
| 104 | +can for tagging releases of the package. For self-contained libraries, the |
| 105 | +application of semantic versioning is relatively straightforward and generally |
| 106 | +understood. But because go-artifactory is a client library for the Artifactory API |
| 107 | +we've adopted the following versioning policy: |
| 108 | + |
| 109 | +* We increment the **major version** with any incompatible change to |
| 110 | + functionality, including changes to the exported Go API surface |
| 111 | + or behavior of the API. |
| 112 | +* We increment the **minor version** with any backwards-compatible changes to |
| 113 | + functionality. |
| 114 | +* We increment the **patch version** with any backwards-compatible bug fixes. |
| 115 | + |
| 116 | +Generally methods will be annotated with a since version. |
| 117 | + |
| 118 | +## Reporting issues ## |
| 119 | + |
| 120 | +We believe in open contributions and the power of a strong development community. Please read our [Contributing guidelines][CONTRIBUTING] on how to contribute back and report issues to go-stride. |
| 121 | + |
| 122 | +## Contributors ## |
| 123 | + |
| 124 | +Pull requests, issues and comments are welcomed. For pull requests: |
| 125 | + |
| 126 | +* Add tests for new features and bug fixes |
| 127 | +* Follow the existing style |
| 128 | +* Separate unrelated changes into multiple pull requests |
| 129 | +* Read [Contributing guidelines][CONTRIBUTING] for more details |
| 130 | + |
| 131 | +See the existing issues for things to start contributing. |
| 132 | + |
| 133 | +For bigger changes, make sure you start a discussion first by creating |
| 134 | +an issue and explaining the intended change. |
| 135 | + |
| 136 | +Atlassian requires contributors to sign a Contributor License Agreement, |
| 137 | +known as a CLA. This serves as a record stating that the contributor is |
| 138 | +entitled to contribute the code/documentation/translation to the project |
| 139 | +and is willing to have it used in distributions and derivative works |
| 140 | +(or is willing to transfer ownership). |
| 141 | + |
| 142 | +Prior to accepting your contributions we ask that you please follow the appropriate |
| 143 | +link below to digitally sign the CLA. The Corporate CLA is for those who are |
| 144 | +contributing as a member of an organization and the individual CLA is for |
| 145 | +those contributing as an individual. |
| 146 | + |
| 147 | +* [CLA for corporate contributors](https://na2.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=e1c17c66-ca4d-4aab-a953-2c231af4a20b) |
| 148 | +* [CLA for individuals](https://na2.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=3f94fbdc-2fbe-46ac-b14c-5d152700ae5d) |
| 149 | + |
| 150 | + |
| 151 | +## License ## |
| 152 | +Copyright (c) 2017 Atlassian and others. Apache 2.0 licensed, see [LICENSE][LICENSE] file. |
| 153 | + |
| 154 | + |
| 155 | +[CONTRIBUTING]: ./CONTRIBUTING.md |
| 156 | +[LICENSE]: ./LICENSE.txt |
0 commit comments