-
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.
Merge pull request #8 from grafana/7-implement-cli
implement cli
- Loading branch information
Showing
24 changed files
with
1,478 additions
and
60 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/build | ||
/coverage.txt | ||
/k6registry | ||
/k6registry.exe |
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
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,8 @@ | ||
FROM debian:12.6-slim | ||
|
||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates | ||
RUN update-ca-certificates | ||
|
||
COPY k6registry /usr/bin/ | ||
|
||
ENTRYPOINT ["k6registry"] |
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
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,49 @@ | ||
name: k6registry | ||
description: k6 extension registry processor | ||
author: Grafana Labs | ||
|
||
branding: | ||
icon: settings | ||
color: purple | ||
|
||
inputs: | ||
filter: | ||
description: jq compatible filter | ||
required: false | ||
default: . | ||
|
||
in: | ||
description: input file name | ||
required: true | ||
|
||
out: | ||
description: output file name | ||
required: false | ||
|
||
mute: | ||
description: no output, only validation | ||
required: false | ||
|
||
loose: | ||
description: skip JSON schema validation | ||
required: false | ||
|
||
lint: | ||
description: enable built-in linter | ||
required: false | ||
|
||
compact: | ||
description: compact instead of pretty-printed output | ||
required: false | ||
|
||
raw: | ||
description: output raw strings, not JSON texts | ||
required: false | ||
|
||
yaml: | ||
description: output YAML instead of JSON | ||
required: false | ||
|
||
runs: | ||
using: docker | ||
image: ghcr.io/grafana/k6registry:v0 |
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
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,61 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/cli/go-gh/v2/pkg/api" | ||
"github.com/cli/go-gh/v2/pkg/auth" | ||
"github.com/cli/go-gh/v2/pkg/config" | ||
"github.com/google/go-github/v62/github" | ||
) | ||
|
||
type githubClientKey struct{} | ||
|
||
var errInvalidContext = errors.New("invalid context") | ||
|
||
// contextGitHubClient returns a *github.Client from context. | ||
func contextGitHubClient(ctx context.Context) (*github.Client, error) { | ||
value := ctx.Value(githubClientKey{}) | ||
if value != nil { | ||
if client, ok := value.(*github.Client); ok { | ||
return client, nil | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("%w: missing github.Client", errInvalidContext) | ||
} | ||
|
||
// newContext prepares GitHub CLI extension context with http.Client and github.Client values. | ||
// You can use ContextHTTPClient and ContextGitHubClient later to get client instances from the context. | ||
func newContext(ctx context.Context) (context.Context, error) { | ||
htc, err := newHTTPClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return context.WithValue(ctx, githubClientKey{}, github.NewClient(htc)), nil | ||
} | ||
|
||
func newHTTPClient() (*http.Client, error) { | ||
var opts api.ClientOptions | ||
|
||
opts.Host, _ = auth.DefaultHost() | ||
|
||
opts.AuthToken, _ = auth.TokenForHost(opts.Host) | ||
if opts.AuthToken == "" { | ||
return nil, fmt.Errorf("authentication token not found for host %s", opts.Host) | ||
} | ||
|
||
if cfg, _ := config.Read(nil); cfg != nil { | ||
opts.UnixDomainSocket, _ = cfg.Get([]string{"http_unix_socket"}) | ||
} | ||
|
||
opts.EnableCache = true | ||
opts.CacheTTL = 2 * time.Hour | ||
|
||
return api.NewHTTPClient(opts) | ||
} |
Oops, something went wrong.