go-artifactory

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2018 License: Apache-2.0

README

go-artifactory

go-artifactory is a Go client library for accessing the Artifactory API

Build Status

Requirements

  • Go version 1.9+
  • Dep is used for dependency management

Usage

import "github.com/atlassian/go-artifactory/pkg/artifactory"

Construct a new Artifactory client, then use the various services on the client to access different parts of the Artifactory API. For example:

client := artifactory.NewClient("http://localhost/artifactory", nil)

// list all repositories
repos, resp, err := client.Repositories.List(context.Background(), nil)

Some API methods have optional parameters that can be passed. For example:

client := artifactroy.NewClient("http://localhost/artifactory", nil)

// list all public local repositories
opt := &artifactory.RepositoryListOptions{Type: "local"}
client.Repositories.ListRepositories(ctx, opt)

The services of a client divide the API into logical chunks and correspond to the structure of the Artifactory API documentation at https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API.

NOTE: Using the context package, one can easily pass cancelation signals and deadlines to various services of the client for handling a request. In case there is no context available, then context.Background() can be used as a starting point.

Authentication

The go-artifactory library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle authentication for you.

For API methods that require HTTP Basic Authentication, use the BasicAuthTransport or TokenTransport

package main

import (
	"github.com/atlassian/go-artifactory/pkg/artifactory"
	"fmt"
	"context"
)

func main() {
	tp := artifactory.BasicAuthTransport{
		Username: "<YOUR_USERNAME>",
		Password: "<YOUR_PASSWORD>",
	}
	
	client, err := artifactory.NewClient("https://localhost/artifactory", tp.Client())
	if err != nil {
		fmt.Println(err.Error())
	}

	repos, resp, err := client.Repositories.ListRepositories(context.Background(), nil)
}
Creating and Updating Resources

All structs for GitHub resources use pointer values for all non-repeated fields. This allows distinguishing between unset fields and those set to a zero-value. Helper functions have been provided to easily create these pointers for string, bool, and int values. For example:

    // create a new local repository named "lib-releases"
    repo := artifactory.LocalRepository{
		Key:             artifactory.String("lib-releases"),
		RClass:          artifactory.String("local"),
		PackageType:     artifactory.String("maven"),
		HandleSnapshots: artifactory.Bool(false);
	}

	client.Repositories.CreateLocal(context.Background(), &repo)

Users who have worked with protocol buffers should find this pattern familiar.

Roadmap

This library is being initially developed for an internal application at Atlassian, so API methods will likely be implemented in the order that they are needed by that application. Eventually, it would be ideal to cover the entire Artifactory API, so contributions are of course always welcome. The calling pattern is pretty well established, so adding new methods is relatively straightforward.

Versioning

In general, go-artifactory follows semver as closely as we can for tagging releases of the package. For self-contained libraries, the application of semantic versioning is relatively straightforward and generally understood. But because go-artifactory is a client library for the Artifactory API we've adopted the following versioning policy:

  • We increment the major version with any incompatible change to functionality, including changes to the exported Go API surface or behavior of the API.
  • We increment the minor version with any backwards-compatible changes to functionality.
  • We increment the patch version with any backwards-compatible bug fixes.

Generally methods will be annotated with a since version.

Reporting issues

We believe in open contributions and the power of a strong development community. Please read our Contributing guidelines on how to contribute back and report issues to go-stride.

Contributors

Pull requests, issues and comments are welcomed. For pull requests:

  • Add tests for new features and bug fixes
  • Follow the existing style
  • Separate unrelated changes into multiple pull requests
  • Read Contributing guidelines for more details

See the existing issues for things to start contributing.

For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change.

Atlassian requires contributors to sign a Contributor License Agreement, known as a CLA. This serves as a record stating that the contributor is entitled to contribute the code/documentation/translation to the project and is willing to have it used in distributions and derivative works (or is willing to transfer ownership).

Prior to accepting your contributions we ask that you please follow the appropriate link below to digitally sign the CLA. The Corporate CLA is for those who are contributing as a member of an organization and the individual CLA is for those contributing as an individual.

License

Copyright (c) 2017 Atlassian and others. Apache 2.0 licensed, see LICENSE file.

Directories

Path Synopsis
cmd
examples/simple
Retrieves list of all repositories for an artifactory instance
Retrieves list of all repositories for an artifactory instance
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL