Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Add pkg/repository for interacting with GitHubReleases (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
VJftw authored Jul 15, 2021
1 parent bf09b8b commit 411d6ff
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ require (
github.com/containerd/containerd v1.5.2 // indirect
github.com/docker/docker v20.10.7+incompatible
github.com/docker/go-connections v0.4.0 // indirect
github.com/google/go-github/v37 v37.0.0
github.com/jessevdk/go-flags v1.5.0
github.com/morikuni/aec v1.0.0 // indirect
github.com/rs/zerolog v1.23.0
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/stretchr/testify v1.7.0
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/grpc v1.39.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
github.com/google/go-github/v37 v37.0.0 h1:rCspN8/6kB1BAJWZfuafvHhyfIo5fkAulaP/3bOQ/tM=
github.com/google/go-github/v37 v37.0.0/go.mod h1:LM7in3NmXDrX58GbEHy7FtNLbI2JijX93RnMKvWG3m4=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down Expand Up @@ -610,6 +616,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -681,6 +688,7 @@ golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAG
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
7 changes: 7 additions & 0 deletions pkg/repository/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go_library(
name = "repository",
srcs = ["repository.go"],
visibility = [
"//pkg/repository/...",
],
)
11 changes: 11 additions & 0 deletions pkg/repository/ghreleases/BUILD
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",
],
)
61 changes: 61 additions & 0 deletions pkg/repository/ghreleases/ghreleases.go
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)
}
9 changes: 9 additions & 0 deletions pkg/repository/repository.go
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
}
44 changes: 44 additions & 0 deletions third_party/go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ go_module(
"internal/socks",
"http2",
"http2/hpack",
"context/ctxhttp",
],
licences = ["BSD-3-Clause"],
module = "golang.org/x/net",
Expand Down Expand Up @@ -392,3 +393,46 @@ go_module(
module = "github.com/rs/zerolog",
version = "v1.23.0",
)

go_module(
name = "google_github",
install = ["github"],
licences = ["BSD-3-Clause"],
module = "github.com/google/go-github/v37",
version = "v37.0.0",
deps = [
":google_querystring",
":x_crypto",
],
)

go_module(
name = "x_crypto",
install = [
"openpgp/...",
"cast5",
],
licences = ["BSD-3-Clause"],
module = "golang.org/x/crypto",
version = "v0.0.0-20210711020723-a769d52b0f97",
)

go_module(
name = "google_querystring",
install = ["query"],
licences = ["BSD-3-Clause"],
module = "github.com/google/go-querystring",
version = "v1.1.0",
)

go_module(
name = "x_oauth2",
install = [
".",
"internal",
],
licences = ["BSD-3-Clause"],
module = "golang.org/x/oauth2",
version = "v0.0.0-20210628180205-a41e5a781914",
deps = [":x_net"],
)

0 comments on commit 411d6ff

Please sign in to comment.