Code Monkey home page Code Monkey logo

harness-go-sdk's Introduction

Harness SDK for Go

This project is a Harness SDK for the go programming language. It provides go client for interacting with the current gen GraphQL and Config-as-Code API's.

Disclaimer

This product is not supported by the Harness Customer support team. If you have any questions please open a new issue or join our slack channel.

Getting Started

Installing

Use go get to retrieve the SDK to add it to your GOPATH workspace, or project's Go module dependencies.

go get github.com/harness/harness-go-sdk

To update the SDK use go get -u to retrieve the latest version of the SDK.

go get -u github.com/harness/harness-go-sdk

Dependencies

The metadata of the SDK's dependencies can be found in the Go module file go.mod.

Go Modules

If you are using Go modules, your go get will default to the latest tagged release version of the SDK. To get a specific release version of the SDK use @<tag> in your go get command.

go get github.com/harness/[email protected]

To get the latest SDK repository change use @latest.

go get github.com/harness/harness-go-sdk@latest

Quick Examples

Get an application by name

client := NewClient()
app, err := client.ApplicationClient.GetApplicationByName("my-app)

Create a Service

svc, _ := ServiceFactory(app.Id, serviceName, cac.DeploymentTypes.Kubernetes, cac.ArtifactTypes.Docker)
svc.ApplicationId = app.Id

newService, err := client.Services().UpsertService(svc)

Configuration

There are a few environment variables you can set to configure the api client.

  • HARNESS_ACCOUNT_ID: (required) The ID of the harness account you are connecting to.
  • HARNESS_API_KEY: (required) The API Key used for authentication.
  • HARNESS_BEARER_TOKEN: (optional) The authentication bearer token. This is needed for certain API calls to the config-as-code API's. This will be deprecated in the near future once those endpoints are updated.
  • HARNESS_ENDPOINT: (optional) The FQDN for contacting the Harness managers. Defaults to https://app.harness.io.

If you need to provide additional configuration you can create a client object from scratch.

client := &Client{
    UserAgent:   getUserAgentString(),
    Endpoint:    utils.GetEnv(envvar.Endpoint, utils.DefaultApiUrl),
    AccountId:   os.Getenv(envvar.AccountId),
    APIKey:      os.Getenv(envvar.ApiKey),
    BearerToken: os.Getenv(envvar.BearerToken),
    HTTPClient: &retryablehttp.Client{
        RetryMax:     10,
        RetryWaitMin: 5 * time.Second,
        RetryWaitMax: 10 * time.Second,
        HTTPClient: &http.Client{
            Timeout: 10 * time.Second,
        },
        Backoff:    retryablehttp.DefaultBackoff,
        CheckRetry: retryablehttp.DefaultRetryPolicy,
    },
}

The github.com/hashicorp/go-retryablehttp is essentially a drop-in replacement for the http package and is used to handle retries when getting rate limited.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.