Skip to content

OctopusDeploy/go-octopusdeploy

Repository files navigation

go-octopusdeploy Logo

go-octopusdeploy

Go API Client for Octopus Deploy 🐙

GitHub release PkgGoDev Go Report


Install

go get "github.com/OctopusDeploy/go-octopusdeploy/v2"

Usage

import "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"

The Octopus REST API is exposed through service fields of the client. An API key is required to communicate with the API (see How to Create an API Key for more information).

apiKey := "API-YOUR_API_KEY"
octopusURL := "https://your_octopus_url"
spaceID := "space-id" // can also be blank to assume the default space

apiURL, err := url.Parse(octopusURL)
if err != nil {
    _ = fmt.Errorf("error parsing URL for Octopus API: %v", err)
    return
}

// the first parameter for NewClient can accept a http.Client if you wish to
// override the default; also, the spaceID may be an empty string (i.e. "") if
// you wish to load the default space
octopusClient, err := client.NewClient(nil, apiURL, apiKey, spaceID)
if err != nil {
    _ = fmt.Errorf("error creating API client: %v", err)
    return
}

Once the client has been initialized, APIs can be targeted through the model and services available:

usernamePasswordAccount := accounts.NewUsernamePasswordAccount(name)
usernamePasswordAccount.Username = username

createdAccount, err := accounts.Add(octopusClient, usernamePasswordAccount)
if err != nil {
    _ = fmt.Errorf("error adding account: %v", err)
}

Operations like Add, DeleteByID, GetByID, and Update are supported by most services that are exposed through the client if not exposed in the package. These operations are configured at runtime since the Octopus REST API is hypermedia-driven.

Numerous code samples that showcase the API and this client are available in the examples directory. There are also many integration and unit tests available to examine that demonstrate the capabilities of this API client.

🤝 Contributions

Contributions are welcome! ❤️ Please read our Contributing Guide for information about how to get involved in this project.