code
stringlengths
11
335k
docstring
stringlengths
20
11.8k
func_name
stringlengths
1
100
language
stringclasses
1 value
repo
stringclasses
245 values
path
stringlengths
4
144
url
stringlengths
43
214
license
stringclasses
4 values
func (c *Config) Client(ctx context.Context, t *Token) *http.Client { return NewClient(ctx, c.TokenSource(ctx, t)) }
Client returns an HTTP client using the provided token. The token will auto-refresh as necessary. The underlying HTTP transport will be obtained using the provided context. The returned client and its Transport should not be modified.
Client
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func (c *Config) TokenSource(ctx context.Context, t *Token) TokenSource { tkr := &tokenRefresher{ ctx: ctx, conf: c, } if t != nil { tkr.refreshToken = t.RefreshToken } return &reuseTokenSource{ t: t, new: tkr, } }
TokenSource returns a TokenSource that returns t until t expires, automatically refreshing it as necessary using the provided context. Most users will use Config.Client instead.
TokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func (tf *tokenRefresher) Token() (*Token, error) { if tf.refreshToken == "" { return nil, errors.New("oauth2: token expired and refresh token is not set") } tk, err := retrieveToken(tf.ctx, tf.conf, url.Values{ "grant_type": {"refresh_token"}, "refresh_token": {tf.refreshToken}, }) if err != nil { return nil, err } if tf.refreshToken != tk.RefreshToken { tf.refreshToken = tk.RefreshToken } return tk, err }
WARNING: Token is not safe for concurrent access, as it updates the tokenRefresher's refreshToken field. Within this package, it is used by reuseTokenSource which synchronizes calls to this method with its own mutex.
Token
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func (s *reuseTokenSource) Token() (*Token, error) { s.mu.Lock() defer s.mu.Unlock() if s.t.Valid() { return s.t, nil } t, err := s.new.Token() if err != nil { return nil, err } s.t = t return t, nil }
Token returns the current token if it's still valid, else will refresh the current token (using r.Context for HTTP client information) and return the new one.
Token
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func StaticTokenSource(t *Token) TokenSource { return staticTokenSource{t} }
StaticTokenSource returns a TokenSource that always returns the same token. Because the provided token t is never refreshed, StaticTokenSource is only useful for tokens that never expire.
StaticTokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func NewClient(ctx context.Context, src TokenSource) *http.Client { if src == nil { return internal.ContextClient(ctx) } return &http.Client{ Transport: &Transport{ Base: internal.ContextClient(ctx).Transport, Source: ReuseTokenSource(nil, src), }, } }
NewClient creates an *http.Client from a Context and TokenSource. The returned client is not valid beyond the lifetime of the context. Note that if a custom *http.Client is provided via the Context it is used only for token acquisition and is not used to configure the *http.Client returned from NewClient. As a special case, if src is nil, a non-OAuth2 client is returned using the provided context. This exists to support related OAuth2 packages.
NewClient
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func ReuseTokenSource(t *Token, src TokenSource) TokenSource { // Don't wrap a reuseTokenSource in itself. That would work, // but cause an unnecessary number of mutex operations. // Just build the equivalent one. if rt, ok := src.(*reuseTokenSource); ok { if t == nil { // Just use it directly. return rt } src = rt.new } return &reuseTokenSource{ t: t, new: src, } }
ReuseTokenSource returns a TokenSource which repeatedly returns the same token as long as it's valid, starting with t. When its cached token is invalid, a new token is obtained from src. ReuseTokenSource is typically used to reuse tokens from a cache (such as a file on disk) between runs of a program, rather than obtaining new tokens unnecessarily. The initial token t may be nil, in which case the TokenSource is wrapped in a caching version if it isn't one already. This also means it's always safe to wrap ReuseTokenSource around any other TokenSource without adverse effects.
ReuseTokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/oauth2.go
BSD-3-Clause
func (t *Token) Type() string { if strings.EqualFold(t.TokenType, "bearer") { return "Bearer" } if strings.EqualFold(t.TokenType, "mac") { return "MAC" } if strings.EqualFold(t.TokenType, "basic") { return "Basic" } if t.TokenType != "" { return t.TokenType } return "Bearer" }
Type returns t.TokenType if non-empty, else "Bearer".
Type
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func (t *Token) SetAuthHeader(r *http.Request) { r.Header.Set("Authorization", t.Type()+" "+t.AccessToken) }
SetAuthHeader sets the Authorization header to r using the access token in t. This method is unnecessary when using Transport or an HTTP Client returned by this package.
SetAuthHeader
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func (t *Token) WithExtra(extra interface{}) *Token { t2 := new(Token) *t2 = *t t2.raw = extra return t2 }
WithExtra returns a new Token that's a clone of t, but using the provided raw extra map. This is only intended for use by packages implementing derivative OAuth2 flows.
WithExtra
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func (t *Token) Extra(key string) interface{} { if raw, ok := t.raw.(map[string]interface{}); ok { return raw[key] } vals, ok := t.raw.(url.Values) if !ok { return nil } v := vals.Get(key) switch s := strings.TrimSpace(v); strings.Count(s, ".") { case 0: // Contains no "."; try to parse as int if i, err := strconv.ParseInt(s, 10, 64); err == nil { return i } case 1: // Contains a single "."; try to parse as float if f, err := strconv.ParseFloat(s, 64); err == nil { return f } } return v }
Extra returns an extra field. Extra fields are key-value pairs returned by the server as a part of the token retrieval response.
Extra
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func (t *Token) expired() bool { if t.Expiry.IsZero() { return false } return t.Expiry.Round(0).Add(-expiryDelta).Before(timeNow()) }
expired reports whether the token is expired. t must be non-nil.
expired
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func (t *Token) Valid() bool { return t != nil && t.AccessToken != "" && !t.expired() }
Valid reports whether t is non-nil, has an AccessToken, and is not expired.
Valid
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func tokenFromInternal(t *internal.Token) *Token { if t == nil { return nil } return &Token{ AccessToken: t.AccessToken, TokenType: t.TokenType, RefreshToken: t.RefreshToken, Expiry: t.Expiry, raw: t.Raw, } }
tokenFromInternal maps an *internal.Token struct into a *Token struct.
tokenFromInternal
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func retrieveToken(ctx context.Context, c *Config, v url.Values) (*Token, error) { tk, err := internal.RetrieveToken(ctx, c.ClientID, c.ClientSecret, c.Endpoint.TokenURL, v, internal.AuthStyle(c.Endpoint.AuthStyle)) if err != nil { if rErr, ok := err.(*internal.RetrieveError); ok { return nil, (*RetrieveError)(rErr) } return nil, err } return tokenFromInternal(tk), nil }
retrieveToken takes a *Config and uses that to retrieve an *internal.Token. This token is then mapped from *internal.Token into an *oauth2.Token which is returned along with an error..
retrieveToken
go
flynn/flynn
vendor/golang.org/x/oauth2/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/token.go
BSD-3-Clause
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { reqBodyClosed := false if req.Body != nil { defer func() { if !reqBodyClosed { req.Body.Close() } }() } if t.Source == nil { return nil, errors.New("oauth2: Transport's Source is nil") } token, err := t.Source.Token() if err != nil { return nil, err } req2 := cloneRequest(req) // per RoundTripper contract token.SetAuthHeader(req2) t.setModReq(req, req2) res, err := t.base().RoundTrip(req2) // req.Body is assumed to have been closed by the base RoundTripper. reqBodyClosed = true if err != nil { t.setModReq(req, nil) return nil, err } res.Body = &onEOFReader{ rc: res.Body, fn: func() { t.setModReq(req, nil) }, } return res, nil }
RoundTrip authorizes and authenticates the request with an access token from Transport's Source.
RoundTrip
go
flynn/flynn
vendor/golang.org/x/oauth2/transport.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/transport.go
BSD-3-Clause
func (t *Transport) CancelRequest(req *http.Request) { type canceler interface { CancelRequest(*http.Request) } if cr, ok := t.base().(canceler); ok { t.mu.Lock() modReq := t.modReq[req] delete(t.modReq, req) t.mu.Unlock() cr.CancelRequest(modReq) } }
CancelRequest cancels an in-flight request by closing its connection.
CancelRequest
go
flynn/flynn
vendor/golang.org/x/oauth2/transport.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/transport.go
BSD-3-Clause
func cloneRequest(r *http.Request) *http.Request { // shallow copy of the struct r2 := new(http.Request) *r2 = *r // deep copy of the Header r2.Header = make(http.Header, len(r.Header)) for k, s := range r.Header { r2.Header[k] = append([]string(nil), s...) } return r2 }
cloneRequest returns a clone of the provided *http.Request. The clone is a shallow copy of the struct and its Header map.
cloneRequest
go
flynn/flynn
vendor/golang.org/x/oauth2/transport.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/transport.go
BSD-3-Clause
func ParseKey(key []byte) (*rsa.PrivateKey, error) { block, _ := pem.Decode(key) if block != nil { key = block.Bytes } parsedKey, err := x509.ParsePKCS8PrivateKey(key) if err != nil { parsedKey, err = x509.ParsePKCS1PrivateKey(key) if err != nil { return nil, fmt.Errorf("private key should be a PEM or plain PKCS1 or PKCS8; parse error: %v", err) } } parsed, ok := parsedKey.(*rsa.PrivateKey) if !ok { return nil, errors.New("private key is invalid") } return parsed, nil }
ParseKey converts the binary contents of a private key file to an *rsa.PrivateKey. It detects whether the private key is in a PEM container or not. If so, it extracts the the private key from PEM container before conversion. It only supports PEM containers with no passphrase.
ParseKey
go
flynn/flynn
vendor/golang.org/x/oauth2/internal/oauth2.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/internal/oauth2.go
BSD-3-Clause
func RegisterBrokenAuthHeaderProvider(tokenURL string) {}
RegisterBrokenAuthHeaderProvider previously did something. It is now a no-op. Deprecated: this function no longer does anything. Caller code that wants to avoid potential extra HTTP requests made during auto-probing of the provider's auth style should set Endpoint.AuthStyle.
RegisterBrokenAuthHeaderProvider
go
flynn/flynn
vendor/golang.org/x/oauth2/internal/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/internal/token.go
BSD-3-Clause
func ResetAuthCache() { authStyleCache.Lock() defer authStyleCache.Unlock() authStyleCache.m = nil }
ResetAuthCache resets the global authentication style cache used for AuthStyleUnknown token requests.
ResetAuthCache
go
flynn/flynn
vendor/golang.org/x/oauth2/internal/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/internal/token.go
BSD-3-Clause
func lookupAuthStyle(tokenURL string) (style AuthStyle, ok bool) { authStyleCache.Lock() defer authStyleCache.Unlock() style, ok = authStyleCache.m[tokenURL] return }
lookupAuthStyle reports which auth style we last used with tokenURL when calling RetrieveToken and whether we have ever done so.
lookupAuthStyle
go
flynn/flynn
vendor/golang.org/x/oauth2/internal/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/internal/token.go
BSD-3-Clause
func setAuthStyle(tokenURL string, v AuthStyle) { authStyleCache.Lock() defer authStyleCache.Unlock() if authStyleCache.m == nil { authStyleCache.m = make(map[string]AuthStyle) } authStyleCache.m[tokenURL] = v }
setAuthStyle adds an entry to authStyleCache, documented above.
setAuthStyle
go
flynn/flynn
vendor/golang.org/x/oauth2/internal/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/internal/token.go
BSD-3-Clause
func newTokenRequest(tokenURL, clientID, clientSecret string, v url.Values, authStyle AuthStyle) (*http.Request, error) { if authStyle == AuthStyleInParams { v = cloneURLValues(v) if clientID != "" { v.Set("client_id", clientID) } if clientSecret != "" { v.Set("client_secret", clientSecret) } } req, err := http.NewRequest("POST", tokenURL, strings.NewReader(v.Encode())) if err != nil { return nil, err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") if authStyle == AuthStyleInHeader { req.SetBasicAuth(url.QueryEscape(clientID), url.QueryEscape(clientSecret)) } return req, nil }
newTokenRequest returns a new *http.Request to retrieve a new token from tokenURL using the provided clientID, clientSecret, and POST body parameters. inParams is whether the clientID & clientSecret should be encoded as the POST body. An 'inParams' value of true means to send it in the POST body (along with any values in v); false means to send it in the Authorization header.
newTokenRequest
go
flynn/flynn
vendor/golang.org/x/oauth2/internal/token.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/internal/token.go
BSD-3-Clause
func Decode(payload string) (*ClaimSet, error) { // decode returned id token to get expiry s := strings.Split(payload, ".") if len(s) < 2 { // TODO(jbd): Provide more context about the error. return nil, errors.New("jws: invalid token received") } decoded, err := base64.RawURLEncoding.DecodeString(s[1]) if err != nil { return nil, err } c := &ClaimSet{} err = json.NewDecoder(bytes.NewBuffer(decoded)).Decode(c) return c, err }
Decode decodes a claim set from a JWS payload.
Decode
go
flynn/flynn
vendor/golang.org/x/oauth2/jws/jws.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/jws/jws.go
BSD-3-Clause
func EncodeWithSigner(header *Header, c *ClaimSet, sg Signer) (string, error) { head, err := header.encode() if err != nil { return "", err } cs, err := c.encode() if err != nil { return "", err } ss := fmt.Sprintf("%s.%s", head, cs) sig, err := sg([]byte(ss)) if err != nil { return "", err } return fmt.Sprintf("%s.%s", ss, base64.RawURLEncoding.EncodeToString(sig)), nil }
EncodeWithSigner encodes a header and claim set with the provided signer.
EncodeWithSigner
go
flynn/flynn
vendor/golang.org/x/oauth2/jws/jws.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/jws/jws.go
BSD-3-Clause
func Encode(header *Header, c *ClaimSet, key *rsa.PrivateKey) (string, error) { sg := func(data []byte) (sig []byte, err error) { h := sha256.New() h.Write(data) return rsa.SignPKCS1v15(rand.Reader, key, crypto.SHA256, h.Sum(nil)) } return EncodeWithSigner(header, c, sg) }
Encode encodes a signed JWS with provided header and claim set. This invokes EncodeWithSigner using crypto/rsa.SignPKCS1v15 with the given RSA private key.
Encode
go
flynn/flynn
vendor/golang.org/x/oauth2/jws/jws.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/jws/jws.go
BSD-3-Clause
func Verify(token string, key *rsa.PublicKey) error { parts := strings.Split(token, ".") if len(parts) != 3 { return errors.New("jws: invalid token received, token must have 3 parts") } signedContent := parts[0] + "." + parts[1] signatureString, err := base64.RawURLEncoding.DecodeString(parts[2]) if err != nil { return err } h := sha256.New() h.Write([]byte(signedContent)) return rsa.VerifyPKCS1v15(key, crypto.SHA256, h.Sum(nil), []byte(signatureString)) }
Verify tests whether the provided JWT token's signature was produced by the private key associated with the supplied public key.
Verify
go
flynn/flynn
vendor/golang.org/x/oauth2/jws/jws.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/jws/jws.go
BSD-3-Clause
func (c *Config) TokenSource(ctx context.Context) oauth2.TokenSource { return oauth2.ReuseTokenSource(nil, jwtSource{ctx, c}) }
TokenSource returns a JWT TokenSource using the configuration in c and the HTTP client from the provided context.
TokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/jwt/jwt.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/jwt/jwt.go
BSD-3-Clause
func (c *Config) Client(ctx context.Context) *http.Client { return oauth2.NewClient(ctx, c.TokenSource(ctx)) }
Client returns an HTTP client wrapping the context's HTTP transport and adding Authorization headers with tokens obtained from c. The returned client and its Transport should not be modified.
Client
go
flynn/flynn
vendor/golang.org/x/oauth2/jwt/jwt.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/jwt/jwt.go
BSD-3-Clause
func appEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource { logOnce.Do(func() { log.Print("google: AppEngineTokenSource is deprecated on App Engine standard second generation runtimes (>= Go 1.11) and App Engine flexible. Please use DefaultTokenSource or ComputeTokenSource.") }) return ComputeTokenSource("") }
See comment on AppEngineTokenSource in appengine.go.
appEngineTokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/google/appengine_gen2_flex.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/appengine_gen2_flex.go
BSD-3-Clause
func DefaultClient(ctx context.Context, scope ...string) (*http.Client, error) { ts, err := DefaultTokenSource(ctx, scope...) if err != nil { return nil, err } return oauth2.NewClient(ctx, ts), nil }
DefaultClient returns an HTTP Client that uses the DefaultTokenSource to obtain authentication credentials.
DefaultClient
go
flynn/flynn
vendor/golang.org/x/oauth2/google/default.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/default.go
BSD-3-Clause
func DefaultTokenSource(ctx context.Context, scope ...string) (oauth2.TokenSource, error) { creds, err := FindDefaultCredentials(ctx, scope...) if err != nil { return nil, err } return creds.TokenSource, nil }
DefaultTokenSource returns the token source for "Application Default Credentials". It is a shortcut for FindDefaultCredentials(ctx, scope).TokenSource.
DefaultTokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/google/default.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/default.go
BSD-3-Clause
func FindDefaultCredentials(ctx context.Context, scopes ...string) (*Credentials, error) { // First, try the environment variable. const envVar = "GOOGLE_APPLICATION_CREDENTIALS" if filename := os.Getenv(envVar); filename != "" { creds, err := readCredentialsFile(ctx, filename, scopes) if err != nil { return nil, fmt.Errorf("google: error getting credentials using %v environment variable: %v", envVar, err) } return creds, nil } // Second, try a well-known file. filename := wellKnownFile() if creds, err := readCredentialsFile(ctx, filename, scopes); err == nil { return creds, nil } else if !os.IsNotExist(err) { return nil, fmt.Errorf("google: error getting credentials using well-known file (%v): %v", filename, err) } // Third, if we're on a Google App Engine standard first generation runtime (<= Go 1.9) // use those credentials. App Engine standard second generation runtimes (>= Go 1.11) // and App Engine flexible use ComputeTokenSource and the metadata server. if appengineTokenFunc != nil { return &DefaultCredentials{ ProjectID: appengineAppIDFunc(ctx), TokenSource: AppEngineTokenSource(ctx, scopes...), }, nil } // Fourth, if we're on Google Compute Engine, an App Engine standard second generation runtime, // or App Engine flexible, use the metadata server. if metadata.OnGCE() { id, _ := metadata.ProjectID() return &DefaultCredentials{ ProjectID: id, TokenSource: ComputeTokenSource("", scopes...), }, nil } // None are found; return helpful error. const url = "https://developers.google.com/accounts/docs/application-default-credentials" return nil, fmt.Errorf("google: could not find default credentials. See %v for more information.", url) }
FindDefaultCredentials searches for "Application Default Credentials". It looks for credentials in the following places, preferring the first location found: 1. A JSON file whose path is specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable. 2. A JSON file in a location known to the gcloud command-line tool. On Windows, this is %APPDATA%/gcloud/application_default_credentials.json. On other systems, $HOME/.config/gcloud/application_default_credentials.json. 3. On Google App Engine standard first generation runtimes (<= Go 1.9) it uses the appengine.AccessToken function. 4. On Google Compute Engine, Google App Engine standard second generation runtimes (>= Go 1.11), and Google App Engine flexible environment, it fetches credentials from the metadata server.
FindDefaultCredentials
go
flynn/flynn
vendor/golang.org/x/oauth2/google/default.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/default.go
BSD-3-Clause
func CredentialsFromJSON(ctx context.Context, jsonData []byte, scopes ...string) (*Credentials, error) { var f credentialsFile if err := json.Unmarshal(jsonData, &f); err != nil { return nil, err } ts, err := f.tokenSource(ctx, append([]string(nil), scopes...)) if err != nil { return nil, err } return &DefaultCredentials{ ProjectID: f.ProjectID, TokenSource: ts, JSON: jsonData, }, nil }
CredentialsFromJSON obtains Google credentials from a JSON value. The JSON can represent either a Google Developers Console client_credentials.json file (as in ConfigFromJSON) or a Google Developers service account key file (as in JWTConfigFromJSON).
CredentialsFromJSON
go
flynn/flynn
vendor/golang.org/x/oauth2/google/default.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/default.go
BSD-3-Clause
func JWTAccessTokenSourceFromJSON(jsonKey []byte, audience string) (oauth2.TokenSource, error) { cfg, err := JWTConfigFromJSON(jsonKey) if err != nil { return nil, fmt.Errorf("google: could not parse JSON key: %v", err) } pk, err := internal.ParseKey(cfg.PrivateKey) if err != nil { return nil, fmt.Errorf("google: could not parse key: %v", err) } ts := &jwtAccessTokenSource{ email: cfg.Email, audience: audience, pk: pk, pkID: cfg.PrivateKeyID, } tok, err := ts.Token() if err != nil { return nil, err } return oauth2.ReuseTokenSource(tok, ts), nil }
JWTAccessTokenSourceFromJSON uses a Google Developers service account JSON key file to read the credentials that authorize and authenticate the requests, and returns a TokenSource that does not use any OAuth2 flow but instead creates a JWT and sends that as the access token. The audience is typically a URL that specifies the scope of the credentials. Note that this is not a standard OAuth flow, but rather an optimization supported by a few Google services. Unless you know otherwise, you should use JWTConfigFromJSON instead.
JWTAccessTokenSourceFromJSON
go
flynn/flynn
vendor/golang.org/x/oauth2/google/jwt.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/jwt.go
BSD-3-Clause
func appEngineTokenSource(ctx context.Context, scope ...string) oauth2.TokenSource { scopes := append([]string{}, scope...) sort.Strings(scopes) return &gaeTokenSource{ ctx: ctx, scopes: scopes, key: strings.Join(scopes, " "), } }
See comment on AppEngineTokenSource in appengine.go.
appEngineTokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/google/appengine_gen1.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/appengine_gen1.go
BSD-3-Clause
func NewSDKConfig(account string) (*SDKConfig, error) { configPath, err := sdkConfigPath() if err != nil { return nil, fmt.Errorf("oauth2/google: error getting SDK config path: %v", err) } credentialsPath := filepath.Join(configPath, "credentials") f, err := os.Open(credentialsPath) if err != nil { return nil, fmt.Errorf("oauth2/google: failed to load SDK credentials: %v", err) } defer f.Close() var c sdkCredentials if err := json.NewDecoder(f).Decode(&c); err != nil { return nil, fmt.Errorf("oauth2/google: failed to decode SDK credentials from %q: %v", credentialsPath, err) } if len(c.Data) == 0 { return nil, fmt.Errorf("oauth2/google: no credentials found in %q, run `gcloud auth login` to create one", credentialsPath) } if account == "" { propertiesPath := filepath.Join(configPath, "properties") f, err := os.Open(propertiesPath) if err != nil { return nil, fmt.Errorf("oauth2/google: failed to load SDK properties: %v", err) } defer f.Close() ini, err := parseINI(f) if err != nil { return nil, fmt.Errorf("oauth2/google: failed to parse SDK properties %q: %v", propertiesPath, err) } core, ok := ini["core"] if !ok { return nil, fmt.Errorf("oauth2/google: failed to find [core] section in %v", ini) } active, ok := core["account"] if !ok { return nil, fmt.Errorf("oauth2/google: failed to find %q attribute in %v", "account", core) } account = active } for _, d := range c.Data { if account == "" || d.Key.Account == account { if d.Credential.AccessToken == "" && d.Credential.RefreshToken == "" { return nil, fmt.Errorf("oauth2/google: no token available for account %q", account) } var expiry time.Time if d.Credential.TokenExpiry != nil { expiry = *d.Credential.TokenExpiry } return &SDKConfig{ conf: oauth2.Config{ ClientID: d.Credential.ClientID, ClientSecret: d.Credential.ClientSecret, Scopes: strings.Split(d.Key.Scope, " "), Endpoint: Endpoint, RedirectURL: "oob", }, initialToken: &oauth2.Token{ AccessToken: d.Credential.AccessToken, RefreshToken: d.Credential.RefreshToken, Expiry: expiry, }, }, nil } } return nil, fmt.Errorf("oauth2/google: no such credentials for account %q", account) }
NewSDKConfig creates an SDKConfig for the given Google Cloud SDK account. If account is empty, the account currently active in Google Cloud SDK properties is used. Google Cloud SDK credentials must be created by running `gcloud auth` before using this function. The Google Cloud SDK is available at https://cloud.google.com/sdk/.
NewSDKConfig
go
flynn/flynn
vendor/golang.org/x/oauth2/google/sdk.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/sdk.go
BSD-3-Clause
func (c *SDKConfig) Client(ctx context.Context) *http.Client { return &http.Client{ Transport: &oauth2.Transport{ Source: c.TokenSource(ctx), }, } }
Client returns an HTTP client using Google Cloud SDK credentials to authorize requests. The token will auto-refresh as necessary. The underlying http.RoundTripper will be obtained using the provided context. The returned client and its Transport should not be modified.
Client
go
flynn/flynn
vendor/golang.org/x/oauth2/google/sdk.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/sdk.go
BSD-3-Clause
func (c *SDKConfig) TokenSource(ctx context.Context) oauth2.TokenSource { return c.conf.TokenSource(ctx, c.initialToken) }
TokenSource returns an oauth2.TokenSource that retrieve tokens from Google Cloud SDK credentials using the provided context. It will returns the current access token stored in the credentials, and refresh it when it expires, but it won't update the credentials with the new access token.
TokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/google/sdk.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/sdk.go
BSD-3-Clause
func (c *SDKConfig) Scopes() []string { return c.conf.Scopes }
Scopes are the OAuth 2.0 scopes the current account is authorized for.
Scopes
go
flynn/flynn
vendor/golang.org/x/oauth2/google/sdk.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/sdk.go
BSD-3-Clause
func ConfigFromJSON(jsonKey []byte, scope ...string) (*oauth2.Config, error) { type cred struct { ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` RedirectURIs []string `json:"redirect_uris"` AuthURI string `json:"auth_uri"` TokenURI string `json:"token_uri"` } var j struct { Web *cred `json:"web"` Installed *cred `json:"installed"` } if err := json.Unmarshal(jsonKey, &j); err != nil { return nil, err } var c *cred switch { case j.Web != nil: c = j.Web case j.Installed != nil: c = j.Installed default: return nil, fmt.Errorf("oauth2/google: no credentials found") } if len(c.RedirectURIs) < 1 { return nil, errors.New("oauth2/google: missing redirect URL in the client_credentials.json") } return &oauth2.Config{ ClientID: c.ClientID, ClientSecret: c.ClientSecret, RedirectURL: c.RedirectURIs[0], Scopes: scope, Endpoint: oauth2.Endpoint{ AuthURL: c.AuthURI, TokenURL: c.TokenURI, }, }, nil }
ConfigFromJSON uses a Google Developers Console client_credentials.json file to construct a config. client_credentials.json can be downloaded from https://console.developers.google.com, under "Credentials". Download the Web application credentials in the JSON format and provide the contents of the file as jsonKey.
ConfigFromJSON
go
flynn/flynn
vendor/golang.org/x/oauth2/google/google.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/google.go
BSD-3-Clause
func JWTConfigFromJSON(jsonKey []byte, scope ...string) (*jwt.Config, error) { var f credentialsFile if err := json.Unmarshal(jsonKey, &f); err != nil { return nil, err } if f.Type != serviceAccountKey { return nil, fmt.Errorf("google: read JWT from JSON credentials: 'type' field is %q (expected %q)", f.Type, serviceAccountKey) } scope = append([]string(nil), scope...) // copy return f.jwtConfig(scope), nil }
JWTConfigFromJSON uses a Google Developers service account JSON key file to read the credentials that authorize and authenticate the requests. Create a service account on "Credentials" for your project at https://console.developers.google.com to download a JSON key file.
JWTConfigFromJSON
go
flynn/flynn
vendor/golang.org/x/oauth2/google/google.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/google.go
BSD-3-Clause
func ComputeTokenSource(account string, scope ...string) oauth2.TokenSource { return oauth2.ReuseTokenSource(nil, computeSource{account: account, scopes: scope}) }
ComputeTokenSource returns a token source that fetches access tokens from Google Compute Engine (GCE)'s metadata server. It's only valid to use this token source if your program is running on a GCE instance. If no account is specified, "default" is used. If no scopes are specified, a set of default scopes are automatically granted. Further information about retrieving access tokens from the GCE metadata server can be found at https://cloud.google.com/compute/docs/authentication.
ComputeTokenSource
go
flynn/flynn
vendor/golang.org/x/oauth2/google/google.go
https://github.com/flynn/flynn/blob/master/vendor/golang.org/x/oauth2/google/google.go
BSD-3-Clause
func Test(t *testing.T) { TestingT(t) }
Hook gocheck up to the "go test" runner
Test
go
flynn/flynn
controller/controller_test.go
https://github.com/flynn/flynn/blob/master/controller/controller_test.go
BSD-3-Clause
func (a *App) Critical() bool { v, ok := a.Meta["flynn-system-critical"] return ok && v == "true" }
Critical apps cannot be completely scaled down by the scheduler
Critical
go
flynn/flynn
controller/types/types.go
https://github.com/flynn/flynn/blob/master/controller/types/types.go
BSD-3-Clause
func (a *App) DeployBatchSize() *int { v, ok := a.Meta["flynn-deploy-batch-size"] if !ok { return nil } if i, err := strconv.Atoi(v); err == nil { return &i } return nil }
DeployBatchSize returns the batch size to use when deploying using the in-batches deployment strategy
DeployBatchSize
go
flynn/flynn
controller/types/types.go
https://github.com/flynn/flynn/blob/master/controller/types/types.go
BSD-3-Clause
func (a *App) SetDeployBatchSize(size int) { if a.Meta == nil { a.Meta = make(map[string]string) } a.Meta["flynn-deploy-batch-size"] = strconv.Itoa(size) }
SetDeployBatchSize sets the batch size to use when deploying using the in-batches deployment strategy
SetDeployBatchSize
go
flynn/flynn
controller/types/types.go
https://github.com/flynn/flynn/blob/master/controller/types/types.go
BSD-3-Clause
func (p Processes) IsScaleDownOf(proc Processes) bool { for typ, count := range p { if count <= -proc[typ] { return true } } return false }
IsScaleDownOf returns whether a diff is the complete scale down of any process types in the given processes
IsScaleDownOf
go
flynn/flynn
controller/scheduler/formation.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/formation.go
BSD-3-Clause
func (f *Formation) RectifyOmni(hostCount int) bool { changed := false for typ, proc := range f.Release.Processes { if proc.Omni && f.Processes != nil && f.Processes[typ] > 0 { count := f.OriginalProcesses[typ] * hostCount if f.Processes[typ] != count { f.Processes[typ] = count changed = true } } } return changed }
RectifyOmni updates the process counts for omni jobs by multiplying them by the host count, returning whether or not any counts have changed
RectifyOmni
go
flynn/flynn
controller/scheduler/formation.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/formation.go
BSD-3-Clause
func (f *Formation) Diff(running Processes) Processes { return Processes(f.Processes).Diff(running) }
Diff returns the diff between the given running processes and what is expected to be running for the formation
Diff
go
flynn/flynn
controller/scheduler/formation.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/formation.go
BSD-3-Clause
func (s *Scheduler) stopSurplusOmniJobs(formation *Formation) { log := s.logger.New("fn", "stopSurplusOmniJobs") for typ, proc := range formation.Release.Processes { if !proc.Omni { continue } // get a list of jobs per host so we can count them and // potentially stop any surplus ones hostJobs := make(map[string][]*Job) for _, job := range s.jobs.WithFormationAndType(formation, typ) { if job.IsRunning() { hostJobs[job.HostID] = append(hostJobs[job.HostID], job) } } // detect surplus jobs per host by comparing the expected count // from the formation with the number of jobs currently running // on that host expected := formation.OriginalProcesses[typ] var surplusJobs []*Job for _, jobs := range hostJobs { if diff := len(jobs) - expected; diff > 0 { // add the most recent jobs which are at the start // of the slice (WithFormationAndType returns them // in reverse chronological order above) surplusJobs = append(surplusJobs, jobs[0:diff]...) } } if len(surplusJobs) == 0 { continue } log.Info(fmt.Sprintf("detected %d surplus omni jobs", len(surplusJobs)), "type", typ) for _, job := range surplusJobs { s.stopJob(job) } } }
stopSurplusOmniJobs stops surplus jobs which are running on a host which has more than the expected number of omni jobs for a given type (this happens for example when both the bootstrapper and scheduler are starting jobs and distribute omni jobs unevenly)
stopSurplusOmniJobs
go
flynn/flynn
controller/scheduler/scheduler.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/scheduler.go
BSD-3-Clause
func (s *Scheduler) stopJobsWithMismatchedTags(formation *Formation) { log := s.logger.New("fn", "stopJobsWithMismatchedTags") for _, job := range s.jobs { if !job.IsInFormation(formation.key()) || !job.IsRunning() { continue } host, ok := s.hosts[job.HostID] if !ok { continue } if job.TagsMatchHost(host) { continue } log.Info("job has mismatched tags, stopping", "job.id", job.ID, "job.tags", job.Tags(), "host.id", host.ID, "host.tags", host.Tags) s.stopJob(job) } }
stopJobsWithMismatchedTags stops any running jobs whose tags do not match those of the host they are running on (possible after either the host's tags or the formation's tags are updated)
stopJobsWithMismatchedTags
go
flynn/flynn
controller/scheduler/scheduler.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/scheduler.go
BSD-3-Clause
func (s *Scheduler) maybeStartBlockedJobs(host *Host) { for _, job := range s.jobs { if job.State == JobStateBlocked && job.TagsMatchHost(host) { job.State = JobStatePending go s.StartJob(job) } } }
maybeStartBlockedJobs starts any jobs which are blocked due to not matching tags of any hosts on the given host, which is expected to be either a new host or a host whose tags have just changed
maybeStartBlockedJobs
go
flynn/flynn
controller/scheduler/scheduler.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/scheduler.go
BSD-3-Clause
func (s *Scheduler) findVolume(job *Job, req *ct.VolumeReq) *Volume { for _, vol := range s.volumes { // skip destroyed or decommissioned volumes if vol.GetState() == ct.VolumeStateDestroyed || vol.DecommissionedAt != nil { continue } // skip if the app, release, type or path do not match if vol.AppID != job.AppID { continue } if vol.ReleaseID != job.ReleaseID { continue } if vol.JobType != job.Type { continue } if vol.Path != req.Path { continue } // skip if the volume is assigned to another job if vol.JobID != nil && *vol.JobID != job.ID { continue } // skip if we have already assigned the job to a host // and this volume doesn't exist on that host if job.HostID != "" && vol.HostID != job.HostID { continue } // return the matching volume return vol } return nil }
findVolume looks for an existing, unassigned volume which matches the given job's app, release and type, and the volume request's path
findVolume
go
flynn/flynn
controller/scheduler/scheduler.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/scheduler.go
BSD-3-Clause
func (s *Scheduler) ControllerPersistLoop() { log := s.logger.New("fn", "ControllerPersistLoop") log.Info("starting controller persistence loop") // jobQueue is a map of job UUID to a slice of jobs to persist for that // given UUID, and the loop below persists the jobs in the slice in // FIFO order jobQueue := make(map[string][]*ct.Job) // jobDone is a channel which receives a UUID once a job has been // persisted for that UUID, thus potentially triggering the // persistence of the next job in the queue for that UUID jobDone := make(chan string) // volQueue is a map of volume ID to a slice of volumes to persist for // that given ID, and the loop below persists the volumes in the slice // in FIFO order volQueue := make(map[string][]*ct.Volume) // volDone is a channel which receives an ID once a volume has been // persisted for that ID, thus potentially triggering the persistence // of the next volume in the queue for that ID volDone := make(chan string) // scaleRequests is a queue of scale requests waiting to be persisted // after the associated job events scaleRequests := make(map[string]*ct.ScaleRequest) // persistJob makes multiple attempts to persist the given job, sending // to the jobDone channel once the attempts have finished persistJob := func(job *ct.Job) { err := controllerPersistAttempts.RunWithValidator(func() error { return s.PutJob(job) }, httphelper.IsRetryableError) if err != nil { log.Error("error persisting job", "job.id", job.ID, "job.state", job.State, "err", err) } jobDone <- job.UUID } // persistVolume makes multiple attempts to persist the given volume, // sending to the volDone channel once the attempts have finished persistVolume := func(vol *ct.Volume) { err := controllerPersistAttempts.RunWithValidator(func() error { return s.PutVolume(vol) }, httphelper.IsRetryableError) if err != nil { s.logger.Error("error persisting volume", "vol.id", vol.ID, "vol.state", vol.State, "err", err) } volDone <- vol.ID } maybePersistScaleRequest := func(req *ct.ScaleRequest) { // if there are any associated jobs being persisted, add to the // scale request queue to be persisted later (to avoid scale // events preceding job events) for _, jobs := range jobQueue { for _, job := range jobs { if job.AppID == req.AppID && job.ReleaseID == req.ReleaseID { scaleRequests[req.ID] = req return } } } go func() { err := controllerPersistAttempts.RunWithValidator(func() error { return s.PutScaleRequest(req) }, httphelper.IsRetryableError) if err != nil { log.Error("error marking scale request as complete", "scale_request.id", req.ID, "app.id", req.AppID, "release.id", req.ReleaseID, "err", err) } }() delete(scaleRequests, req.ID) } // start the persistence loop which receives from s.controllerPersist, // jobDone and volDone, modifies the queues accordingly and then calls // the persist functions if necessary for { select { case v, ok := <-s.controllerPersist: if !ok { log.Info("stopping controller persistence loop") return } switch v := v.(type) { case *ct.Job: // push the job to the back of the queue jobQueue[v.UUID] = append(jobQueue[v.UUID], v) // if there is only one job in the queue, persist it if len(jobQueue[v.UUID]) == 1 { go persistJob(v) } case *ct.Volume: // push the volume to the back of the queue volQueue[v.ID] = append(volQueue[v.ID], v) // if there is only one volume in the queue, persist it if len(volQueue[v.ID]) == 1 { go persistVolume(v) } case *ct.ScaleRequest: maybePersistScaleRequest(v) } case uuid := <-jobDone: // remove the persisted job from the queue jobQueue[uuid] = jobQueue[uuid][1:] // if the queue has more jobs, persist the first one if len(jobQueue[uuid]) > 0 { go persistJob(jobQueue[uuid][0]) } else { delete(jobQueue, uuid) } // try and persist scale requests for _, req := range scaleRequests { maybePersistScaleRequest(req) } case id := <-volDone: // remove the persisted volume from the queue volQueue[id] = volQueue[id][1:] // if the queue has more volumes, persist the first one if len(volQueue[id]) > 0 { go persistVolume(volQueue[id][0]) } else { delete(volQueue, id) } } }
ControllerPersistLoop starts a loop which receives jobs, volumes and scale requests from the s.controllerPersist channel and persists them to the controller using the controllerPersistAttempts retry strategy. A goroutine is started per job, volume and scale request to persist, but care is taken to persist jobs with the same UUID sequentially and in order (to avoid for example a job transitioning from "down" to "up" in the controller) and scale requests after associated jobs (so that scale events are emitted after job events).
ControllerPersistLoop
go
flynn/flynn
controller/scheduler/scheduler.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/scheduler.go
BSD-3-Clause
func (j *Job) Tags() map[string]string { if j.Formation == nil { return nil } return j.Formation.Tags[j.Type] }
Tags returns the tags for the job's process type from the formation
Tags
go
flynn/flynn
controller/scheduler/job.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/job.go
BSD-3-Clause
func (j *Job) TagsMatchHost(host *Host) bool { for k, v := range j.Tags() { if w, ok := host.Tags[k]; !ok || v != w { return false } } return true }
TagsMatchHost checks whether all of the job's tags match the corresponding host's tags
TagsMatchHost
go
flynn/flynn
controller/scheduler/job.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/job.go
BSD-3-Clause
func (j Jobs) WithFormationAndType(f *Formation, typ string) sortJobs { jobs := make(sortJobs, 0, len(j)) for _, job := range j { if job.Formation == f && job.Type == typ { jobs = append(jobs, job) } } jobs.Sort() return jobs }
WithFormationAndType returns a list of jobs which belong to the given formation and have the given type, ordered with the most recently started job first
WithFormationAndType
go
flynn/flynn
controller/scheduler/job.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/job.go
BSD-3-Clause
func (h *Host) StreamJobEventsTo(ch chan *host.Event) (map[string]host.ActiveJob, error) { log := h.logger.New("fn", "StreamJobEventsTo", "host.id", h.ID) var events chan *host.Event var stream stream.Stream connect := func() (err error) { log.Info("connecting job event stream") events = make(chan *host.Event) stream, err = h.client.StreamEvents("all", events) if err != nil { log.Error("error connecting job event stream", "err", err) } return } if err := connect(); err != nil { return nil, err } log.Info("getting active jobs") jobs, err := h.client.ListJobs() if err != nil { log.Error("error getting active jobs", "err", err) return nil, err } log.Info(fmt.Sprintf("got %d active job(s) for host %s", len(jobs), h.ID)) go func() { defer stream.Close() defer close(h.jobsDone) for { eventLoop: for { select { case event, ok := <-events: if !ok { break eventLoop } ch <- event // if the host is a FakeHostClient with TestEventHook // set, send on the channel to synchronize with tests if h, ok := h.client.(*testutils.FakeHostClient); ok && h.TestEventHook != nil { h.TestEventHook <- struct{}{} } case <-h.stop: return } } log.Warn("job event stream disconnected", "err", stream.Err()) // keep trying to reconnect, unless we are told to stop retryLoop: for { select { case <-h.stop: return default: } if err := connect(); err == nil { break retryLoop } time.Sleep(100 * time.Millisecond) } } }() return jobs, nil }
StreamJobEventsTo streams all job events from the host to the given channel in a goroutine, returning the current list of active jobs.
StreamJobEventsTo
go
flynn/flynn
controller/scheduler/host.go
https://github.com/flynn/flynn/blob/master/controller/scheduler/host.go
BSD-3-Clause
func (ReleaseType) EnumDescriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{0} }
Deprecated: Use ReleaseType.Descriptor instead.
EnumDescriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (ScaleRequestState) EnumDescriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{1} }
Deprecated: Use ScaleRequestState.Descriptor instead.
EnumDescriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (DeploymentStatus) EnumDescriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{2} }
Deprecated: Use DeploymentStatus.Descriptor instead.
EnumDescriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (StatusResponse_Code) EnumDescriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{0, 0} }
Deprecated: Use StatusResponse_Code.Descriptor instead.
EnumDescriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (LabelFilter_Expression_Operator) EnumDescriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{1, 0, 0} }
Deprecated: Use LabelFilter_Expression_Operator.Descriptor instead.
EnumDescriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (DeploymentEvent_JobState) EnumDescriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{27, 0} }
Deprecated: Use DeploymentEvent_JobState.Descriptor instead.
EnumDescriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StatusResponse) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{0} }
Deprecated: Use StatusResponse.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*LabelFilter) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{1} }
Deprecated: Use LabelFilter.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamAppsRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{2} }
Deprecated: Use StreamAppsRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamAppsResponse) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{3} }
Deprecated: Use StreamAppsResponse.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamReleasesRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{4} }
Deprecated: Use StreamReleasesRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamReleasesResponse) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{5} }
Deprecated: Use StreamReleasesResponse.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamScalesRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{6} }
Deprecated: Use StreamScalesRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamScalesResponse) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{7} }
Deprecated: Use StreamScalesResponse.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamDeploymentsRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{8} }
Deprecated: Use StreamDeploymentsRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*StreamDeploymentsResponse) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{9} }
Deprecated: Use StreamDeploymentsResponse.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*UpdateAppRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{10} }
Deprecated: Use UpdateAppRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*CreateScaleRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{11} }
Deprecated: Use CreateScaleRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*CreateReleaseRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{12} }
Deprecated: Use CreateReleaseRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*CreateDeploymentRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{13} }
Deprecated: Use CreateDeploymentRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*App) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{14} }
Deprecated: Use App.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*HostHealthCheck) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{15} }
Deprecated: Use HostHealthCheck.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*HostService) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{16} }
Deprecated: Use HostService.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*Port) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{17} }
Deprecated: Use Port.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*VolumeReq) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{18} }
Deprecated: Use VolumeReq.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*HostResourceSpec) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{19} }
Deprecated: Use HostResourceSpec.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*HostMount) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{20} }
Deprecated: Use HostMount.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*LibContainerDevice) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{21} }
Deprecated: Use LibContainerDevice.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*ProcessType) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{22} }
Deprecated: Use ProcessType.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*Release) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{23} }
Deprecated: Use Release.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*ScaleRequest) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{24} }
Deprecated: Use ScaleRequest.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*DeploymentProcessTags) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{25} }
Deprecated: Use DeploymentProcessTags.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*ExpandedDeployment) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{26} }
Deprecated: Use ExpandedDeployment.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*DeploymentEvent) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{27} }
Deprecated: Use DeploymentEvent.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*SignedData) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{28} }
Deprecated: Use SignedData.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*AccessToken) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{29} }
Deprecated: Use AccessToken.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func (*LabelFilter_Expression) Descriptor() ([]byte, []int) { return file_controller_proto_rawDescGZIP(), []int{1, 0} }
Deprecated: Use LabelFilter_Expression.ProtoReflect.Descriptor instead.
Descriptor
go
flynn/flynn
controller/api/controller.pb.go
https://github.com/flynn/flynn/blob/master/controller/api/controller.pb.go
BSD-3-Clause
func verifyASN1(pub *ecdsa.PublicKey, hash, sig []byte) bool { var ( r, s = &big.Int{}, &big.Int{} inner cryptobyte.String ) input := cryptobyte.String(sig) if !input.ReadASN1(&inner, asn1.SEQUENCE) || !input.Empty() || !inner.ReadASN1Integer(r) || !inner.ReadASN1Integer(s) || !inner.Empty() { return false } return ecdsa.Verify(pub, hash, r, s) }
This should be replaced with ecdsa.VerifyASN1 when Go 1.15 is available https://go.googlesource.com/go/+/8c09e8af3633b0c08d2c309e56a58124dfee3d7c
verifyASN1
go
flynn/flynn
controller/authorizer/authorizer.go
https://github.com/flynn/flynn/blob/master/controller/authorizer/authorizer.go
BSD-3-Clause
func (c *context) execWithRetries(query string, args ...interface{}) error { return execAttempts.Run(func() error { return c.db.Exec(query, args...) }) }
Retry db queries in case postgres has been deployed
execWithRetries
go
flynn/flynn
controller/worker/deployment/context.go
https://github.com/flynn/flynn/blob/master/controller/worker/deployment/context.go
BSD-3-Clause
func (d *DeployJob) deployDiscoverdMeta() (err error) { log := d.logger.New("fn", "deployDiscoverdMeta") log.Info("starting discoverd-meta deployment") defer func() { if err != nil { // TODO: support rolling back err = ErrSkipRollback{err.Error()} } }() for typ, count := range d.Processes { proc := d.newRelease.Processes[typ] if proc.Service == "" { if err := d.scaleOneByOne(typ, log); err != nil { return err } continue } discDeploy, err := dd.NewDeployment(proc.Service) if err != nil { return err } if err := discDeploy.Create(d.ID); err != nil { return err } defer discDeploy.Close() for i := 0; i < count; i++ { if err := d.scaleNewFormationUpByOne(typ, log); err != nil { return err } if err := discDeploy.Wait(d.ID, d.timeout, log); err != nil { return err } if err := d.scaleOldFormationDownByOne(typ, log); err != nil { return err } } } return nil }
deployDiscoverMeta does a one-by-one deployment but uses discoverd.Deployment to wait for appropriate service metadata before stopping old jobs.
deployDiscoverdMeta
go
flynn/flynn
controller/worker/deployment/discoverd_meta.go
https://github.com/flynn/flynn/blob/master/controller/worker/deployment/discoverd_meta.go
BSD-3-Clause