-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: initial commit * chore: check in generated methods * update * chore: push runner sdk
- Loading branch information
1 parent
110cdee
commit 21a56fd
Showing
403 changed files
with
98,759 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2024 Nuon Inc | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,71 @@ | ||
# nuon-runner-go | ||
|
||
The SDK that powers the Nuon runner. | ||
|
||
## Overview | ||
|
||
The Nuon runner is deployed in each install, and powers everything from updates, releases and rollouts to day 2 | ||
monitoring. | ||
|
||
Full documentation is available at https://runner.nuon.co/docs/index.html. | ||
|
||
All endpoints in the API follow REST conventions and standard HTTP methods. You can find the OpenAPI Spec | ||
[here](https://runner.nuon.co/oapi/v3) | ||
|
||
## Installation | ||
|
||
In your project, you can install the package directly using `go get`: | ||
|
||
```bash | ||
go get github.com/nuonco/nuon-runner-go | ||
``` | ||
|
||
In your code, add the following import: | ||
|
||
``` | ||
import nuonrunner "github.com/nuonco/nuon-runner-go" | ||
``` | ||
|
||
## Create a client | ||
|
||
Create a new api client, using an API key set in the environment. | ||
|
||
```go | ||
apiURL := "https://runner.nuon.co" | ||
apiToken := os.Getenv("NUON_API_TOKEN") | ||
runnerID := os.Getenv("NUON_RUNNER_ID") | ||
|
||
apiClient, err := client.New(s.v, | ||
client.WithAuthToken(apiToken), | ||
client.WithURL(apiURL), | ||
client.WithRunnerID(orgID), | ||
) | ||
if err != nil { | ||
return fmt.Errorf("unable to get api client: %w", err) | ||
} | ||
``` | ||
|
||
## Example usage | ||
|
||
### List current available jobs | ||
|
||
```go | ||
jobs, err := apiClient.AvailableJobs(ctx) | ||
``` | ||
|
||
## Contributing | ||
|
||
Please submit a PR, and if you would like help, contact us on our [community | ||
slack](https://join.slack.com/t/nuoncommunity/shared_invite/zt-1q323vw9z-C8ztRP~HfWjZx6AXi50VRA). | ||
|
||
You can generate mock code using: | ||
|
||
```bash | ||
$ go generate ./... | ||
``` | ||
|
||
You can also change the open api spec to generate against, by setting the `API_URL` field to a different value: | ||
|
||
```bash | ||
$ NUON_API_URL=http://localhost:8081 go generate ./... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package nuonrunner | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
// appTransport is a transport that injects our authentication token and org id into the api request | ||
type appTransport struct { | ||
authToken string | ||
orgID string | ||
|
||
transport http.RoundTripper | ||
} | ||
|
||
func (t *appTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
req.Header.Set("Authorization", "Bearer "+t.authToken) | ||
if t.orgID != "" { | ||
req.Header.Set("X-Nuon-Org-ID", t.orgID) | ||
} | ||
|
||
return t.transport.RoundTrip(req) | ||
} | ||
|
||
func (c *client) SetOrgID(orgID string) { | ||
c.appTransport.orgID = orgID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nuonrunner | ||
|
||
import ( | ||
"github.com/go-openapi/runtime" | ||
runtimeclient "github.com/go-openapi/runtime/client" | ||
) | ||
|
||
func (c *client) getAuthInfo() runtime.ClientAuthInfoWriter { | ||
return runtimeclient.Compose( | ||
c.getApiKeyAuthInfo(), | ||
) | ||
} | ||
|
||
func (c *client) getApiKeyAuthInfo() runtime.ClientAuthInfoWriter { | ||
return runtimeclient.BearerToken(c.APIToken) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package nuonrunner | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
httptransport "github.com/go-openapi/runtime/client" | ||
"github.com/go-playground/validator/v10" | ||
|
||
genclient "github.com/nuonco/nuon-runner-go/client" | ||
|
||
"github.com/nuonco/nuon-runner-go/models" | ||
) | ||
|
||
//go:generate ./generate.sh | ||
type Client interface { | ||
SetRunnerID(runnerID string) | ||
|
||
GetSettings(ctx context.Context) (*models.AppRunnerGroupSettings, error) | ||
|
||
// heartbeat and health checks | ||
CreateHeartBeat(ctx context.Context, req *models.ServiceCreateRunnerHeartBeatRequest) (*models.AppRunnerHeartBeat, error) | ||
CreateHealthCheck(ctx context.Context, req *models.ServiceCreateRunnerHealthCheckRequest) (*models.AppRunnerHealthCheck, error) | ||
|
||
// jobs | ||
GetJobs(ctx context.Context, grp models.AppRunnerJobGroup, status models.AppRunnerJobStatus, limit *int64) ([]*models.AppRunnerJob, error) | ||
GetJob(ctx context.Context, jobID string) (*models.AppRunnerJob, error) | ||
GetJobPlan(ctx context.Context, jobID string) (*models.Planv1Plan, error) | ||
|
||
// job executions | ||
GetJobExecutions(ctx context.Context, jobID string) ([]*models.AppRunnerJobExecution, error) | ||
CreateJobExecution(ctx context.Context, jobID string, req *models.ServiceCreateRunnerJobExecutionRequest) (*models.AppRunnerJobExecution, error) | ||
UpdateJobExecution(ctx context.Context, jobID, jobExecutionID string, req *models.ServiceUpdateRunnerJobExecutionRequest) (*models.AppRunnerJobExecution, error) | ||
CreateJobExecutionResult(ctx context.Context, jobID, jobExecutionID string, req *models.ServiceCreateRunnerJobExecutionResultRequest) (*models.AppRunnerJobExecutionResult, error) | ||
|
||
// otel operations | ||
WriteOTELLogs(ctx context.Context, req interface{}) error | ||
WriteOTELTraces(ctx context.Context, req interface{}) error | ||
WriteOTELMetrics(ctx context.Context, req interface{}) error | ||
} | ||
|
||
var _ Client = (*client)(nil) | ||
|
||
type client struct { | ||
v *validator.Validate | ||
|
||
APIURL string `validate:"required"` | ||
APIToken string | ||
RunnerID string | ||
|
||
genClient *genclient.NuonRunnerAPI | ||
appTransport *appTransport | ||
} | ||
|
||
type clientOption func(*client) error | ||
|
||
func New(opts ...clientOption) (*client, error) { | ||
c := &client{} | ||
for _, opt := range opts { | ||
if err := opt(c); err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
if c.v == nil { | ||
c.v = validator.New() | ||
} | ||
|
||
if err := c.v.Struct(c); err != nil { | ||
return nil, err | ||
} | ||
|
||
apiURL, err := url.Parse(c.APIURL) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse api url: %w", err) | ||
} | ||
|
||
transport := httptransport.New(apiURL.Host, "", []string{apiURL.Scheme}) | ||
appTransport := &appTransport{ | ||
authToken: c.APIToken, | ||
transport: http.DefaultTransport, | ||
} | ||
c.appTransport = appTransport | ||
transport.Transport = appTransport | ||
genClient := genclient.New(transport, nil) | ||
c.genClient = genClient | ||
|
||
return c, nil | ||
} | ||
|
||
// WithAuthToken specifies the auth token to use | ||
func WithAuthToken(token string) clientOption { | ||
return func(c *client) error { | ||
c.APIToken = token | ||
return nil | ||
} | ||
} | ||
|
||
// WithURL specifies the url to use | ||
func WithURL(url string) clientOption { | ||
return func(c *client) error { | ||
c.APIURL = url | ||
return nil | ||
} | ||
} | ||
|
||
// WithRunnerID specifies the runner id to use | ||
func WithRunnerID(runnerID string) clientOption { | ||
return func(c *client) error { | ||
c.RunnerID = runnerID | ||
return nil | ||
} | ||
} | ||
|
||
// WithValidator specifies a validator to use | ||
func WithValidator(v *validator.Validate) clientOption { | ||
return func(c *client) error { | ||
c.v = v | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package client |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.