mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:31:43 +00:00
Movin enterprise codeintel stuff (and ~two others that had to be dragged
along) out of `enterprise/internal` and into `internal` as part of the
shift towards enterprise-only
## Test plan
Successfully built frontend with bazel, CI will check the rest
😎 no logic changed, just shufflin things around
38 lines
789 B
Go
38 lines
789 B
Go
package auth
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
|
|
"github.com/sourcegraph/sourcegraph/internal/rcache"
|
|
)
|
|
|
|
type GitHubAuthCache struct {
|
|
cache *rcache.Cache
|
|
}
|
|
|
|
var githubAuthCache = &GitHubAuthCache{
|
|
cache: rcache.NewWithTTL("codeintel.github-authz:", 60 /* seconds */),
|
|
}
|
|
|
|
func (c *GitHubAuthCache) Get(key string) (authorized bool, _ bool) {
|
|
b, ok := c.cache.Get(key)
|
|
if !ok {
|
|
return false, false
|
|
}
|
|
|
|
err := json.Unmarshal(b, &authorized)
|
|
return authorized, err == nil
|
|
}
|
|
|
|
func (c *GitHubAuthCache) Set(key string, authorized bool) {
|
|
b, _ := json.Marshal(authorized)
|
|
c.cache.Set(key, b)
|
|
}
|
|
|
|
func makeGitHubAuthCacheKey(githubToken, repoName string) string {
|
|
key := sha256.Sum256([]byte(githubToken + ":" + repoName))
|
|
return hex.EncodeToString(key[:])
|
|
}
|