Skip to content

Latest commit

History

1,485 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

LicenseMade With GoReleaseIssuesContributorsActivityCodeCovDependabotGo Reference

The OpsLevel Gopher

Overall

opslevel-go

Package opslevel provides an OpsLevel API client implementation.

Installation

opslevel requires Go version 1.8 or later.

go get -u github.com/opslevel/opslevel-go/v2026

Usage

Construct a client, specifying the API token. Then, you can use it to make GraphQL queries and mutations.

client:=opslevel.NewGQLClient(opslevel.SetAPIToken("XXX_API_TOKEN_XXX"))
// Use client...

You can validate the client can successfully talk to the OpsLevel API.

client:=opslevel.NewGQLClient(opslevel.SetAPIToken("XXX_API_TOKEN_XXX"))
iferr:=client.Validate(); err!=nil {
panic(err)
}

Every resource (IE: service, lifecycle, tier, etc.) in OpsLevel API has a corresponding data structure in go as well as the graphql query & mutation inputs. Additionally, there are also some helper functions that use native go types like string and []string to make it easier to work with. The following are a handful of examples:

Find a service given an alias and print the owning team name:

foundService, foundServiceErr:=client.GetService("MyCoolService")
iffoundServiceErr!=nil {
panic(foundServiceErr)
}
fmt.Println(foundService.Owner.Name)

Create a new service in OpsLevel and print the ID:

serviceCreateInput:= opslevel.ServiceCreateInput{
Name: "MyCoolService",
Description: opslevel.RefOf("The Coolest Service"),
Language: opslevel.RefOf("go"),
OwnerAlias: opslevel.RefOf("team-platform"),
}
newService, newServiceErr:=client.CreateService(serviceCreateInput)
ifnewServiceErr!=nil {
panic(newServiceErr)
}
fmt.Println(newService.Id)

Assign the tag {"hello": "world"} to our newly created service and print all the tags currently on it:

allTagsOnThisService, assignTagsErr:=client.AssignTags(string(newService.Id), map[string]string{"hello": "world"})
ifassignTagsErr!=nil {
panic(assignTagsErr)
}
for_, tagOnService:=rangeallTagsOnThisService {
fmt.Printf("Tag '{%s : %s}'", tagOnService.Id, tagOnService.Value)
}

List all the tags for a service:

myService, foundServiceErr:=client.GetService("MyCoolService")
iffoundServiceErr!=nil {
panic(foundServiceErr)
}
tags, getTagsErr:=myService.GetTags(client, nil)
ifgetTagsErr!=nil {
panic(getTagsErr)
}
for_, tag:=rangetags {
fmt.Printf("Tag '{%s : %s}'\n", tag.Key, tag.Value)
}

Build a lookup table of teams:

funcGetTeams(client*opslevel.Client) (map[string]opslevel.Team, error) {
teams:=make(map[string]opslevel.Team)
data, dataErr:=client.ListTeams(nil)
ifdataErr!=nil {
returnteams, dataErr
}
for_, team:=rangedata {
teams[string(team.Alias)] =team
}
returnteams, nil
}

Advanced Usage

The client also exposes functions Query and Mutate for doing custom query or mutations. We are running on top of this go graphql library.

About

A Go client for interacting with OpsLevel

Topics

Resources

Contributing

Stars

6 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages