mirror of
https://github.com/peridotbuild/peridot.git
synced 2024-12-03 18:16:25 +00:00
Add support for remote forges
This commit is contained in:
parent
26aeb7cc9e
commit
051589caee
12
tools/mothership/worker_server/forge/BUILD
Normal file
12
tools/mothership/worker_server/forge/BUILD
Normal file
@ -0,0 +1,12 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "forge",
|
||||
srcs = [
|
||||
"caching.go",
|
||||
"forge.go",
|
||||
],
|
||||
importpath = "go.resf.org/peridot/tools/mothership/worker_server/forge",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = ["//vendor/github.com/go-git/go-git/v5/plumbing/transport"],
|
||||
)
|
@ -1 +1,35 @@
|
||||
package forge
|
||||
|
||||
import "time"
|
||||
|
||||
type Cacher struct {
|
||||
Forge
|
||||
|
||||
authenticator *Authenticator
|
||||
}
|
||||
|
||||
func NewCacher(f Forge) *Cacher {
|
||||
return &Cacher{
|
||||
Forge: f,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cacher) GetAuthenticator() (*Authenticator, error) {
|
||||
if c.authenticator != nil {
|
||||
// Check if the token is expired, if not return it
|
||||
if !c.authenticator.Expires.Before(time.Now()) {
|
||||
return c.authenticator, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, get a new token
|
||||
c.authenticator = nil
|
||||
a, err := c.Forge.GetAuthenticator()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.authenticator = a
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
@ -1 +1,22 @@
|
||||
package forge
|
||||
|
||||
import (
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Authenticator struct {
|
||||
transport.AuthMethod
|
||||
|
||||
AuthorName string
|
||||
AuthorEmail string
|
||||
// Expires is the time when the token expires.
|
||||
// So it can be used to cache the token.
|
||||
Expires time.Time
|
||||
}
|
||||
|
||||
type Forge interface {
|
||||
GetAuthenticator() (*Authenticator, error)
|
||||
GetRemote() string
|
||||
EnsureRepositoryExists(auth *Authenticator, repo string) error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user