This repository has been archived by the owner on Nov 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pkg/repository for interacting with GitHubReleases (#10)
- Loading branch information
Showing
7 changed files
with
142 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
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,7 @@ | ||
go_library( | ||
name = "repository", | ||
srcs = ["repository.go"], | ||
visibility = [ | ||
"//pkg/repository/...", | ||
], | ||
) |
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,11 @@ | ||
go_library( | ||
name = "ghreleases", | ||
srcs = ["ghreleases.go"], | ||
visibility = ["//build/..."], | ||
deps = [ | ||
"//internal/logging", | ||
"//pkg/repository", | ||
"//third_party/go:google_github", | ||
"//third_party/go:x_oauth2", | ||
], | ||
) |
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 ghreleases | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/go-github/v37/github" | ||
"github.com/thought-machine/falco-probes/internal/logging" | ||
"github.com/thought-machine/falco-probes/pkg/repository" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
var log = logging.Logger | ||
|
||
// Opts represents the available options for the GitHub Releases client. | ||
type Opts struct { | ||
Token string `long:"token" description:"The token to use to authenticate against github" env:"GITHUB_TOKEN" required:"true"` | ||
} | ||
|
||
// GHReleases implements repository.Repository against Github Releases. | ||
type GHReleases struct { | ||
repository.Repository | ||
|
||
ghClient *github.Client | ||
owner string | ||
repo string | ||
} | ||
|
||
// MustGHReleases returns a new GitHub Releases repository, fatally erroring if an error is encountered. | ||
func MustGHReleases(opts *Opts) *GHReleases { | ||
|
||
ghClient := newGHClient(opts.Token) | ||
|
||
return &GHReleases{ | ||
ghClient: ghClient, | ||
owner: "thought-machine", | ||
repo: "falco-probes", | ||
} | ||
} | ||
|
||
// PublishProbe implmements repository.Repository.PublishProbe for GitHub Releases. | ||
func (ghr *GHReleases) PublishProbe(driverVersion string, probeName string, probePath string) error { | ||
// TODO: unimplimented | ||
return fmt.Errorf("unimplemented") | ||
} | ||
|
||
// IsAlreadyMirrored implmements repository.Repository.IsAlreadyMirrored for GitHub Releases. | ||
func (ghr *GHReleases) IsAlreadyMirrored(driverVersion string, probeName string) error { | ||
// TODO: unimplimented | ||
return fmt.Errorf("unimplemented") | ||
} | ||
|
||
func newGHClient(token string) *github.Client { | ||
ts := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: token}, | ||
) | ||
ctx := context.Background() | ||
tc := oauth2.NewClient(ctx, ts) | ||
|
||
return github.NewClient(tc) | ||
} |
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,9 @@ | ||
package repository | ||
|
||
// Repository abstracts the implementation of repositories which mirror Falco probes. | ||
type Repository interface { | ||
// PublishProbe "publishes" (uploads/mirrors) the given probePath to the repository using the given driverVersion and probeName to organise probes. | ||
PublishProbe(driverVersion string, probeName string, probePath string) error | ||
// IsAlreadyMirrored returns whether or not the given probeName is already mirrored in the repository for the given driverVersion. | ||
IsAlreadyMirrored(driverVersion string, probeName string) bool | ||
} |
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