repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
remind101/empire
|
releases.go
|
Release
|
func (s *releasesService) Release(ctx context.Context, release *Release, ss twelvefactor.StatusStream) error {
a, err := newSchedulerApp(release)
if err != nil {
return err
}
return s.Scheduler.Submit(ctx, a, ss)
}
|
go
|
func (s *releasesService) Release(ctx context.Context, release *Release, ss twelvefactor.StatusStream) error {
a, err := newSchedulerApp(release)
if err != nil {
return err
}
return s.Scheduler.Submit(ctx, a, ss)
}
|
[
"func",
"(",
"s",
"*",
"releasesService",
")",
"Release",
"(",
"ctx",
"context",
".",
"Context",
",",
"release",
"*",
"Release",
",",
"ss",
"twelvefactor",
".",
"StatusStream",
")",
"error",
"{",
"a",
",",
"err",
":=",
"newSchedulerApp",
"(",
"release",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"Scheduler",
".",
"Submit",
"(",
"ctx",
",",
"a",
",",
"ss",
")",
"\n",
"}"
] |
// Release submits a release to the scheduler.
|
[
"Release",
"submits",
"a",
"release",
"to",
"the",
"scheduler",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L163-L169
|
train
|
remind101/empire
|
releases.go
|
Restart
|
func (s *releasesService) Restart(ctx context.Context, db *gorm.DB, app *App) error {
return s.Scheduler.Restart(ctx, app.ID, nil)
}
|
go
|
func (s *releasesService) Restart(ctx context.Context, db *gorm.DB, app *App) error {
return s.Scheduler.Restart(ctx, app.ID, nil)
}
|
[
"func",
"(",
"s",
"*",
"releasesService",
")",
"Restart",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"error",
"{",
"return",
"s",
".",
"Scheduler",
".",
"Restart",
"(",
"ctx",
",",
"app",
".",
"ID",
",",
"nil",
")",
"\n",
"}"
] |
// Restart will find the last release for an app and submit it to the scheduler
// to restart the app.
|
[
"Restart",
"will",
"find",
"the",
"last",
"release",
"for",
"an",
"app",
"and",
"submit",
"it",
"to",
"the",
"scheduler",
"to",
"restart",
"the",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L190-L192
|
train
|
remind101/empire
|
releases.go
|
releasesFind
|
func releasesFind(db *gorm.DB, scope scope) (*Release, error) {
var release Release
scope = composedScope{releasesPreload, scope}
if err := first(db, scope, &release); err != nil {
return &release, err
}
return &release, nil
}
|
go
|
func releasesFind(db *gorm.DB, scope scope) (*Release, error) {
var release Release
scope = composedScope{releasesPreload, scope}
if err := first(db, scope, &release); err != nil {
return &release, err
}
return &release, nil
}
|
[
"func",
"releasesFind",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"var",
"release",
"Release",
"\n\n",
"scope",
"=",
"composedScope",
"{",
"releasesPreload",
",",
"scope",
"}",
"\n",
"if",
"err",
":=",
"first",
"(",
"db",
",",
"scope",
",",
"&",
"release",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"&",
"release",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"release",
",",
"nil",
"\n",
"}"
] |
// releasesFind returns the first matching release.
|
[
"releasesFind",
"returns",
"the",
"first",
"matching",
"release",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L198-L207
|
train
|
remind101/empire
|
releases.go
|
releases
|
func releases(db *gorm.DB, scope scope) ([]*Release, error) {
var releases []*Release
scope = composedScope{releasesPreload, scope}
return releases, find(db, scope, &releases)
}
|
go
|
func releases(db *gorm.DB, scope scope) ([]*Release, error) {
var releases []*Release
scope = composedScope{releasesPreload, scope}
return releases, find(db, scope, &releases)
}
|
[
"func",
"releases",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"[",
"]",
"*",
"Release",
",",
"error",
")",
"{",
"var",
"releases",
"[",
"]",
"*",
"Release",
"\n",
"scope",
"=",
"composedScope",
"{",
"releasesPreload",
",",
"scope",
"}",
"\n",
"return",
"releases",
",",
"find",
"(",
"db",
",",
"scope",
",",
"&",
"releases",
")",
"\n",
"}"
] |
// releases returns all releases matching the scope.
|
[
"releases",
"returns",
"all",
"releases",
"matching",
"the",
"scope",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L210-L214
|
train
|
remind101/empire
|
releases.go
|
currentFormation
|
func currentFormation(db *gorm.DB, app *App) (Formation, error) {
// Get the current release
current, err := releasesFind(db, ReleasesQuery{App: app})
if err != nil {
return nil, err
}
f := current.Formation
return f, nil
}
|
go
|
func currentFormation(db *gorm.DB, app *App) (Formation, error) {
// Get the current release
current, err := releasesFind(db, ReleasesQuery{App: app})
if err != nil {
return nil, err
}
f := current.Formation
return f, nil
}
|
[
"func",
"currentFormation",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"(",
"Formation",
",",
"error",
")",
"{",
"// Get the current release",
"current",
",",
"err",
":=",
"releasesFind",
"(",
"db",
",",
"ReleasesQuery",
"{",
"App",
":",
"app",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"f",
":=",
"current",
".",
"Formation",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] |
// currentFormations gets the current formations for an app
|
[
"currentFormations",
"gets",
"the",
"current",
"formations",
"for",
"an",
"app"
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L243-L251
|
train
|
remind101/empire
|
releases.go
|
releasesLastVersion
|
func releasesLastVersion(db *gorm.DB, appID string) (int, error) {
var version int
rows, err := db.Raw(`select version from releases where app_id = ? order by version desc`, appID).Rows()
if err != nil {
return version, err
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&version)
return version, err
}
return version, nil
}
|
go
|
func releasesLastVersion(db *gorm.DB, appID string) (int, error) {
var version int
rows, err := db.Raw(`select version from releases where app_id = ? order by version desc`, appID).Rows()
if err != nil {
return version, err
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&version)
return version, err
}
return version, nil
}
|
[
"func",
"releasesLastVersion",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"appID",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"version",
"int",
"\n\n",
"rows",
",",
"err",
":=",
"db",
".",
"Raw",
"(",
"`select version from releases where app_id = ? order by version desc`",
",",
"appID",
")",
".",
"Rows",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"version",
",",
"err",
"\n",
"}",
"\n",
"defer",
"rows",
".",
"Close",
"(",
")",
"\n\n",
"for",
"rows",
".",
"Next",
"(",
")",
"{",
"err",
":=",
"rows",
".",
"Scan",
"(",
"&",
"version",
")",
"\n",
"return",
"version",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"version",
",",
"nil",
"\n",
"}"
] |
// ReleasesLastVersion returns the last ReleaseVersion for the given App.
|
[
"ReleasesLastVersion",
"returns",
"the",
"last",
"ReleaseVersion",
"for",
"the",
"given",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L254-L269
|
train
|
remind101/empire
|
releases.go
|
releasesCreate
|
func releasesCreate(db *gorm.DB, release *Release) (*Release, error) {
// Get the last release version for this app.
v, err := releasesLastVersion(db, release.App.ID)
if err != nil {
return release, err
}
// Increment the release version.
release.Version = v + 1
if err := db.Create(release).Error; err != nil {
return release, err
}
return release, nil
}
|
go
|
func releasesCreate(db *gorm.DB, release *Release) (*Release, error) {
// Get the last release version for this app.
v, err := releasesLastVersion(db, release.App.ID)
if err != nil {
return release, err
}
// Increment the release version.
release.Version = v + 1
if err := db.Create(release).Error; err != nil {
return release, err
}
return release, nil
}
|
[
"func",
"releasesCreate",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"release",
"*",
"Release",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"// Get the last release version for this app.",
"v",
",",
"err",
":=",
"releasesLastVersion",
"(",
"db",
",",
"release",
".",
"App",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"release",
",",
"err",
"\n",
"}",
"\n\n",
"// Increment the release version.",
"release",
".",
"Version",
"=",
"v",
"+",
"1",
"\n\n",
"if",
"err",
":=",
"db",
".",
"Create",
"(",
"release",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"release",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"release",
",",
"nil",
"\n",
"}"
] |
// releasesCreate creates a new Release and inserts it into the database.
|
[
"releasesCreate",
"creates",
"a",
"new",
"Release",
"and",
"inserts",
"it",
"into",
"the",
"database",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L272-L287
|
train
|
remind101/empire
|
releases.go
|
standardWebExposure
|
func standardWebExposure(app *App) *twelvefactor.Exposure {
ports := []twelvefactor.Port{
{
Container: 8080,
Host: 80,
Protocol: &twelvefactor.HTTP{},
},
}
// If a certificate is attached to the "web" process, add an SSL port.
if cert, ok := app.Certs[webProcessType]; ok {
ports = append(ports, twelvefactor.Port{
Container: 8080,
Host: 443,
Protocol: &twelvefactor.HTTPS{
Cert: cert,
},
})
}
return &twelvefactor.Exposure{
External: app.Exposure == exposePublic,
Ports: ports,
}
}
|
go
|
func standardWebExposure(app *App) *twelvefactor.Exposure {
ports := []twelvefactor.Port{
{
Container: 8080,
Host: 80,
Protocol: &twelvefactor.HTTP{},
},
}
// If a certificate is attached to the "web" process, add an SSL port.
if cert, ok := app.Certs[webProcessType]; ok {
ports = append(ports, twelvefactor.Port{
Container: 8080,
Host: 443,
Protocol: &twelvefactor.HTTPS{
Cert: cert,
},
})
}
return &twelvefactor.Exposure{
External: app.Exposure == exposePublic,
Ports: ports,
}
}
|
[
"func",
"standardWebExposure",
"(",
"app",
"*",
"App",
")",
"*",
"twelvefactor",
".",
"Exposure",
"{",
"ports",
":=",
"[",
"]",
"twelvefactor",
".",
"Port",
"{",
"{",
"Container",
":",
"8080",
",",
"Host",
":",
"80",
",",
"Protocol",
":",
"&",
"twelvefactor",
".",
"HTTP",
"{",
"}",
",",
"}",
",",
"}",
"\n\n",
"// If a certificate is attached to the \"web\" process, add an SSL port.",
"if",
"cert",
",",
"ok",
":=",
"app",
".",
"Certs",
"[",
"webProcessType",
"]",
";",
"ok",
"{",
"ports",
"=",
"append",
"(",
"ports",
",",
"twelvefactor",
".",
"Port",
"{",
"Container",
":",
"8080",
",",
"Host",
":",
"443",
",",
"Protocol",
":",
"&",
"twelvefactor",
".",
"HTTPS",
"{",
"Cert",
":",
"cert",
",",
"}",
",",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"twelvefactor",
".",
"Exposure",
"{",
"External",
":",
"app",
".",
"Exposure",
"==",
"exposePublic",
",",
"Ports",
":",
"ports",
",",
"}",
"\n",
"}"
] |
// standardWebExposure generates a scheduler.Exposure for a web process in the
// standard Procfile format.
|
[
"standardWebExposure",
"generates",
"a",
"scheduler",
".",
"Exposure",
"for",
"a",
"web",
"process",
"in",
"the",
"standard",
"Procfile",
"format",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/releases.go#L398-L422
|
train
|
remind101/empire
|
internal/saml/identity_provider.go
|
ServeHTTP
|
func (idp *IdentityProvider) ServeHTTP(w http.ResponseWriter, r *http.Request) {
metadataURL, err := url.Parse(idp.MetadataURL)
if err != nil {
panic(err)
}
ssoURL, err := url.Parse(idp.SSOURL)
if err != nil {
panic(err)
}
switch r.URL.Path {
case metadataURL.Path:
idp.ServeMetadata(w, r)
case ssoURL.Path:
idp.ServeSSO(w, r)
default:
http.NotFound(w, r)
}
}
|
go
|
func (idp *IdentityProvider) ServeHTTP(w http.ResponseWriter, r *http.Request) {
metadataURL, err := url.Parse(idp.MetadataURL)
if err != nil {
panic(err)
}
ssoURL, err := url.Parse(idp.SSOURL)
if err != nil {
panic(err)
}
switch r.URL.Path {
case metadataURL.Path:
idp.ServeMetadata(w, r)
case ssoURL.Path:
idp.ServeSSO(w, r)
default:
http.NotFound(w, r)
}
}
|
[
"func",
"(",
"idp",
"*",
"IdentityProvider",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"metadataURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"idp",
".",
"MetadataURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"ssoURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"idp",
".",
"SSOURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"switch",
"r",
".",
"URL",
".",
"Path",
"{",
"case",
"metadataURL",
".",
"Path",
":",
"idp",
".",
"ServeMetadata",
"(",
"w",
",",
"r",
")",
"\n",
"case",
"ssoURL",
".",
"Path",
":",
"idp",
".",
"ServeSSO",
"(",
"w",
",",
"r",
")",
"\n",
"default",
":",
"http",
".",
"NotFound",
"(",
"w",
",",
"r",
")",
"\n",
"}",
"\n",
"}"
] |
// ServeHTTP implements the http.Handler interface to serve the IDP metadata and
// SSO.
|
[
"ServeHTTP",
"implements",
"the",
"http",
".",
"Handler",
"interface",
"to",
"serve",
"the",
"IDP",
"metadata",
"and",
"SSO",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/identity_provider.go#L131-L149
|
train
|
remind101/empire
|
internal/saml/identity_provider.go
|
ServeMetadata
|
func (idp *IdentityProvider) ServeMetadata(w http.ResponseWriter, r *http.Request) {
buf, _ := xml.MarshalIndent(idp.Metadata(), "", " ")
w.Header().Set("Content-Type", "application/samlmetadata+xml")
w.Write(buf)
}
|
go
|
func (idp *IdentityProvider) ServeMetadata(w http.ResponseWriter, r *http.Request) {
buf, _ := xml.MarshalIndent(idp.Metadata(), "", " ")
w.Header().Set("Content-Type", "application/samlmetadata+xml")
w.Write(buf)
}
|
[
"func",
"(",
"idp",
"*",
"IdentityProvider",
")",
"ServeMetadata",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"buf",
",",
"_",
":=",
"xml",
".",
"MarshalIndent",
"(",
"idp",
".",
"Metadata",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"Write",
"(",
"buf",
")",
"\n",
"}"
] |
// ServeMetadata is an http.HandlerFunc that serves the IDP metadata
|
[
"ServeMetadata",
"is",
"an",
"http",
".",
"HandlerFunc",
"that",
"serves",
"the",
"IDP",
"metadata"
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/identity_provider.go#L152-L156
|
train
|
remind101/empire
|
internal/saml/identity_provider.go
|
ServeSSO
|
func (idp *IdentityProvider) ServeSSO(w http.ResponseWriter, r *http.Request) {
req, err := NewIdpAuthnRequest(idp, r)
if err != nil {
log.Printf("failed to parse request: %s", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
if err := req.Validate(); err != nil {
log.Printf("failed to validate request: %s", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
// TODO(ross): we must check that the request ID has not been previously
// issued.
session := idp.SessionProvider.GetSession(w, r, req)
if session == nil {
return
}
// we have a valid session and must make a SAML assertion
if err := req.MakeAssertion(session); err != nil {
log.Printf("failed to make assertion: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err := req.WriteResponse(w); err != nil {
log.Printf("failed to write response: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}
|
go
|
func (idp *IdentityProvider) ServeSSO(w http.ResponseWriter, r *http.Request) {
req, err := NewIdpAuthnRequest(idp, r)
if err != nil {
log.Printf("failed to parse request: %s", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
if err := req.Validate(); err != nil {
log.Printf("failed to validate request: %s", err)
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
// TODO(ross): we must check that the request ID has not been previously
// issued.
session := idp.SessionProvider.GetSession(w, r, req)
if session == nil {
return
}
// we have a valid session and must make a SAML assertion
if err := req.MakeAssertion(session); err != nil {
log.Printf("failed to make assertion: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err := req.WriteResponse(w); err != nil {
log.Printf("failed to write response: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}
|
[
"func",
"(",
"idp",
"*",
"IdentityProvider",
")",
"ServeSSO",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"req",
",",
"err",
":=",
"NewIdpAuthnRequest",
"(",
"idp",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusBadRequest",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"req",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusBadRequest",
")",
",",
"http",
".",
"StatusBadRequest",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// TODO(ross): we must check that the request ID has not been previously",
"// issued.",
"session",
":=",
"idp",
".",
"SessionProvider",
".",
"GetSession",
"(",
"w",
",",
"r",
",",
"req",
")",
"\n",
"if",
"session",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"// we have a valid session and must make a SAML assertion",
"if",
"err",
":=",
"req",
".",
"MakeAssertion",
"(",
"session",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
":=",
"req",
".",
"WriteResponse",
"(",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"http",
".",
"StatusText",
"(",
"http",
".",
"StatusInternalServerError",
")",
",",
"http",
".",
"StatusInternalServerError",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"
] |
// ServeSSO handles SAML auth requests.
//
// When it gets a request for a user that does not have a valid session,
// then it prompts the user via XXX.
//
// If the session already exists, then it produces a SAML assertion and
// returns an HTTP response according to the specified binding. The
// only supported binding right now is the HTTP-POST binding which returns
// an HTML form in the appropriate format with Javascript to automatically
// submit that form the to service provider's Assertion Customer Service
// endpoint.
//
// If the SAML request is invalid or cannot be verified a simple StatusBadRequest
// response is sent.
//
// If the assertion cannot be created or returned, a StatusInternalServerError
// response is sent.
|
[
"ServeSSO",
"handles",
"SAML",
"auth",
"requests",
".",
"When",
"it",
"gets",
"a",
"request",
"for",
"a",
"user",
"that",
"does",
"not",
"have",
"a",
"valid",
"session",
"then",
"it",
"prompts",
"the",
"user",
"via",
"XXX",
".",
"If",
"the",
"session",
"already",
"exists",
"then",
"it",
"produces",
"a",
"SAML",
"assertion",
"and",
"returns",
"an",
"HTTP",
"response",
"according",
"to",
"the",
"specified",
"binding",
".",
"The",
"only",
"supported",
"binding",
"right",
"now",
"is",
"the",
"HTTP",
"-",
"POST",
"binding",
"which",
"returns",
"an",
"HTML",
"form",
"in",
"the",
"appropriate",
"format",
"with",
"Javascript",
"to",
"automatically",
"submit",
"that",
"form",
"the",
"to",
"service",
"provider",
"s",
"Assertion",
"Customer",
"Service",
"endpoint",
".",
"If",
"the",
"SAML",
"request",
"is",
"invalid",
"or",
"cannot",
"be",
"verified",
"a",
"simple",
"StatusBadRequest",
"response",
"is",
"sent",
".",
"If",
"the",
"assertion",
"cannot",
"be",
"created",
"or",
"returned",
"a",
"StatusInternalServerError",
"response",
"is",
"sent",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/identity_provider.go#L175-L208
|
train
|
remind101/empire
|
internal/saml/identity_provider.go
|
NewIdpAuthnRequest
|
func NewIdpAuthnRequest(idp *IdentityProvider, r *http.Request) (*IdpAuthnRequest, error) {
req := &IdpAuthnRequest{
IDP: idp,
HTTPRequest: r,
}
switch r.Method {
case "GET":
compressedRequest, err := base64.StdEncoding.DecodeString(r.URL.Query().Get("SAMLRequest"))
if err != nil {
return nil, fmt.Errorf("cannot decode request: %s", err)
}
req.RequestBuffer, err = ioutil.ReadAll(flate.NewReader(bytes.NewReader(compressedRequest)))
if err != nil {
return nil, fmt.Errorf("cannot decompress request: %s", err)
}
req.RelayState = r.URL.Query().Get("RelayState")
case "POST":
if err := r.ParseForm(); err != nil {
return nil, err
}
var err error
req.RequestBuffer, err = base64.StdEncoding.DecodeString(r.PostForm.Get("SAMLRequest"))
if err != nil {
return nil, err
}
req.RelayState = r.PostForm.Get("RelayState")
default:
return nil, fmt.Errorf("method not allowed")
}
return req, nil
}
|
go
|
func NewIdpAuthnRequest(idp *IdentityProvider, r *http.Request) (*IdpAuthnRequest, error) {
req := &IdpAuthnRequest{
IDP: idp,
HTTPRequest: r,
}
switch r.Method {
case "GET":
compressedRequest, err := base64.StdEncoding.DecodeString(r.URL.Query().Get("SAMLRequest"))
if err != nil {
return nil, fmt.Errorf("cannot decode request: %s", err)
}
req.RequestBuffer, err = ioutil.ReadAll(flate.NewReader(bytes.NewReader(compressedRequest)))
if err != nil {
return nil, fmt.Errorf("cannot decompress request: %s", err)
}
req.RelayState = r.URL.Query().Get("RelayState")
case "POST":
if err := r.ParseForm(); err != nil {
return nil, err
}
var err error
req.RequestBuffer, err = base64.StdEncoding.DecodeString(r.PostForm.Get("SAMLRequest"))
if err != nil {
return nil, err
}
req.RelayState = r.PostForm.Get("RelayState")
default:
return nil, fmt.Errorf("method not allowed")
}
return req, nil
}
|
[
"func",
"NewIdpAuthnRequest",
"(",
"idp",
"*",
"IdentityProvider",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"IdpAuthnRequest",
",",
"error",
")",
"{",
"req",
":=",
"&",
"IdpAuthnRequest",
"{",
"IDP",
":",
"idp",
",",
"HTTPRequest",
":",
"r",
",",
"}",
"\n\n",
"switch",
"r",
".",
"Method",
"{",
"case",
"\"",
"\"",
":",
"compressedRequest",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
".",
"RequestBuffer",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"flate",
".",
"NewReader",
"(",
"bytes",
".",
"NewReader",
"(",
"compressedRequest",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
".",
"RelayState",
"=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"case",
"\"",
"\"",
":",
"if",
"err",
":=",
"r",
".",
"ParseForm",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"err",
"error",
"\n",
"req",
".",
"RequestBuffer",
",",
"err",
"=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"r",
".",
"PostForm",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"req",
".",
"RelayState",
"=",
"r",
".",
"PostForm",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"req",
",",
"nil",
"\n",
"}"
] |
// NewIdpAuthnRequest returns a new IdpAuthnRequest for the given HTTP request to the authorization
// service.
|
[
"NewIdpAuthnRequest",
"returns",
"a",
"new",
"IdpAuthnRequest",
"for",
"the",
"given",
"HTTP",
"request",
"to",
"the",
"authorization",
"service",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/identity_provider.go#L266-L297
|
train
|
remind101/empire
|
internal/saml/identity_provider.go
|
MarshalAssertion
|
func (req *IdpAuthnRequest) MarshalAssertion() error {
buf, err := xml.Marshal(req.Assertion)
if err != nil {
return err
}
buf, err = xmlsec.Sign([]byte(req.IDP.Key),
buf, xmlsec.SignatureOptions{})
if err != nil {
return err
}
buf, err = xmlsec.Encrypt(getSPEncryptionCert(req.ServiceProviderMetadata),
buf, xmlsec.EncryptOptions{})
if err != nil {
return err
}
req.AssertionBuffer = buf
return nil
}
|
go
|
func (req *IdpAuthnRequest) MarshalAssertion() error {
buf, err := xml.Marshal(req.Assertion)
if err != nil {
return err
}
buf, err = xmlsec.Sign([]byte(req.IDP.Key),
buf, xmlsec.SignatureOptions{})
if err != nil {
return err
}
buf, err = xmlsec.Encrypt(getSPEncryptionCert(req.ServiceProviderMetadata),
buf, xmlsec.EncryptOptions{})
if err != nil {
return err
}
req.AssertionBuffer = buf
return nil
}
|
[
"func",
"(",
"req",
"*",
"IdpAuthnRequest",
")",
"MarshalAssertion",
"(",
")",
"error",
"{",
"buf",
",",
"err",
":=",
"xml",
".",
"Marshal",
"(",
"req",
".",
"Assertion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
"=",
"xmlsec",
".",
"Sign",
"(",
"[",
"]",
"byte",
"(",
"req",
".",
"IDP",
".",
"Key",
")",
",",
"buf",
",",
"xmlsec",
".",
"SignatureOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
"=",
"xmlsec",
".",
"Encrypt",
"(",
"getSPEncryptionCert",
"(",
"req",
".",
"ServiceProviderMetadata",
")",
",",
"buf",
",",
"xmlsec",
".",
"EncryptOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"AssertionBuffer",
"=",
"buf",
"\n",
"return",
"nil",
"\n",
"}"
] |
// MarshalAssertion sets `AssertionBuffer` to a signed, encrypted
// version of `Assertion`.
|
[
"MarshalAssertion",
"sets",
"AssertionBuffer",
"to",
"a",
"signed",
"encrypted",
"version",
"of",
"Assertion",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/identity_provider.go#L480-L500
|
train
|
remind101/empire
|
pkg/troposphere/functions.go
|
Ref
|
func Ref(ref interface{}) interface{} {
switch v := ref.(type) {
case NamedResource:
ref = v.Name
}
return map[string]interface{}{"Ref": ref}
}
|
go
|
func Ref(ref interface{}) interface{} {
switch v := ref.(type) {
case NamedResource:
ref = v.Name
}
return map[string]interface{}{"Ref": ref}
}
|
[
"func",
"Ref",
"(",
"ref",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"switch",
"v",
":=",
"ref",
".",
"(",
"type",
")",
"{",
"case",
"NamedResource",
":",
"ref",
"=",
"v",
".",
"Name",
"\n",
"}",
"\n",
"return",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"ref",
"}",
"\n",
"}"
] |
// Ref provides a helper for the Ref function.
|
[
"Ref",
"provides",
"a",
"helper",
"for",
"the",
"Ref",
"function",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/troposphere/functions.go#L4-L10
|
train
|
remind101/empire
|
pkg/troposphere/functions.go
|
GetAtt
|
func GetAtt(ref, attr interface{}) interface{} {
switch v := ref.(type) {
case NamedResource:
ref = v.Name
}
return map[string][]interface{}{"Fn::GetAtt": []interface{}{ref, attr}}
}
|
go
|
func GetAtt(ref, attr interface{}) interface{} {
switch v := ref.(type) {
case NamedResource:
ref = v.Name
}
return map[string][]interface{}{"Fn::GetAtt": []interface{}{ref, attr}}
}
|
[
"func",
"GetAtt",
"(",
"ref",
",",
"attr",
"interface",
"{",
"}",
")",
"interface",
"{",
"}",
"{",
"switch",
"v",
":=",
"ref",
".",
"(",
"type",
")",
"{",
"case",
"NamedResource",
":",
"ref",
"=",
"v",
".",
"Name",
"\n",
"}",
"\n",
"return",
"map",
"[",
"string",
"]",
"[",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"[",
"]",
"interface",
"{",
"}",
"{",
"ref",
",",
"attr",
"}",
"}",
"\n",
"}"
] |
// GetAtt provides a helper for the GetAtt function.
|
[
"GetAtt",
"provides",
"a",
"helper",
"for",
"the",
"GetAtt",
"function",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/troposphere/functions.go#L13-L19
|
train
|
remind101/empire
|
pkg/heroku/log_drain.go
|
LogDrainCreate
|
func (c *Client) LogDrainCreate(appIdentity string, url string) (*LogDrain, error) {
params := struct {
URL string `json:"url"`
}{
URL: url,
}
var logDrainRes LogDrain
return &logDrainRes, c.Post(&logDrainRes, "/apps/"+appIdentity+"/log-drains", params)
}
|
go
|
func (c *Client) LogDrainCreate(appIdentity string, url string) (*LogDrain, error) {
params := struct {
URL string `json:"url"`
}{
URL: url,
}
var logDrainRes LogDrain
return &logDrainRes, c.Post(&logDrainRes, "/apps/"+appIdentity+"/log-drains", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LogDrainCreate",
"(",
"appIdentity",
"string",
",",
"url",
"string",
")",
"(",
"*",
"LogDrain",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"URL",
"string",
"`json:\"url\"`",
"\n",
"}",
"{",
"URL",
":",
"url",
",",
"}",
"\n",
"var",
"logDrainRes",
"LogDrain",
"\n",
"return",
"&",
"logDrainRes",
",",
"c",
".",
"Post",
"(",
"&",
"logDrainRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new log drain.
//
// appIdentity is the unique identifier of the LogDrain's App. url is the url
// associated with the log drain.
|
[
"Create",
"a",
"new",
"log",
"drain",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogDrain",
"s",
"App",
".",
"url",
"is",
"the",
"url",
"associated",
"with",
"the",
"log",
"drain",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/log_drain.go#L42-L50
|
train
|
remind101/empire
|
pkg/heroku/log_drain.go
|
LogDrainDelete
|
func (c *Client) LogDrainDelete(appIdentity string, logDrainIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/log-drains/" + logDrainIdentity)
}
|
go
|
func (c *Client) LogDrainDelete(appIdentity string, logDrainIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/log-drains/" + logDrainIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LogDrainDelete",
"(",
"appIdentity",
"string",
",",
"logDrainIdentity",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Delete",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"logDrainIdentity",
")",
"\n",
"}"
] |
// Delete an existing log drain. Log drains added by add-ons can only be removed
// by removing the add-on.
//
// appIdentity is the unique identifier of the LogDrain's App. logDrainIdentity
// is the unique identifier of the LogDrain.
|
[
"Delete",
"an",
"existing",
"log",
"drain",
".",
"Log",
"drains",
"added",
"by",
"add",
"-",
"ons",
"can",
"only",
"be",
"removed",
"by",
"removing",
"the",
"add",
"-",
"on",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogDrain",
"s",
"App",
".",
"logDrainIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogDrain",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/log_drain.go#L57-L59
|
train
|
remind101/empire
|
pkg/heroku/log_drain.go
|
LogDrainInfo
|
func (c *Client) LogDrainInfo(appIdentity string, logDrainIdentity string) (*LogDrain, error) {
var logDrain LogDrain
return &logDrain, c.Get(&logDrain, "/apps/"+appIdentity+"/log-drains/"+logDrainIdentity)
}
|
go
|
func (c *Client) LogDrainInfo(appIdentity string, logDrainIdentity string) (*LogDrain, error) {
var logDrain LogDrain
return &logDrain, c.Get(&logDrain, "/apps/"+appIdentity+"/log-drains/"+logDrainIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LogDrainInfo",
"(",
"appIdentity",
"string",
",",
"logDrainIdentity",
"string",
")",
"(",
"*",
"LogDrain",
",",
"error",
")",
"{",
"var",
"logDrain",
"LogDrain",
"\n",
"return",
"&",
"logDrain",
",",
"c",
".",
"Get",
"(",
"&",
"logDrain",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"logDrainIdentity",
")",
"\n",
"}"
] |
// Info for existing log drain.
//
// appIdentity is the unique identifier of the LogDrain's App. logDrainIdentity
// is the unique identifier of the LogDrain.
|
[
"Info",
"for",
"existing",
"log",
"drain",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogDrain",
"s",
"App",
".",
"logDrainIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogDrain",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/log_drain.go#L65-L68
|
train
|
remind101/empire
|
pkg/heroku/log_drain.go
|
LogDrainList
|
func (c *Client) LogDrainList(appIdentity string, lr *ListRange) ([]LogDrain, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/log-drains", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var logDrainsRes []LogDrain
return logDrainsRes, c.DoReq(req, &logDrainsRes)
}
|
go
|
func (c *Client) LogDrainList(appIdentity string, lr *ListRange) ([]LogDrain, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/log-drains", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var logDrainsRes []LogDrain
return logDrainsRes, c.DoReq(req, &logDrainsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LogDrainList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"LogDrain",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"logDrainsRes",
"[",
"]",
"LogDrain",
"\n",
"return",
"logDrainsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"logDrainsRes",
")",
"\n",
"}"
] |
// List existing log drains.
//
// appIdentity is the unique identifier of the LogDrain's App. lr is an optional
// ListRange that sets the Range options for the paginated list of results.
|
[
"List",
"existing",
"log",
"drains",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogDrain",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/log_drain.go#L74-L86
|
train
|
remind101/empire
|
pkg/heroku/region.go
|
RegionInfo
|
func (c *Client) RegionInfo(regionIdentity string) (*Region, error) {
var region Region
return ®ion, c.Get(®ion, "/regions/"+regionIdentity)
}
|
go
|
func (c *Client) RegionInfo(regionIdentity string) (*Region, error) {
var region Region
return ®ion, c.Get(®ion, "/regions/"+regionIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RegionInfo",
"(",
"regionIdentity",
"string",
")",
"(",
"*",
"Region",
",",
"error",
")",
"{",
"var",
"region",
"Region",
"\n",
"return",
"&",
"region",
",",
"c",
".",
"Get",
"(",
"&",
"region",
",",
"\"",
"\"",
"+",
"regionIdentity",
")",
"\n",
"}"
] |
// Info for existing region.
//
// regionIdentity is the unique identifier of the Region.
|
[
"Info",
"for",
"existing",
"region",
".",
"regionIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Region",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/region.go#L32-L35
|
train
|
remind101/empire
|
pkg/heroku/region.go
|
RegionList
|
func (c *Client) RegionList(lr *ListRange) ([]Region, error) {
req, err := c.NewRequest("GET", "/regions", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var regionsRes []Region
return regionsRes, c.DoReq(req, ®ionsRes)
}
|
go
|
func (c *Client) RegionList(lr *ListRange) ([]Region, error) {
req, err := c.NewRequest("GET", "/regions", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var regionsRes []Region
return regionsRes, c.DoReq(req, ®ionsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"RegionList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Region",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"regionsRes",
"[",
"]",
"Region",
"\n",
"return",
"regionsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"regionsRes",
")",
"\n",
"}"
] |
// List existing regions.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results.
|
[
"List",
"existing",
"regions",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/region.go#L41-L53
|
train
|
remind101/empire
|
server/auth/cache.go
|
CacheAuthorization
|
func CacheAuthorization(a Authorizer, expiration time.Duration) Authorizer {
cache := cache.New(expiration, 30*time.Second)
return &cachedAuthorizer{
Authorizer: a,
cache: cache,
}
}
|
go
|
func CacheAuthorization(a Authorizer, expiration time.Duration) Authorizer {
cache := cache.New(expiration, 30*time.Second)
return &cachedAuthorizer{
Authorizer: a,
cache: cache,
}
}
|
[
"func",
"CacheAuthorization",
"(",
"a",
"Authorizer",
",",
"expiration",
"time",
".",
"Duration",
")",
"Authorizer",
"{",
"cache",
":=",
"cache",
".",
"New",
"(",
"expiration",
",",
"30",
"*",
"time",
".",
"Second",
")",
"\n\n",
"return",
"&",
"cachedAuthorizer",
"{",
"Authorizer",
":",
"a",
",",
"cache",
":",
"cache",
",",
"}",
"\n",
"}"
] |
// CacheAuthorization wraps an Authorizer in an in memory cache that expires
// after the given expiration. Only positive authorizations will be cached.
|
[
"CacheAuthorization",
"wraps",
"an",
"Authorizer",
"in",
"an",
"in",
"memory",
"cache",
"that",
"expires",
"after",
"the",
"given",
"expiration",
".",
"Only",
"positive",
"authorizations",
"will",
"be",
"cached",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/cache.go#L12-L19
|
train
|
remind101/empire
|
pkg/heroku/dyno.go
|
DynoRestart
|
func (c *Client) DynoRestart(appIdentity, dynoIdentity, message string) error {
rh := RequestHeaders{CommitMessage: message}
return c.DeleteWithHeaders("/apps/"+appIdentity+"/dynos/"+dynoIdentity, rh.Headers())
}
|
go
|
func (c *Client) DynoRestart(appIdentity, dynoIdentity, message string) error {
rh := RequestHeaders{CommitMessage: message}
return c.DeleteWithHeaders("/apps/"+appIdentity+"/dynos/"+dynoIdentity, rh.Headers())
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DynoRestart",
"(",
"appIdentity",
",",
"dynoIdentity",
",",
"message",
"string",
")",
"error",
"{",
"rh",
":=",
"RequestHeaders",
"{",
"CommitMessage",
":",
"message",
"}",
"\n",
"return",
"c",
".",
"DeleteWithHeaders",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"dynoIdentity",
",",
"rh",
".",
"Headers",
"(",
")",
")",
"\n",
"}"
] |
// Restart dyno.
//
// appIdentity is the unique identifier of the Dyno's App. dynoIdentity is the
// unique identifier of the Dyno.
|
[
"Restart",
"dyno",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Dyno",
"s",
"App",
".",
"dynoIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Dyno",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/dyno.go#L96-L99
|
train
|
remind101/empire
|
pkg/heroku/dyno.go
|
DynoRestartAll
|
func (c *Client) DynoRestartAll(appIdentity, message string) error {
rh := RequestHeaders{CommitMessage: message}
return c.DeleteWithHeaders("/apps/"+appIdentity+"/dynos", rh.Headers())
}
|
go
|
func (c *Client) DynoRestartAll(appIdentity, message string) error {
rh := RequestHeaders{CommitMessage: message}
return c.DeleteWithHeaders("/apps/"+appIdentity+"/dynos", rh.Headers())
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DynoRestartAll",
"(",
"appIdentity",
",",
"message",
"string",
")",
"error",
"{",
"rh",
":=",
"RequestHeaders",
"{",
"CommitMessage",
":",
"message",
"}",
"\n",
"return",
"c",
".",
"DeleteWithHeaders",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"rh",
".",
"Headers",
"(",
")",
")",
"\n",
"}"
] |
// Restart all dynos
//
// appIdentity is the unique identifier of the Dyno's App.
|
[
"Restart",
"all",
"dynos",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Dyno",
"s",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/dyno.go#L104-L107
|
train
|
remind101/empire
|
pkg/heroku/dyno.go
|
DynoInfo
|
func (c *Client) DynoInfo(appIdentity string, dynoIdentity string) (*Dyno, error) {
var dyno Dyno
return &dyno, c.Get(&dyno, "/apps/"+appIdentity+"/dynos/"+dynoIdentity)
}
|
go
|
func (c *Client) DynoInfo(appIdentity string, dynoIdentity string) (*Dyno, error) {
var dyno Dyno
return &dyno, c.Get(&dyno, "/apps/"+appIdentity+"/dynos/"+dynoIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DynoInfo",
"(",
"appIdentity",
"string",
",",
"dynoIdentity",
"string",
")",
"(",
"*",
"Dyno",
",",
"error",
")",
"{",
"var",
"dyno",
"Dyno",
"\n",
"return",
"&",
"dyno",
",",
"c",
".",
"Get",
"(",
"&",
"dyno",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"dynoIdentity",
")",
"\n",
"}"
] |
// Info for existing dyno.
//
// appIdentity is the unique identifier of the Dyno's App. dynoIdentity is the
// unique identifier of the Dyno.
|
[
"Info",
"for",
"existing",
"dyno",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Dyno",
"s",
"App",
".",
"dynoIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Dyno",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/dyno.go#L113-L116
|
train
|
remind101/empire
|
pkg/heroku/dyno.go
|
DynoList
|
func (c *Client) DynoList(appIdentity string, lr *ListRange) ([]Dyno, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/dynos", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var dynosRes []Dyno
return dynosRes, c.DoReq(req, &dynosRes)
}
|
go
|
func (c *Client) DynoList(appIdentity string, lr *ListRange) ([]Dyno, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/dynos", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var dynosRes []Dyno
return dynosRes, c.DoReq(req, &dynosRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"DynoList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Dyno",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"dynosRes",
"[",
"]",
"Dyno",
"\n",
"return",
"dynosRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"dynosRes",
")",
"\n",
"}"
] |
// List existing dynos.
//
// appIdentity is the unique identifier of the Dyno's App. lr is an optional
// ListRange that sets the Range options for the paginated list of results.
|
[
"List",
"existing",
"dynos",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Dyno",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/dyno.go#L122-L134
|
train
|
remind101/empire
|
apps.go
|
IsValid
|
func (a *App) IsValid() error {
if !NamePattern.Match([]byte(a.Name)) {
return ErrInvalidName
}
return nil
}
|
go
|
func (a *App) IsValid() error {
if !NamePattern.Match([]byte(a.Name)) {
return ErrInvalidName
}
return nil
}
|
[
"func",
"(",
"a",
"*",
"App",
")",
"IsValid",
"(",
")",
"error",
"{",
"if",
"!",
"NamePattern",
".",
"Match",
"(",
"[",
"]",
"byte",
"(",
"a",
".",
"Name",
")",
")",
"{",
"return",
"ErrInvalidName",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// IsValid returns an error if the app isn't valid.
|
[
"IsValid",
"returns",
"an",
"error",
"if",
"the",
"app",
"isn",
"t",
"valid",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L97-L103
|
train
|
remind101/empire
|
apps.go
|
Destroy
|
func (s *appsService) Destroy(ctx context.Context, db *gorm.DB, app *App) error {
if err := appsDestroy(db, app); err != nil {
return err
}
return s.Scheduler.Remove(ctx, app.ID)
}
|
go
|
func (s *appsService) Destroy(ctx context.Context, db *gorm.DB, app *App) error {
if err := appsDestroy(db, app); err != nil {
return err
}
return s.Scheduler.Remove(ctx, app.ID)
}
|
[
"func",
"(",
"s",
"*",
"appsService",
")",
"Destroy",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"error",
"{",
"if",
"err",
":=",
"appsDestroy",
"(",
"db",
",",
"app",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"Scheduler",
".",
"Remove",
"(",
"ctx",
",",
"app",
".",
"ID",
")",
"\n",
"}"
] |
// Destroy destroys removes an app from the scheduler, then destroys it here.
|
[
"Destroy",
"destroys",
"removes",
"an",
"app",
"from",
"the",
"scheduler",
"then",
"destroys",
"it",
"here",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L153-L159
|
train
|
remind101/empire
|
apps.go
|
appsEnsureRepo
|
func appsEnsureRepo(db *gorm.DB, app *App, repo string) error {
if app.Repo != nil {
return nil
}
app.Repo = &repo
return appsUpdate(db, app)
}
|
go
|
func appsEnsureRepo(db *gorm.DB, app *App, repo string) error {
if app.Repo != nil {
return nil
}
app.Repo = &repo
return appsUpdate(db, app)
}
|
[
"func",
"appsEnsureRepo",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
",",
"repo",
"string",
")",
"error",
"{",
"if",
"app",
".",
"Repo",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"app",
".",
"Repo",
"=",
"&",
"repo",
"\n\n",
"return",
"appsUpdate",
"(",
"db",
",",
"app",
")",
"\n",
"}"
] |
// appsEnsureRepo will set the repo if it's not set.
|
[
"appsEnsureRepo",
"will",
"set",
"the",
"repo",
"if",
"it",
"s",
"not",
"set",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L219-L227
|
train
|
remind101/empire
|
apps.go
|
appsFindOrCreateByRepo
|
func appsFindOrCreateByRepo(db *gorm.DB, repo string) (*App, error) {
n := appNameFromRepo(repo)
a, err := appsFind(db, AppsQuery{Name: &n})
if err != nil && err != gorm.RecordNotFound {
return a, err
}
// If the app wasn't found, create a new app.
if err != gorm.RecordNotFound {
return a, appsEnsureRepo(db, a, repo)
}
a = &App{
Name: n,
Repo: &repo,
}
return appsCreate(db, a)
}
|
go
|
func appsFindOrCreateByRepo(db *gorm.DB, repo string) (*App, error) {
n := appNameFromRepo(repo)
a, err := appsFind(db, AppsQuery{Name: &n})
if err != nil && err != gorm.RecordNotFound {
return a, err
}
// If the app wasn't found, create a new app.
if err != gorm.RecordNotFound {
return a, appsEnsureRepo(db, a, repo)
}
a = &App{
Name: n,
Repo: &repo,
}
return appsCreate(db, a)
}
|
[
"func",
"appsFindOrCreateByRepo",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"repo",
"string",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"n",
":=",
"appNameFromRepo",
"(",
"repo",
")",
"\n",
"a",
",",
"err",
":=",
"appsFind",
"(",
"db",
",",
"AppsQuery",
"{",
"Name",
":",
"&",
"n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"gorm",
".",
"RecordNotFound",
"{",
"return",
"a",
",",
"err",
"\n",
"}",
"\n\n",
"// If the app wasn't found, create a new app.",
"if",
"err",
"!=",
"gorm",
".",
"RecordNotFound",
"{",
"return",
"a",
",",
"appsEnsureRepo",
"(",
"db",
",",
"a",
",",
"repo",
")",
"\n",
"}",
"\n\n",
"a",
"=",
"&",
"App",
"{",
"Name",
":",
"n",
",",
"Repo",
":",
"&",
"repo",
",",
"}",
"\n\n",
"return",
"appsCreate",
"(",
"db",
",",
"a",
")",
"\n",
"}"
] |
// appsFindOrCreateByRepo first attempts to find an app by repo, falling back to
// creating a new app.
|
[
"appsFindOrCreateByRepo",
"first",
"attempts",
"to",
"find",
"an",
"app",
"by",
"repo",
"falling",
"back",
"to",
"creating",
"a",
"new",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L231-L249
|
train
|
remind101/empire
|
apps.go
|
appsFind
|
func appsFind(db *gorm.DB, scope scope) (*App, error) {
var app App
return &app, first(db, scope, &app)
}
|
go
|
func appsFind(db *gorm.DB, scope scope) (*App, error) {
var app App
return &app, first(db, scope, &app)
}
|
[
"func",
"appsFind",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"var",
"app",
"App",
"\n",
"return",
"&",
"app",
",",
"first",
"(",
"db",
",",
"scope",
",",
"&",
"app",
")",
"\n",
"}"
] |
// appsFind finds a single app given the scope.
|
[
"appsFind",
"finds",
"a",
"single",
"app",
"given",
"the",
"scope",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L252-L255
|
train
|
remind101/empire
|
apps.go
|
apps
|
func apps(db *gorm.DB, scope scope) ([]*App, error) {
var apps []*App
// Default to ordering by name.
scope = composedScope{order("name"), scope}
return apps, find(db, scope, &apps)
}
|
go
|
func apps(db *gorm.DB, scope scope) ([]*App, error) {
var apps []*App
// Default to ordering by name.
scope = composedScope{order("name"), scope}
return apps, find(db, scope, &apps)
}
|
[
"func",
"apps",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"[",
"]",
"*",
"App",
",",
"error",
")",
"{",
"var",
"apps",
"[",
"]",
"*",
"App",
"\n",
"// Default to ordering by name.",
"scope",
"=",
"composedScope",
"{",
"order",
"(",
"\"",
"\"",
")",
",",
"scope",
"}",
"\n",
"return",
"apps",
",",
"find",
"(",
"db",
",",
"scope",
",",
"&",
"apps",
")",
"\n",
"}"
] |
// apps finds all apps matching the scope.
|
[
"apps",
"finds",
"all",
"apps",
"matching",
"the",
"scope",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L258-L263
|
train
|
remind101/empire
|
apps.go
|
appsCreate
|
func appsCreate(db *gorm.DB, app *App) (*App, error) {
return app, db.Create(app).Error
}
|
go
|
func appsCreate(db *gorm.DB, app *App) (*App, error) {
return app, db.Create(app).Error
}
|
[
"func",
"appsCreate",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"return",
"app",
",",
"db",
".",
"Create",
"(",
"app",
")",
".",
"Error",
"\n",
"}"
] |
// appsCreate inserts the app into the database.
|
[
"appsCreate",
"inserts",
"the",
"app",
"into",
"the",
"database",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L266-L268
|
train
|
remind101/empire
|
apps.go
|
appsUpdate
|
func appsUpdate(db *gorm.DB, app *App) error {
return db.Save(app).Error
}
|
go
|
func appsUpdate(db *gorm.DB, app *App) error {
return db.Save(app).Error
}
|
[
"func",
"appsUpdate",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"error",
"{",
"return",
"db",
".",
"Save",
"(",
"app",
")",
".",
"Error",
"\n",
"}"
] |
// appsUpdate updates an app.
|
[
"appsUpdate",
"updates",
"an",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L271-L273
|
train
|
remind101/empire
|
apps.go
|
appsDestroy
|
func appsDestroy(db *gorm.DB, app *App) error {
now := timex.Now()
app.DeletedAt = &now
return appsUpdate(db, app)
}
|
go
|
func appsDestroy(db *gorm.DB, app *App) error {
now := timex.Now()
app.DeletedAt = &now
return appsUpdate(db, app)
}
|
[
"func",
"appsDestroy",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"error",
"{",
"now",
":=",
"timex",
".",
"Now",
"(",
")",
"\n",
"app",
".",
"DeletedAt",
"=",
"&",
"now",
"\n",
"return",
"appsUpdate",
"(",
"db",
",",
"app",
")",
"\n",
"}"
] |
// appsDestroy destroys an app.
|
[
"appsDestroy",
"destroys",
"an",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/apps.go#L276-L280
|
train
|
remind101/empire
|
pkg/httpmock/httpmock.go
|
NewServeReplay
|
func NewServeReplay(t *testing.T) *ServeReplay {
return &ServeReplay{
t: t,
Handlers: make([]http.Handler, 0),
NoneLeftFunc: defaultNoneLeftFunc,
}
}
|
go
|
func NewServeReplay(t *testing.T) *ServeReplay {
return &ServeReplay{
t: t,
Handlers: make([]http.Handler, 0),
NoneLeftFunc: defaultNoneLeftFunc,
}
}
|
[
"func",
"NewServeReplay",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"*",
"ServeReplay",
"{",
"return",
"&",
"ServeReplay",
"{",
"t",
":",
"t",
",",
"Handlers",
":",
"make",
"(",
"[",
"]",
"http",
".",
"Handler",
",",
"0",
")",
",",
"NoneLeftFunc",
":",
"defaultNoneLeftFunc",
",",
"}",
"\n",
"}"
] |
// NewServeReplay returns a new ServeReplay.
|
[
"NewServeReplay",
"returns",
"a",
"new",
"ServeReplay",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/httpmock/httpmock.go#L26-L32
|
train
|
remind101/empire
|
pkg/httpmock/httpmock.go
|
Add
|
func (h *ServeReplay) Add(handler http.Handler) *ServeReplay {
h.Handlers = append(h.Handlers, handler)
return h
}
|
go
|
func (h *ServeReplay) Add(handler http.Handler) *ServeReplay {
h.Handlers = append(h.Handlers, handler)
return h
}
|
[
"func",
"(",
"h",
"*",
"ServeReplay",
")",
"Add",
"(",
"handler",
"http",
".",
"Handler",
")",
"*",
"ServeReplay",
"{",
"h",
".",
"Handlers",
"=",
"append",
"(",
"h",
".",
"Handlers",
",",
"handler",
")",
"\n",
"return",
"h",
"\n",
"}"
] |
// Add appends a handler to ServReplay's handler list.
// It returns itself to allow chaining.
|
[
"Add",
"appends",
"a",
"handler",
"to",
"ServReplay",
"s",
"handler",
"list",
".",
"It",
"returns",
"itself",
"to",
"allow",
"chaining",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/httpmock/httpmock.go#L36-L39
|
train
|
remind101/empire
|
pkg/httpmock/httpmock.go
|
ServeHTTP
|
func (h *ServeReplay) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if h.i >= len(h.Handlers) {
h.NoneLeftFunc(h.t, r)
} else {
h.Handlers[h.i].ServeHTTP(w, r)
h.i++
}
}
|
go
|
func (h *ServeReplay) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if h.i >= len(h.Handlers) {
h.NoneLeftFunc(h.t, r)
} else {
h.Handlers[h.i].ServeHTTP(w, r)
h.i++
}
}
|
[
"func",
"(",
"h",
"*",
"ServeReplay",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"h",
".",
"i",
">=",
"len",
"(",
"h",
".",
"Handlers",
")",
"{",
"h",
".",
"NoneLeftFunc",
"(",
"h",
".",
"t",
",",
"r",
")",
"\n",
"}",
"else",
"{",
"h",
".",
"Handlers",
"[",
"h",
".",
"i",
"]",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"h",
".",
"i",
"++",
"\n",
"}",
"\n",
"}"
] |
// ServeHTTP dispatches the request to the next handler in the list.
|
[
"ServeHTTP",
"dispatches",
"the",
"request",
"to",
"the",
"next",
"handler",
"in",
"the",
"list",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/httpmock/httpmock.go#L42-L49
|
train
|
remind101/empire
|
pkg/heroku/organization_app_collaborator.go
|
OrganizationAppCollaboratorDelete
|
func (c *Client) OrganizationAppCollaboratorDelete(appIdentity string, collaboratorIdentity string) error {
return c.Delete("/organizations/apps/" + appIdentity + "/collaborators/" + collaboratorIdentity)
}
|
go
|
func (c *Client) OrganizationAppCollaboratorDelete(appIdentity string, collaboratorIdentity string) error {
return c.Delete("/organizations/apps/" + appIdentity + "/collaborators/" + collaboratorIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppCollaboratorDelete",
"(",
"appIdentity",
"string",
",",
"collaboratorIdentity",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Delete",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"collaboratorIdentity",
")",
"\n",
"}"
] |
// Delete an existing collaborator from an organization app.
//
// appIdentity is the unique identifier of the OrganizationAppCollaborator's
// App. collaboratorIdentity is the unique identifier of the
// OrganizationAppCollaborator's Collaborator.
|
[
"Delete",
"an",
"existing",
"collaborator",
"from",
"an",
"organization",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationAppCollaborator",
"s",
"App",
".",
"collaboratorIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationAppCollaborator",
"s",
"Collaborator",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app_collaborator.go#L67-L69
|
train
|
remind101/empire
|
pkg/heroku/organization_app_collaborator.go
|
OrganizationAppCollaboratorInfo
|
func (c *Client) OrganizationAppCollaboratorInfo(appIdentity string, collaboratorIdentity string) (*OrganizationAppCollaborator, error) {
var organizationAppCollaborator OrganizationAppCollaborator
return &organizationAppCollaborator, c.Get(&organizationAppCollaborator, "/organizations/apps/"+appIdentity+"/collaborators/"+collaboratorIdentity)
}
|
go
|
func (c *Client) OrganizationAppCollaboratorInfo(appIdentity string, collaboratorIdentity string) (*OrganizationAppCollaborator, error) {
var organizationAppCollaborator OrganizationAppCollaborator
return &organizationAppCollaborator, c.Get(&organizationAppCollaborator, "/organizations/apps/"+appIdentity+"/collaborators/"+collaboratorIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppCollaboratorInfo",
"(",
"appIdentity",
"string",
",",
"collaboratorIdentity",
"string",
")",
"(",
"*",
"OrganizationAppCollaborator",
",",
"error",
")",
"{",
"var",
"organizationAppCollaborator",
"OrganizationAppCollaborator",
"\n",
"return",
"&",
"organizationAppCollaborator",
",",
"c",
".",
"Get",
"(",
"&",
"organizationAppCollaborator",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"collaboratorIdentity",
")",
"\n",
"}"
] |
// Info for a collaborator on an organization app.
//
// appIdentity is the unique identifier of the OrganizationAppCollaborator's
// App. collaboratorIdentity is the unique identifier of the
// OrganizationAppCollaborator's Collaborator.
|
[
"Info",
"for",
"a",
"collaborator",
"on",
"an",
"organization",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationAppCollaborator",
"s",
"App",
".",
"collaboratorIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationAppCollaborator",
"s",
"Collaborator",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app_collaborator.go#L76-L79
|
train
|
remind101/empire
|
pkg/heroku/organization_app_collaborator.go
|
OrganizationAppCollaboratorList
|
func (c *Client) OrganizationAppCollaboratorList(appIdentity string, lr *ListRange) ([]OrganizationAppCollaborator, error) {
req, err := c.NewRequest("GET", "/organizations/apps/"+appIdentity+"/collaborators", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationAppCollaboratorsRes []OrganizationAppCollaborator
return organizationAppCollaboratorsRes, c.DoReq(req, &organizationAppCollaboratorsRes)
}
|
go
|
func (c *Client) OrganizationAppCollaboratorList(appIdentity string, lr *ListRange) ([]OrganizationAppCollaborator, error) {
req, err := c.NewRequest("GET", "/organizations/apps/"+appIdentity+"/collaborators", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationAppCollaboratorsRes []OrganizationAppCollaborator
return organizationAppCollaboratorsRes, c.DoReq(req, &organizationAppCollaboratorsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppCollaboratorList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"OrganizationAppCollaborator",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"organizationAppCollaboratorsRes",
"[",
"]",
"OrganizationAppCollaborator",
"\n",
"return",
"organizationAppCollaboratorsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"organizationAppCollaboratorsRes",
")",
"\n",
"}"
] |
// List collaborators on an organization app.
//
// appIdentity is the unique identifier of the OrganizationAppCollaborator's
// App. lr is an optional ListRange that sets the Range options for the
// paginated list of results.
|
[
"List",
"collaborators",
"on",
"an",
"organization",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationAppCollaborator",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app_collaborator.go#L86-L98
|
train
|
remind101/empire
|
twelvefactor/twelvefactor.go
|
Transform
|
func Transform(s Scheduler, fn func(*Manifest) *Manifest) Scheduler {
return &transformer{s, fn}
}
|
go
|
func Transform(s Scheduler, fn func(*Manifest) *Manifest) Scheduler {
return &transformer{s, fn}
}
|
[
"func",
"Transform",
"(",
"s",
"Scheduler",
",",
"fn",
"func",
"(",
"*",
"Manifest",
")",
"*",
"Manifest",
")",
"Scheduler",
"{",
"return",
"&",
"transformer",
"{",
"s",
",",
"fn",
"}",
"\n",
"}"
] |
// Trasnform wraps a Scheduler to perform transformations on the Manifest. This
// can be used to, for example, add defaults placement constraints before
// providing it to the backend scheduler.
|
[
"Trasnform",
"wraps",
"a",
"Scheduler",
"to",
"perform",
"transformations",
"on",
"the",
"Manifest",
".",
"This",
"can",
"be",
"used",
"to",
"for",
"example",
"add",
"defaults",
"placement",
"constraints",
"before",
"providing",
"it",
"to",
"the",
"backend",
"scheduler",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/twelvefactor/twelvefactor.go#L194-L196
|
train
|
remind101/empire
|
twelvefactor/twelvefactor.go
|
Env
|
func Env(app *Manifest, process *Process) map[string]string {
return merge(app.Env, process.Env)
}
|
go
|
func Env(app *Manifest, process *Process) map[string]string {
return merge(app.Env, process.Env)
}
|
[
"func",
"Env",
"(",
"app",
"*",
"Manifest",
",",
"process",
"*",
"Process",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"merge",
"(",
"app",
".",
"Env",
",",
"process",
".",
"Env",
")",
"\n",
"}"
] |
// Env merges the App environment with any environment variables provided
// in the process.
|
[
"Env",
"merges",
"the",
"App",
"environment",
"with",
"any",
"environment",
"variables",
"provided",
"in",
"the",
"process",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/twelvefactor/twelvefactor.go#L218-L220
|
train
|
remind101/empire
|
twelvefactor/twelvefactor.go
|
Labels
|
func Labels(app *Manifest, process *Process) map[string]string {
return merge(app.Labels, process.Labels)
}
|
go
|
func Labels(app *Manifest, process *Process) map[string]string {
return merge(app.Labels, process.Labels)
}
|
[
"func",
"Labels",
"(",
"app",
"*",
"Manifest",
",",
"process",
"*",
"Process",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"merge",
"(",
"app",
".",
"Labels",
",",
"process",
".",
"Labels",
")",
"\n",
"}"
] |
// Labels merges the App labels with any labels provided in the process.
|
[
"Labels",
"merges",
"the",
"App",
"labels",
"with",
"any",
"labels",
"provided",
"in",
"the",
"process",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/twelvefactor/twelvefactor.go#L223-L225
|
train
|
remind101/empire
|
twelvefactor/twelvefactor.go
|
merge
|
func merge(envs ...map[string]string) map[string]string {
merged := make(map[string]string)
for _, env := range envs {
for k, v := range env {
merged[k] = v
}
}
return merged
}
|
go
|
func merge(envs ...map[string]string) map[string]string {
merged := make(map[string]string)
for _, env := range envs {
for k, v := range env {
merged[k] = v
}
}
return merged
}
|
[
"func",
"merge",
"(",
"envs",
"...",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"merged",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"env",
":=",
"range",
"envs",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"env",
"{",
"merged",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"merged",
"\n",
"}"
] |
// merges the maps together, favoring keys from the right to the left.
|
[
"merges",
"the",
"maps",
"together",
"favoring",
"keys",
"from",
"the",
"right",
"to",
"the",
"left",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/twelvefactor/twelvefactor.go#L228-L236
|
train
|
remind101/empire
|
cmd/emp/main.go
|
matchesCommand
|
func matchesCommand(cmd *Command, want string) bool {
if cmd.Alias != "" && cmd.Alias == want {
return true
}
return cmd.Name() == want
}
|
go
|
func matchesCommand(cmd *Command, want string) bool {
if cmd.Alias != "" && cmd.Alias == want {
return true
}
return cmd.Name() == want
}
|
[
"func",
"matchesCommand",
"(",
"cmd",
"*",
"Command",
",",
"want",
"string",
")",
"bool",
"{",
"if",
"cmd",
".",
"Alias",
"!=",
"\"",
"\"",
"&&",
"cmd",
".",
"Alias",
"==",
"want",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"cmd",
".",
"Name",
"(",
")",
"==",
"want",
"\n",
"}"
] |
// matchesCommand checks if the Command matches the command that we want to run.
|
[
"matchesCommand",
"checks",
"if",
"the",
"Command",
"matches",
"the",
"command",
"that",
"we",
"want",
"to",
"run",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/cmd/emp/main.go#L294-L300
|
train
|
remind101/empire
|
internal/uuid/time.go
|
UnixTime
|
func (t Time) UnixTime() (sec, nsec int64) {
sec = int64(t - g1582ns100)
nsec = (sec % 10000000) * 100
sec /= 10000000
return sec, nsec
}
|
go
|
func (t Time) UnixTime() (sec, nsec int64) {
sec = int64(t - g1582ns100)
nsec = (sec % 10000000) * 100
sec /= 10000000
return sec, nsec
}
|
[
"func",
"(",
"t",
"Time",
")",
"UnixTime",
"(",
")",
"(",
"sec",
",",
"nsec",
"int64",
")",
"{",
"sec",
"=",
"int64",
"(",
"t",
"-",
"g1582ns100",
")",
"\n",
"nsec",
"=",
"(",
"sec",
"%",
"10000000",
")",
"*",
"100",
"\n",
"sec",
"/=",
"10000000",
"\n",
"return",
"sec",
",",
"nsec",
"\n",
"}"
] |
// UnixTime converts t the number of seconds and nanoseconds using the Unix
// epoch of 1 Jan 1970.
|
[
"UnixTime",
"converts",
"t",
"the",
"number",
"of",
"seconds",
"and",
"nanoseconds",
"using",
"the",
"Unix",
"epoch",
"of",
"1",
"Jan",
"1970",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/uuid/time.go#L35-L40
|
train
|
remind101/empire
|
internal/uuid/time.go
|
Time
|
func (uuid UUID) Time() (Time, bool) {
if len(uuid) != 16 {
return 0, false
}
time := int64(binary.BigEndian.Uint32(uuid[0:4]))
time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
return Time(time), true
}
|
go
|
func (uuid UUID) Time() (Time, bool) {
if len(uuid) != 16 {
return 0, false
}
time := int64(binary.BigEndian.Uint32(uuid[0:4]))
time |= int64(binary.BigEndian.Uint16(uuid[4:6])) << 32
time |= int64(binary.BigEndian.Uint16(uuid[6:8])&0xfff) << 48
return Time(time), true
}
|
[
"func",
"(",
"uuid",
"UUID",
")",
"Time",
"(",
")",
"(",
"Time",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"uuid",
")",
"!=",
"16",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"time",
":=",
"int64",
"(",
"binary",
".",
"BigEndian",
".",
"Uint32",
"(",
"uuid",
"[",
"0",
":",
"4",
"]",
")",
")",
"\n",
"time",
"|=",
"int64",
"(",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"uuid",
"[",
"4",
":",
"6",
"]",
")",
")",
"<<",
"32",
"\n",
"time",
"|=",
"int64",
"(",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"uuid",
"[",
"6",
":",
"8",
"]",
")",
"&",
"0xfff",
")",
"<<",
"48",
"\n",
"return",
"Time",
"(",
"time",
")",
",",
"true",
"\n",
"}"
] |
// Time returns the time in 100s of nanoseconds since 15 Oct 1582 encoded in
// uuid. It returns false if uuid is not valid. The time is only well defined
// for version 1 and 2 UUIDs.
|
[
"Time",
"returns",
"the",
"time",
"in",
"100s",
"of",
"nanoseconds",
"since",
"15",
"Oct",
"1582",
"encoded",
"in",
"uuid",
".",
"It",
"returns",
"false",
"if",
"uuid",
"is",
"not",
"valid",
".",
"The",
"time",
"is",
"only",
"well",
"defined",
"for",
"version",
"1",
"and",
"2",
"UUIDs",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/uuid/time.go#L114-L122
|
train
|
remind101/empire
|
internal/uuid/time.go
|
ClockSequence
|
func (uuid UUID) ClockSequence() (int, bool) {
if len(uuid) != 16 {
return 0, false
}
return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff, true
}
|
go
|
func (uuid UUID) ClockSequence() (int, bool) {
if len(uuid) != 16 {
return 0, false
}
return int(binary.BigEndian.Uint16(uuid[8:10])) & 0x3fff, true
}
|
[
"func",
"(",
"uuid",
"UUID",
")",
"ClockSequence",
"(",
")",
"(",
"int",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"uuid",
")",
"!=",
"16",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"return",
"int",
"(",
"binary",
".",
"BigEndian",
".",
"Uint16",
"(",
"uuid",
"[",
"8",
":",
"10",
"]",
")",
")",
"&",
"0x3fff",
",",
"true",
"\n",
"}"
] |
// ClockSequence returns the clock sequence encoded in uuid. It returns false
// if uuid is not valid. The clock sequence is only well defined for version 1
// and 2 UUIDs.
|
[
"ClockSequence",
"returns",
"the",
"clock",
"sequence",
"encoded",
"in",
"uuid",
".",
"It",
"returns",
"false",
"if",
"uuid",
"is",
"not",
"valid",
".",
"The",
"clock",
"sequence",
"is",
"only",
"well",
"defined",
"for",
"version",
"1",
"and",
"2",
"UUIDs",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/uuid/time.go#L127-L132
|
train
|
remind101/empire
|
configs.go
|
newConfig
|
func newConfig(old *Config, vars Vars) *Config {
v := mergeVars(old.Vars, vars)
return &Config{
AppID: old.AppID,
Vars: v,
}
}
|
go
|
func newConfig(old *Config, vars Vars) *Config {
v := mergeVars(old.Vars, vars)
return &Config{
AppID: old.AppID,
Vars: v,
}
}
|
[
"func",
"newConfig",
"(",
"old",
"*",
"Config",
",",
"vars",
"Vars",
")",
"*",
"Config",
"{",
"v",
":=",
"mergeVars",
"(",
"old",
".",
"Vars",
",",
"vars",
")",
"\n\n",
"return",
"&",
"Config",
"{",
"AppID",
":",
"old",
".",
"AppID",
",",
"Vars",
":",
"v",
",",
"}",
"\n",
"}"
] |
// newConfig initializes a new config based on the old config, with the new
// variables provided.
|
[
"newConfig",
"initializes",
"a",
"new",
"config",
"based",
"on",
"the",
"old",
"config",
"with",
"the",
"new",
"variables",
"provided",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/configs.go#L32-L39
|
train
|
remind101/empire
|
configs.go
|
configsFind
|
func configsFind(db *gorm.DB, scope scope) (*Config, error) {
var config Config
scope = composedScope{order("created_at desc"), scope}
return &config, first(db, scope, &config)
}
|
go
|
func configsFind(db *gorm.DB, scope scope) (*Config, error) {
var config Config
scope = composedScope{order("created_at desc"), scope}
return &config, first(db, scope, &config)
}
|
[
"func",
"configsFind",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"var",
"config",
"Config",
"\n",
"scope",
"=",
"composedScope",
"{",
"order",
"(",
"\"",
"\"",
")",
",",
"scope",
"}",
"\n",
"return",
"&",
"config",
",",
"first",
"(",
"db",
",",
"scope",
",",
"&",
"config",
")",
"\n",
"}"
] |
// configsFind returns the first matching config.
|
[
"configsFind",
"returns",
"the",
"first",
"matching",
"config",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/configs.go#L112-L116
|
train
|
remind101/empire
|
configs.go
|
configsCreate
|
func configsCreate(db *gorm.DB, config *Config) (*Config, error) {
return config, db.Create(config).Error
}
|
go
|
func configsCreate(db *gorm.DB, config *Config) (*Config, error) {
return config, db.Create(config).Error
}
|
[
"func",
"configsCreate",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"config",
"*",
"Config",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"return",
"config",
",",
"db",
".",
"Create",
"(",
"config",
")",
".",
"Error",
"\n",
"}"
] |
// ConfigsCreate inserts a Config in the database.
|
[
"ConfigsCreate",
"inserts",
"a",
"Config",
"in",
"the",
"database",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/configs.go#L119-L121
|
train
|
remind101/empire
|
configs.go
|
Config
|
func (s *configsService) Config(db *gorm.DB, app *App) (*Config, error) {
r, err := releasesFind(db, ReleasesQuery{App: app})
if err != nil {
if err == gorm.RecordNotFound {
// It's possible to have config without releases, this handles that.
c, err := configsFind(db, ConfigsQuery{App: app})
if err != nil {
if err == gorm.RecordNotFound {
// Return an empty config.
return &Config{
AppID: app.ID,
App: app,
Vars: make(Vars),
}, nil
}
return nil, err
}
return c, nil
}
return nil, err
}
return r.Config, nil
}
|
go
|
func (s *configsService) Config(db *gorm.DB, app *App) (*Config, error) {
r, err := releasesFind(db, ReleasesQuery{App: app})
if err != nil {
if err == gorm.RecordNotFound {
// It's possible to have config without releases, this handles that.
c, err := configsFind(db, ConfigsQuery{App: app})
if err != nil {
if err == gorm.RecordNotFound {
// Return an empty config.
return &Config{
AppID: app.ID,
App: app,
Vars: make(Vars),
}, nil
}
return nil, err
}
return c, nil
}
return nil, err
}
return r.Config, nil
}
|
[
"func",
"(",
"s",
"*",
"configsService",
")",
"Config",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"app",
"*",
"App",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"releasesFind",
"(",
"db",
",",
"ReleasesQuery",
"{",
"App",
":",
"app",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"gorm",
".",
"RecordNotFound",
"{",
"// It's possible to have config without releases, this handles that.",
"c",
",",
"err",
":=",
"configsFind",
"(",
"db",
",",
"ConfigsQuery",
"{",
"App",
":",
"app",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"gorm",
".",
"RecordNotFound",
"{",
"// Return an empty config.",
"return",
"&",
"Config",
"{",
"AppID",
":",
"app",
".",
"ID",
",",
"App",
":",
"app",
",",
"Vars",
":",
"make",
"(",
"Vars",
")",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"Config",
",",
"nil",
"\n",
"}"
] |
// Returns configs for latest release or the latest configs if there are no releases.
|
[
"Returns",
"configs",
"for",
"latest",
"release",
"or",
"the",
"latest",
"configs",
"if",
"there",
"are",
"no",
"releases",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/configs.go#L160-L185
|
train
|
remind101/empire
|
configs.go
|
mergeVars
|
func mergeVars(old, new Vars) Vars {
vars := make(Vars)
for n, v := range old {
vars[n] = v
}
for n, v := range new {
if v == nil {
delete(vars, n)
} else {
vars[n] = v
}
}
return vars
}
|
go
|
func mergeVars(old, new Vars) Vars {
vars := make(Vars)
for n, v := range old {
vars[n] = v
}
for n, v := range new {
if v == nil {
delete(vars, n)
} else {
vars[n] = v
}
}
return vars
}
|
[
"func",
"mergeVars",
"(",
"old",
",",
"new",
"Vars",
")",
"Vars",
"{",
"vars",
":=",
"make",
"(",
"Vars",
")",
"\n\n",
"for",
"n",
",",
"v",
":=",
"range",
"old",
"{",
"vars",
"[",
"n",
"]",
"=",
"v",
"\n",
"}",
"\n\n",
"for",
"n",
",",
"v",
":=",
"range",
"new",
"{",
"if",
"v",
"==",
"nil",
"{",
"delete",
"(",
"vars",
",",
"n",
")",
"\n",
"}",
"else",
"{",
"vars",
"[",
"n",
"]",
"=",
"v",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"vars",
"\n",
"}"
] |
// mergeVars copies all of the vars from a, and merges b into them, returning a
// new Vars.
|
[
"mergeVars",
"copies",
"all",
"of",
"the",
"vars",
"from",
"a",
"and",
"merges",
"b",
"into",
"them",
"returning",
"a",
"new",
"Vars",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/configs.go#L189-L205
|
train
|
remind101/empire
|
configs.go
|
configsApplyReleaseDesc
|
func configsApplyReleaseDesc(opts SetOpts) string {
vars := opts.Vars
verb := "Set"
plural := ""
if len(vars) > 1 {
plural = "s"
}
keys := make(sort.StringSlice, 0, len(vars))
for k, v := range vars {
keys = append(keys, string(k))
if v == nil {
verb = "Unset"
}
}
keys.Sort()
desc := fmt.Sprintf("%s %s config var%s", verb, strings.Join(keys, ", "), plural)
return appendMessageToDescription(desc, opts.User, opts.Message)
}
|
go
|
func configsApplyReleaseDesc(opts SetOpts) string {
vars := opts.Vars
verb := "Set"
plural := ""
if len(vars) > 1 {
plural = "s"
}
keys := make(sort.StringSlice, 0, len(vars))
for k, v := range vars {
keys = append(keys, string(k))
if v == nil {
verb = "Unset"
}
}
keys.Sort()
desc := fmt.Sprintf("%s %s config var%s", verb, strings.Join(keys, ", "), plural)
return appendMessageToDescription(desc, opts.User, opts.Message)
}
|
[
"func",
"configsApplyReleaseDesc",
"(",
"opts",
"SetOpts",
")",
"string",
"{",
"vars",
":=",
"opts",
".",
"Vars",
"\n",
"verb",
":=",
"\"",
"\"",
"\n",
"plural",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"vars",
")",
">",
"1",
"{",
"plural",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"keys",
":=",
"make",
"(",
"sort",
".",
"StringSlice",
",",
"0",
",",
"len",
"(",
"vars",
")",
")",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"vars",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"string",
"(",
"k",
")",
")",
"\n",
"if",
"v",
"==",
"nil",
"{",
"verb",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"keys",
".",
"Sort",
"(",
")",
"\n",
"desc",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"verb",
",",
"strings",
".",
"Join",
"(",
"keys",
",",
"\"",
"\"",
")",
",",
"plural",
")",
"\n",
"return",
"appendMessageToDescription",
"(",
"desc",
",",
"opts",
".",
"User",
",",
"opts",
".",
"Message",
")",
"\n",
"}"
] |
// configsApplyReleaseDesc formats a release description based on the config variables
// being applied.
|
[
"configsApplyReleaseDesc",
"formats",
"a",
"release",
"description",
"based",
"on",
"the",
"config",
"variables",
"being",
"applied",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/configs.go#L209-L227
|
train
|
remind101/empire
|
stats/stats.go
|
WithStats
|
func WithStats(ctx context.Context, stats Stats) context.Context {
return context.WithValue(ctx, statsKey, stats)
}
|
go
|
func WithStats(ctx context.Context, stats Stats) context.Context {
return context.WithValue(ctx, statsKey, stats)
}
|
[
"func",
"WithStats",
"(",
"ctx",
"context",
".",
"Context",
",",
"stats",
"Stats",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"statsKey",
",",
"stats",
")",
"\n",
"}"
] |
// WithStats returns a new context.Context with the Stats implementation
// embedded.
|
[
"WithStats",
"returns",
"a",
"new",
"context",
".",
"Context",
"with",
"the",
"Stats",
"implementation",
"embedded",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/stats.go#L63-L65
|
train
|
remind101/empire
|
stats/stats.go
|
FromContext
|
func FromContext(ctx context.Context) (Stats, bool) {
stats, ok := ctx.Value(statsKey).(Stats)
return stats, ok
}
|
go
|
func FromContext(ctx context.Context) (Stats, bool) {
stats, ok := ctx.Value(statsKey).(Stats)
return stats, ok
}
|
[
"func",
"FromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"Stats",
",",
"bool",
")",
"{",
"stats",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"statsKey",
")",
".",
"(",
"Stats",
")",
"\n",
"return",
"stats",
",",
"ok",
"\n",
"}"
] |
// FromContext returns the Stats implementation that's embedded in the context.
|
[
"FromContext",
"returns",
"the",
"Stats",
"implementation",
"that",
"s",
"embedded",
"in",
"the",
"context",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/stats.go#L68-L71
|
train
|
remind101/empire
|
stats/stats.go
|
WithTags
|
func WithTags(ctx context.Context, tags []string) context.Context {
stats, ok := FromContext(ctx)
if !ok {
return ctx
}
return WithStats(ctx, &taggedStats{tags, stats})
}
|
go
|
func WithTags(ctx context.Context, tags []string) context.Context {
stats, ok := FromContext(ctx)
if !ok {
return ctx
}
return WithStats(ctx, &taggedStats{tags, stats})
}
|
[
"func",
"WithTags",
"(",
"ctx",
"context",
".",
"Context",
",",
"tags",
"[",
"]",
"string",
")",
"context",
".",
"Context",
"{",
"stats",
",",
"ok",
":=",
"FromContext",
"(",
"ctx",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"ctx",
"\n",
"}",
"\n",
"return",
"WithStats",
"(",
"ctx",
",",
"&",
"taggedStats",
"{",
"tags",
",",
"stats",
"}",
")",
"\n",
"}"
] |
// WithTags will return a context.Context where all metrics recorded with the
// embedded Stats implementation will include the given stats.
|
[
"WithTags",
"will",
"return",
"a",
"context",
".",
"Context",
"where",
"all",
"metrics",
"recorded",
"with",
"the",
"embedded",
"Stats",
"implementation",
"will",
"include",
"the",
"given",
"stats",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/stats.go#L75-L81
|
train
|
remind101/empire
|
domains.go
|
domainsFind
|
func domainsFind(db *gorm.DB, scope scope) (*Domain, error) {
var domain Domain
return &domain, first(db, scope, &domain)
}
|
go
|
func domainsFind(db *gorm.DB, scope scope) (*Domain, error) {
var domain Domain
return &domain, first(db, scope, &domain)
}
|
[
"func",
"domainsFind",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"var",
"domain",
"Domain",
"\n",
"return",
"&",
"domain",
",",
"first",
"(",
"db",
",",
"scope",
",",
"&",
"domain",
")",
"\n",
"}"
] |
// domainsFind returns the first matching domain.
|
[
"domainsFind",
"returns",
"the",
"first",
"matching",
"domain",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/domains.go#L103-L106
|
train
|
remind101/empire
|
domains.go
|
domains
|
func domains(db *gorm.DB, scope scope) ([]*Domain, error) {
var domains []*Domain
return domains, find(db, scope, &domains)
}
|
go
|
func domains(db *gorm.DB, scope scope) ([]*Domain, error) {
var domains []*Domain
return domains, find(db, scope, &domains)
}
|
[
"func",
"domains",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
")",
"(",
"[",
"]",
"*",
"Domain",
",",
"error",
")",
"{",
"var",
"domains",
"[",
"]",
"*",
"Domain",
"\n",
"return",
"domains",
",",
"find",
"(",
"db",
",",
"scope",
",",
"&",
"domains",
")",
"\n",
"}"
] |
// domains returns all domains matching the scope.
|
[
"domains",
"returns",
"all",
"domains",
"matching",
"the",
"scope",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/domains.go#L109-L112
|
train
|
remind101/empire
|
pkg/heroku/config_var.go
|
ConfigVarInfo
|
func (c *Client) ConfigVarInfo(appIdentity string) (map[string]string, error) {
var configVar map[string]string
return configVar, c.Get(&configVar, "/apps/"+appIdentity+"/config-vars")
}
|
go
|
func (c *Client) ConfigVarInfo(appIdentity string) (map[string]string, error) {
var configVar map[string]string
return configVar, c.Get(&configVar, "/apps/"+appIdentity+"/config-vars")
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ConfigVarInfo",
"(",
"appIdentity",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"configVar",
"map",
"[",
"string",
"]",
"string",
"\n",
"return",
"configVar",
",",
"c",
".",
"Get",
"(",
"&",
"configVar",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
")",
"\n",
"}"
] |
// Get config-vars for app.
//
// appIdentity is the unique identifier of the ConfigVar's App.
|
[
"Get",
"config",
"-",
"vars",
"for",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"ConfigVar",
"s",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/config_var.go#L12-L15
|
train
|
remind101/empire
|
pkg/heroku/config_var.go
|
ConfigVarInfoByReleaseVersion
|
func (c *Client) ConfigVarInfoByReleaseVersion(appIdentity, version string) (map[string]string, error) {
var configVar map[string]string
return configVar, c.Get(&configVar, fmt.Sprintf("/apps/%s/config-vars/%s", appIdentity, version))
}
|
go
|
func (c *Client) ConfigVarInfoByReleaseVersion(appIdentity, version string) (map[string]string, error) {
var configVar map[string]string
return configVar, c.Get(&configVar, fmt.Sprintf("/apps/%s/config-vars/%s", appIdentity, version))
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"ConfigVarInfoByReleaseVersion",
"(",
"appIdentity",
",",
"version",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"var",
"configVar",
"map",
"[",
"string",
"]",
"string",
"\n",
"return",
"configVar",
",",
"c",
".",
"Get",
"(",
"&",
"configVar",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"appIdentity",
",",
"version",
")",
")",
"\n",
"}"
] |
// Get config-vars for app and release.
//
// appIdentity is the unique identifier of the ConfigVar's App.
// version is the release version of the app.
|
[
"Get",
"config",
"-",
"vars",
"for",
"app",
"and",
"release",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"ConfigVar",
"s",
"App",
".",
"version",
"is",
"the",
"release",
"version",
"of",
"the",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/config_var.go#L21-L24
|
train
|
remind101/empire
|
cmd/emp/dynos.go
|
quote
|
func quote(s string) string {
b, _ := json.Marshal(s)
return string(b)
}
|
go
|
func quote(s string) string {
b, _ := json.Marshal(s)
return string(b)
}
|
[
"func",
"quote",
"(",
"s",
"string",
")",
"string",
"{",
"b",
",",
"_",
":=",
"json",
".",
"Marshal",
"(",
"s",
")",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] |
// quotes s as a json string
|
[
"quotes",
"s",
"as",
"a",
"json",
"string"
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/cmd/emp/dynos.go#L80-L83
|
train
|
remind101/empire
|
pkg/heroku/account_feature.go
|
AccountFeatureInfo
|
func (c *Client) AccountFeatureInfo(accountFeatureIdentity string) (*AccountFeature, error) {
var accountFeature AccountFeature
return &accountFeature, c.Get(&accountFeature, "/account/features/"+accountFeatureIdentity)
}
|
go
|
func (c *Client) AccountFeatureInfo(accountFeatureIdentity string) (*AccountFeature, error) {
var accountFeature AccountFeature
return &accountFeature, c.Get(&accountFeature, "/account/features/"+accountFeatureIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AccountFeatureInfo",
"(",
"accountFeatureIdentity",
"string",
")",
"(",
"*",
"AccountFeature",
",",
"error",
")",
"{",
"var",
"accountFeature",
"AccountFeature",
"\n",
"return",
"&",
"accountFeature",
",",
"c",
".",
"Get",
"(",
"&",
"accountFeature",
",",
"\"",
"\"",
"+",
"accountFeatureIdentity",
")",
"\n",
"}"
] |
// Info for an existing account feature.
//
// accountFeatureIdentity is the unique identifier of the AccountFeature.
|
[
"Info",
"for",
"an",
"existing",
"account",
"feature",
".",
"accountFeatureIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AccountFeature",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/account_feature.go#L42-L45
|
train
|
remind101/empire
|
pkg/heroku/account_feature.go
|
AccountFeatureList
|
func (c *Client) AccountFeatureList(lr *ListRange) ([]AccountFeature, error) {
req, err := c.NewRequest("GET", "/account/features", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var accountFeaturesRes []AccountFeature
return accountFeaturesRes, c.DoReq(req, &accountFeaturesRes)
}
|
go
|
func (c *Client) AccountFeatureList(lr *ListRange) ([]AccountFeature, error) {
req, err := c.NewRequest("GET", "/account/features", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var accountFeaturesRes []AccountFeature
return accountFeaturesRes, c.DoReq(req, &accountFeaturesRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AccountFeatureList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"AccountFeature",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"accountFeaturesRes",
"[",
"]",
"AccountFeature",
"\n",
"return",
"accountFeaturesRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"accountFeaturesRes",
")",
"\n",
"}"
] |
// List existing account features.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results.
|
[
"List",
"existing",
"account",
"features",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/account_feature.go#L51-L63
|
train
|
remind101/empire
|
pkg/heroku/account_feature.go
|
AccountFeatureUpdate
|
func (c *Client) AccountFeatureUpdate(accountFeatureIdentity string, enabled bool) (*AccountFeature, error) {
params := struct {
Enabled bool `json:"enabled"`
}{
Enabled: enabled,
}
var accountFeatureRes AccountFeature
return &accountFeatureRes, c.Patch(&accountFeatureRes, "/account/features/"+accountFeatureIdentity, params)
}
|
go
|
func (c *Client) AccountFeatureUpdate(accountFeatureIdentity string, enabled bool) (*AccountFeature, error) {
params := struct {
Enabled bool `json:"enabled"`
}{
Enabled: enabled,
}
var accountFeatureRes AccountFeature
return &accountFeatureRes, c.Patch(&accountFeatureRes, "/account/features/"+accountFeatureIdentity, params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AccountFeatureUpdate",
"(",
"accountFeatureIdentity",
"string",
",",
"enabled",
"bool",
")",
"(",
"*",
"AccountFeature",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Enabled",
"bool",
"`json:\"enabled\"`",
"\n",
"}",
"{",
"Enabled",
":",
"enabled",
",",
"}",
"\n",
"var",
"accountFeatureRes",
"AccountFeature",
"\n",
"return",
"&",
"accountFeatureRes",
",",
"c",
".",
"Patch",
"(",
"&",
"accountFeatureRes",
",",
"\"",
"\"",
"+",
"accountFeatureIdentity",
",",
"params",
")",
"\n",
"}"
] |
// Update an existing account feature.
//
// accountFeatureIdentity is the unique identifier of the AccountFeature.
// enabled is the whether or not account feature has been enabled.
|
[
"Update",
"an",
"existing",
"account",
"feature",
".",
"accountFeatureIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AccountFeature",
".",
"enabled",
"is",
"the",
"whether",
"or",
"not",
"account",
"feature",
"has",
"been",
"enabled",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/account_feature.go#L69-L77
|
train
|
remind101/empire
|
db.go
|
OpenDB
|
func OpenDB(uri string) (*DB, error) {
_, err := url.Parse(uri)
if err != nil {
return nil, err
}
conn, err := sql.Open(DBDriver, uri)
if err != nil {
return nil, err
}
return NewDB(conn)
}
|
go
|
func OpenDB(uri string) (*DB, error) {
_, err := url.Parse(uri)
if err != nil {
return nil, err
}
conn, err := sql.Open(DBDriver, uri)
if err != nil {
return nil, err
}
return NewDB(conn)
}
|
[
"func",
"OpenDB",
"(",
"uri",
"string",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"conn",
",",
"err",
":=",
"sql",
".",
"Open",
"(",
"DBDriver",
",",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewDB",
"(",
"conn",
")",
"\n",
"}"
] |
// OpenDB returns a new gorm.DB instance.
|
[
"OpenDB",
"returns",
"a",
"new",
"gorm",
".",
"DB",
"instance",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L42-L54
|
train
|
remind101/empire
|
db.go
|
NewDB
|
func NewDB(conn *sql.DB) (*DB, error) {
db, err := gorm.Open(DBDriver, conn)
if err != nil {
return nil, err
}
m := migrate.NewPostgresMigrator(conn)
// Run all migrations in a single transaction, so they will be rolled
// back as one. This is almost always the behavior that users would want
// when upgrading Empire. If a new release has multiple migrations, and
// one of those fails, it's easier for them if the entire upgrade rolls
// back instead of getting stuck in failed state.
m.TransactionMode = migrate.SingleTransaction
return &DB{
DB: &db,
migrator: m,
}, nil
}
|
go
|
func NewDB(conn *sql.DB) (*DB, error) {
db, err := gorm.Open(DBDriver, conn)
if err != nil {
return nil, err
}
m := migrate.NewPostgresMigrator(conn)
// Run all migrations in a single transaction, so they will be rolled
// back as one. This is almost always the behavior that users would want
// when upgrading Empire. If a new release has multiple migrations, and
// one of those fails, it's easier for them if the entire upgrade rolls
// back instead of getting stuck in failed state.
m.TransactionMode = migrate.SingleTransaction
return &DB{
DB: &db,
migrator: m,
}, nil
}
|
[
"func",
"NewDB",
"(",
"conn",
"*",
"sql",
".",
"DB",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"db",
",",
"err",
":=",
"gorm",
".",
"Open",
"(",
"DBDriver",
",",
"conn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"m",
":=",
"migrate",
".",
"NewPostgresMigrator",
"(",
"conn",
")",
"\n",
"// Run all migrations in a single transaction, so they will be rolled",
"// back as one. This is almost always the behavior that users would want",
"// when upgrading Empire. If a new release has multiple migrations, and",
"// one of those fails, it's easier for them if the entire upgrade rolls",
"// back instead of getting stuck in failed state.",
"m",
".",
"TransactionMode",
"=",
"migrate",
".",
"SingleTransaction",
"\n\n",
"return",
"&",
"DB",
"{",
"DB",
":",
"&",
"db",
",",
"migrator",
":",
"m",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewDB wraps a sql.DB instance as a DB.
|
[
"NewDB",
"wraps",
"a",
"sql",
".",
"DB",
"instance",
"as",
"a",
"DB",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L57-L75
|
train
|
remind101/empire
|
db.go
|
MigrateUp
|
func (db *DB) MigrateUp() error {
return db.migrator.Exec(migrate.Up, db.migrations()...)
}
|
go
|
func (db *DB) MigrateUp() error {
return db.migrator.Exec(migrate.Up, db.migrations()...)
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"MigrateUp",
"(",
")",
"error",
"{",
"return",
"db",
".",
"migrator",
".",
"Exec",
"(",
"migrate",
".",
"Up",
",",
"db",
".",
"migrations",
"(",
")",
"...",
")",
"\n",
"}"
] |
// MigrateUp migrates the database to the latest version of the schema.
|
[
"MigrateUp",
"migrates",
"the",
"database",
"to",
"the",
"latest",
"version",
"of",
"the",
"schema",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L78-L80
|
train
|
remind101/empire
|
db.go
|
Reset
|
func (db *DB) Reset() error {
var err error
exec := func(sql string) {
if err == nil {
err = db.Exec(sql).Error
}
}
exec(`TRUNCATE TABLE apps CASCADE`)
exec(`TRUNCATE TABLE ports CASCADE`)
exec(`TRUNCATE TABLE slugs CASCADE`)
exec(`UPDATE ports SET app_id = NULL`)
return err
}
|
go
|
func (db *DB) Reset() error {
var err error
exec := func(sql string) {
if err == nil {
err = db.Exec(sql).Error
}
}
exec(`TRUNCATE TABLE apps CASCADE`)
exec(`TRUNCATE TABLE ports CASCADE`)
exec(`TRUNCATE TABLE slugs CASCADE`)
exec(`UPDATE ports SET app_id = NULL`)
return err
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"Reset",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"exec",
":=",
"func",
"(",
"sql",
"string",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"db",
".",
"Exec",
"(",
"sql",
")",
".",
"Error",
"\n",
"}",
"\n",
"}",
"\n\n",
"exec",
"(",
"`TRUNCATE TABLE apps CASCADE`",
")",
"\n",
"exec",
"(",
"`TRUNCATE TABLE ports CASCADE`",
")",
"\n",
"exec",
"(",
"`TRUNCATE TABLE slugs CASCADE`",
")",
"\n",
"exec",
"(",
"`UPDATE ports SET app_id = NULL`",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// Reset resets the database to a pristine state.
|
[
"Reset",
"resets",
"the",
"database",
"to",
"a",
"pristine",
"state",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L87-L101
|
train
|
remind101/empire
|
db.go
|
IsHealthy
|
func (db *DB) IsHealthy() error {
if err := db.DB.DB().Ping(); err != nil {
return err
}
if err := db.CheckSchemaVersion(); err != nil {
return err
}
return nil
}
|
go
|
func (db *DB) IsHealthy() error {
if err := db.DB.DB().Ping(); err != nil {
return err
}
if err := db.CheckSchemaVersion(); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"IsHealthy",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"db",
".",
"DB",
".",
"DB",
"(",
")",
".",
"Ping",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"db",
".",
"CheckSchemaVersion",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// IsHealthy checks that we can connect to the database.
|
[
"IsHealthy",
"checks",
"that",
"we",
"can",
"connect",
"to",
"the",
"database",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L104-L114
|
train
|
remind101/empire
|
db.go
|
CheckSchemaVersion
|
func (db *DB) CheckSchemaVersion() error {
schemaVersion, err := db.SchemaVersion()
if err != nil {
return fmt.Errorf("error fetching schema version: %v", err)
}
expectedSchemaVersion := db.schema().latestSchema()
if schemaVersion != expectedSchemaVersion {
return &IncompatibleSchemaError{
SchemaVersion: schemaVersion,
ExpectedSchemaVersion: expectedSchemaVersion,
}
}
return nil
}
|
go
|
func (db *DB) CheckSchemaVersion() error {
schemaVersion, err := db.SchemaVersion()
if err != nil {
return fmt.Errorf("error fetching schema version: %v", err)
}
expectedSchemaVersion := db.schema().latestSchema()
if schemaVersion != expectedSchemaVersion {
return &IncompatibleSchemaError{
SchemaVersion: schemaVersion,
ExpectedSchemaVersion: expectedSchemaVersion,
}
}
return nil
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"CheckSchemaVersion",
"(",
")",
"error",
"{",
"schemaVersion",
",",
"err",
":=",
"db",
".",
"SchemaVersion",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"expectedSchemaVersion",
":=",
"db",
".",
"schema",
"(",
")",
".",
"latestSchema",
"(",
")",
"\n",
"if",
"schemaVersion",
"!=",
"expectedSchemaVersion",
"{",
"return",
"&",
"IncompatibleSchemaError",
"{",
"SchemaVersion",
":",
"schemaVersion",
",",
"ExpectedSchemaVersion",
":",
"expectedSchemaVersion",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// CheckSchemaVersion verifies that the actual database schema matches the
// version that this version of Empire expects.
|
[
"CheckSchemaVersion",
"verifies",
"that",
"the",
"actual",
"database",
"schema",
"matches",
"the",
"version",
"that",
"this",
"version",
"of",
"Empire",
"expects",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L118-L133
|
train
|
remind101/empire
|
db.go
|
SchemaVersion
|
func (db *DB) SchemaVersion() (int, error) {
sql := `select version from schema_migrations order by version desc limit 1`
var schemaVersion int
err := db.DB.DB().QueryRow(sql).Scan(&schemaVersion)
return schemaVersion, err
}
|
go
|
func (db *DB) SchemaVersion() (int, error) {
sql := `select version from schema_migrations order by version desc limit 1`
var schemaVersion int
err := db.DB.DB().QueryRow(sql).Scan(&schemaVersion)
return schemaVersion, err
}
|
[
"func",
"(",
"db",
"*",
"DB",
")",
"SchemaVersion",
"(",
")",
"(",
"int",
",",
"error",
")",
"{",
"sql",
":=",
"`select version from schema_migrations order by version desc limit 1`",
"\n",
"var",
"schemaVersion",
"int",
"\n",
"err",
":=",
"db",
".",
"DB",
".",
"DB",
"(",
")",
".",
"QueryRow",
"(",
"sql",
")",
".",
"Scan",
"(",
"&",
"schemaVersion",
")",
"\n",
"return",
"schemaVersion",
",",
"err",
"\n",
"}"
] |
// SchemaVersion returns the current schema version.
|
[
"SchemaVersion",
"returns",
"the",
"current",
"schema",
"version",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L136-L141
|
train
|
remind101/empire
|
db.go
|
fieldEquals
|
func fieldEquals(field string, v interface{}) scope {
return scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Where(fmt.Sprintf("%s = ?", field), v)
})
}
|
go
|
func fieldEquals(field string, v interface{}) scope {
return scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Where(fmt.Sprintf("%s = ?", field), v)
})
}
|
[
"func",
"fieldEquals",
"(",
"field",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"scope",
"{",
"return",
"scopeFunc",
"(",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"db",
".",
"Where",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"field",
")",
",",
"v",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// fieldEquals returns a scope that filters on a field.
|
[
"fieldEquals",
"returns",
"a",
"scope",
"that",
"filters",
"on",
"a",
"field",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L193-L197
|
train
|
remind101/empire
|
db.go
|
preload
|
func preload(associations ...string) scope {
var scope composedScope
for _, a := range associations {
aa := a
scope = append(scope, scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Preload(aa)
}))
}
return scope
}
|
go
|
func preload(associations ...string) scope {
var scope composedScope
for _, a := range associations {
aa := a
scope = append(scope, scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Preload(aa)
}))
}
return scope
}
|
[
"func",
"preload",
"(",
"associations",
"...",
"string",
")",
"scope",
"{",
"var",
"scope",
"composedScope",
"\n\n",
"for",
"_",
",",
"a",
":=",
"range",
"associations",
"{",
"aa",
":=",
"a",
"\n",
"scope",
"=",
"append",
"(",
"scope",
",",
"scopeFunc",
"(",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"db",
".",
"Preload",
"(",
"aa",
")",
"\n",
"}",
")",
")",
"\n",
"}",
"\n\n",
"return",
"scope",
"\n",
"}"
] |
// preload returns a scope that preloads the associations.
|
[
"preload",
"returns",
"a",
"scope",
"that",
"preloads",
"the",
"associations",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L206-L217
|
train
|
remind101/empire
|
db.go
|
order
|
func order(order string) scope {
return scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Order(order)
})
}
|
go
|
func order(order string) scope {
return scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Order(order)
})
}
|
[
"func",
"order",
"(",
"order",
"string",
")",
"scope",
"{",
"return",
"scopeFunc",
"(",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"db",
".",
"Order",
"(",
"order",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// order returns a scope that orders the results.
|
[
"order",
"returns",
"a",
"scope",
"that",
"orders",
"the",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L220-L224
|
train
|
remind101/empire
|
db.go
|
limit
|
func limit(limit int) scope {
return scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Limit(limit)
})
}
|
go
|
func limit(limit int) scope {
return scopeFunc(func(db *gorm.DB) *gorm.DB {
return db.Limit(limit)
})
}
|
[
"func",
"limit",
"(",
"limit",
"int",
")",
"scope",
"{",
"return",
"scopeFunc",
"(",
"func",
"(",
"db",
"*",
"gorm",
".",
"DB",
")",
"*",
"gorm",
".",
"DB",
"{",
"return",
"db",
".",
"Limit",
"(",
"limit",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// limit returns a scope that limits the results.
|
[
"limit",
"returns",
"a",
"scope",
"that",
"limits",
"the",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L227-L231
|
train
|
remind101/empire
|
db.go
|
inRange
|
func inRange(r headerutil.Range) scope {
var scope composedScope
if r.Max != nil {
scope = append(scope, limit(*r.Max))
}
if r.Sort != nil && r.Order != nil {
o := fmt.Sprintf("%s %s", *r.Sort, *r.Order)
scope = append(scope, order(o))
}
return scope
}
|
go
|
func inRange(r headerutil.Range) scope {
var scope composedScope
if r.Max != nil {
scope = append(scope, limit(*r.Max))
}
if r.Sort != nil && r.Order != nil {
o := fmt.Sprintf("%s %s", *r.Sort, *r.Order)
scope = append(scope, order(o))
}
return scope
}
|
[
"func",
"inRange",
"(",
"r",
"headerutil",
".",
"Range",
")",
"scope",
"{",
"var",
"scope",
"composedScope",
"\n\n",
"if",
"r",
".",
"Max",
"!=",
"nil",
"{",
"scope",
"=",
"append",
"(",
"scope",
",",
"limit",
"(",
"*",
"r",
".",
"Max",
")",
")",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"Sort",
"!=",
"nil",
"&&",
"r",
".",
"Order",
"!=",
"nil",
"{",
"o",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"r",
".",
"Sort",
",",
"*",
"r",
".",
"Order",
")",
"\n",
"scope",
"=",
"append",
"(",
"scope",
",",
"order",
"(",
"o",
")",
")",
"\n",
"}",
"\n\n",
"return",
"scope",
"\n",
"}"
] |
// inRange returns a scope that limits and orders the results.
|
[
"inRange",
"returns",
"a",
"scope",
"that",
"limits",
"and",
"orders",
"the",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L234-L247
|
train
|
remind101/empire
|
db.go
|
first
|
func first(db *gorm.DB, scope scope, v interface{}) error {
return scope.scope(db).First(v).Error
}
|
go
|
func first(db *gorm.DB, scope scope, v interface{}) error {
return scope.scope(db).First(v).Error
}
|
[
"func",
"first",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"scope",
".",
"scope",
"(",
"db",
")",
".",
"First",
"(",
"v",
")",
".",
"Error",
"\n",
"}"
] |
// first is a small helper that finds the first record matching a scope, and
// returns the error.
|
[
"first",
"is",
"a",
"small",
"helper",
"that",
"finds",
"the",
"first",
"record",
"matching",
"a",
"scope",
"and",
"returns",
"the",
"error",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L251-L253
|
train
|
remind101/empire
|
db.go
|
find
|
func find(db *gorm.DB, scope scope, v interface{}) error {
return scope.scope(db).Find(v).Error
}
|
go
|
func find(db *gorm.DB, scope scope, v interface{}) error {
return scope.scope(db).Find(v).Error
}
|
[
"func",
"find",
"(",
"db",
"*",
"gorm",
".",
"DB",
",",
"scope",
"scope",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"scope",
".",
"scope",
"(",
"db",
")",
".",
"Find",
"(",
"v",
")",
".",
"Error",
"\n",
"}"
] |
// find is a small helper that finds records matching the scope, and returns the
// error.
|
[
"find",
"is",
"a",
"small",
"helper",
"that",
"finds",
"records",
"matching",
"the",
"scope",
"and",
"returns",
"the",
"error",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/db.go#L257-L259
|
train
|
remind101/empire
|
pkg/dockerutil/dockerutil.go
|
FakePull
|
func FakePull(img image.Image, w io.Writer) error {
messages := []jsonmessage.JSONMessage{
{Status: fmt.Sprintf("Pulling repository %s", img.Repository)},
{Status: fmt.Sprintf("Pulling image (%s) from %s", img.Tag, img.Repository), Progress: &jsonmessage.JSONProgress{}, ID: "345c7524bc96"},
{Status: fmt.Sprintf("Pulling image (%s) from %s, endpoint: https://registry-1.docker.io/v1/", img.Tag, img.Repository), Progress: &jsonmessage.JSONProgress{}, ID: "345c7524bc96"},
{Status: "Pulling dependent layers", Progress: &jsonmessage.JSONProgress{}, ID: "345c7524bc96"},
{Status: "Download complete", Progress: &jsonmessage.JSONProgress{}, ID: "a1dd7097a8e8"},
{Status: fmt.Sprintf("Status: Image is up to date for %s", img)},
}
enc := json.NewEncoder(w)
for _, m := range messages {
if err := enc.Encode(&m); err != nil {
return err
}
}
return nil
}
|
go
|
func FakePull(img image.Image, w io.Writer) error {
messages := []jsonmessage.JSONMessage{
{Status: fmt.Sprintf("Pulling repository %s", img.Repository)},
{Status: fmt.Sprintf("Pulling image (%s) from %s", img.Tag, img.Repository), Progress: &jsonmessage.JSONProgress{}, ID: "345c7524bc96"},
{Status: fmt.Sprintf("Pulling image (%s) from %s, endpoint: https://registry-1.docker.io/v1/", img.Tag, img.Repository), Progress: &jsonmessage.JSONProgress{}, ID: "345c7524bc96"},
{Status: "Pulling dependent layers", Progress: &jsonmessage.JSONProgress{}, ID: "345c7524bc96"},
{Status: "Download complete", Progress: &jsonmessage.JSONProgress{}, ID: "a1dd7097a8e8"},
{Status: fmt.Sprintf("Status: Image is up to date for %s", img)},
}
enc := json.NewEncoder(w)
for _, m := range messages {
if err := enc.Encode(&m); err != nil {
return err
}
}
return nil
}
|
[
"func",
"FakePull",
"(",
"img",
"image",
".",
"Image",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"messages",
":=",
"[",
"]",
"jsonmessage",
".",
"JSONMessage",
"{",
"{",
"Status",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Repository",
")",
"}",
",",
"{",
"Status",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Tag",
",",
"img",
".",
"Repository",
")",
",",
"Progress",
":",
"&",
"jsonmessage",
".",
"JSONProgress",
"{",
"}",
",",
"ID",
":",
"\"",
"\"",
"}",
",",
"{",
"Status",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"Tag",
",",
"img",
".",
"Repository",
")",
",",
"Progress",
":",
"&",
"jsonmessage",
".",
"JSONProgress",
"{",
"}",
",",
"ID",
":",
"\"",
"\"",
"}",
",",
"{",
"Status",
":",
"\"",
"\"",
",",
"Progress",
":",
"&",
"jsonmessage",
".",
"JSONProgress",
"{",
"}",
",",
"ID",
":",
"\"",
"\"",
"}",
",",
"{",
"Status",
":",
"\"",
"\"",
",",
"Progress",
":",
"&",
"jsonmessage",
".",
"JSONProgress",
"{",
"}",
",",
"ID",
":",
"\"",
"\"",
"}",
",",
"{",
"Status",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
")",
"}",
",",
"}",
"\n\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n\n",
"for",
"_",
",",
"m",
":=",
"range",
"messages",
"{",
"if",
"err",
":=",
"enc",
".",
"Encode",
"(",
"&",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// FakePull writes a jsonmessage stream to w that looks like a Docker pull.
|
[
"FakePull",
"writes",
"a",
"jsonmessage",
"stream",
"to",
"w",
"that",
"looks",
"like",
"a",
"Docker",
"pull",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/dockerutil.go#L16-L35
|
train
|
remind101/empire
|
pkg/dockerutil/dockerutil.go
|
PullImageOptions
|
func PullImageOptions(img image.Image) (docker.PullImageOptions, error) {
var options docker.PullImageOptions
// From the Docker API docs:
//
// Tag or digest. If empty when pulling an image, this
// causes all tags for the given image to be pulled.
//
// So, we prefer the digest if it's provided.
tag := img.Digest
if tag == "" {
tag = img.Tag
}
// If there's no tag or digest, error out. Providing an empty
// tag to DockerPull will pull all images, which we don't want.
if tag == "" {
return options, fmt.Errorf("no tag or digest provided")
}
options.Tag = tag
options.Repository = img.Repository
// Only required for Docker Engine 1.9 or 1.10 w/ Remote API < 1.21
// and Docker Engine < 1.9
// This parameter was removed in Docker Engine 1.11
//
// See https://goo.gl/9y9Bpx
options.Registry = img.Registry
return options, nil
}
|
go
|
func PullImageOptions(img image.Image) (docker.PullImageOptions, error) {
var options docker.PullImageOptions
// From the Docker API docs:
//
// Tag or digest. If empty when pulling an image, this
// causes all tags for the given image to be pulled.
//
// So, we prefer the digest if it's provided.
tag := img.Digest
if tag == "" {
tag = img.Tag
}
// If there's no tag or digest, error out. Providing an empty
// tag to DockerPull will pull all images, which we don't want.
if tag == "" {
return options, fmt.Errorf("no tag or digest provided")
}
options.Tag = tag
options.Repository = img.Repository
// Only required for Docker Engine 1.9 or 1.10 w/ Remote API < 1.21
// and Docker Engine < 1.9
// This parameter was removed in Docker Engine 1.11
//
// See https://goo.gl/9y9Bpx
options.Registry = img.Registry
return options, nil
}
|
[
"func",
"PullImageOptions",
"(",
"img",
"image",
".",
"Image",
")",
"(",
"docker",
".",
"PullImageOptions",
",",
"error",
")",
"{",
"var",
"options",
"docker",
".",
"PullImageOptions",
"\n\n",
"// From the Docker API docs:",
"//",
"//\tTag or digest. If empty when pulling an image, this",
"//\tcauses all tags for the given image to be pulled.",
"//",
"// So, we prefer the digest if it's provided.",
"tag",
":=",
"img",
".",
"Digest",
"\n",
"if",
"tag",
"==",
"\"",
"\"",
"{",
"tag",
"=",
"img",
".",
"Tag",
"\n",
"}",
"\n\n",
"// If there's no tag or digest, error out. Providing an empty",
"// tag to DockerPull will pull all images, which we don't want.",
"if",
"tag",
"==",
"\"",
"\"",
"{",
"return",
"options",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"options",
".",
"Tag",
"=",
"tag",
"\n",
"options",
".",
"Repository",
"=",
"img",
".",
"Repository",
"\n\n",
"// Only required for Docker Engine 1.9 or 1.10 w/ Remote API < 1.21",
"// and Docker Engine < 1.9",
"// This parameter was removed in Docker Engine 1.11",
"//",
"// See https://goo.gl/9y9Bpx",
"options",
".",
"Registry",
"=",
"img",
".",
"Registry",
"\n\n",
"return",
"options",
",",
"nil",
"\n",
"}"
] |
// PullImageOptions generates an appropriate docker.PullImageOptions to pull the
// target image based on the idiosyncrasies of docker.
|
[
"PullImageOptions",
"generates",
"an",
"appropriate",
"docker",
".",
"PullImageOptions",
"to",
"pull",
"the",
"target",
"image",
"based",
"on",
"the",
"idiosyncrasies",
"of",
"docker",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/dockerutil.go#L39-L70
|
train
|
remind101/empire
|
pkg/dockerutil/dockerutil.go
|
DecodeJSONMessageStream
|
func DecodeJSONMessageStream(w io.Writer) *DecodedJSONMessageWriter {
outFd, _ := term.GetFdInfo(w)
return &DecodedJSONMessageWriter{
w: w,
fd: outFd,
}
}
|
go
|
func DecodeJSONMessageStream(w io.Writer) *DecodedJSONMessageWriter {
outFd, _ := term.GetFdInfo(w)
return &DecodedJSONMessageWriter{
w: w,
fd: outFd,
}
}
|
[
"func",
"DecodeJSONMessageStream",
"(",
"w",
"io",
".",
"Writer",
")",
"*",
"DecodedJSONMessageWriter",
"{",
"outFd",
",",
"_",
":=",
"term",
".",
"GetFdInfo",
"(",
"w",
")",
"\n",
"return",
"&",
"DecodedJSONMessageWriter",
"{",
"w",
":",
"w",
",",
"fd",
":",
"outFd",
",",
"}",
"\n",
"}"
] |
// DecodeJSONMessageStream wraps an io.Writer to decode a jsonmessage stream into
// plain text. Bytes written to w represent the decoded plain text stream.
|
[
"DecodeJSONMessageStream",
"wraps",
"an",
"io",
".",
"Writer",
"to",
"decode",
"a",
"jsonmessage",
"stream",
"into",
"plain",
"text",
".",
"Bytes",
"written",
"to",
"w",
"represent",
"the",
"decoded",
"plain",
"text",
"stream",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/dockerutil.go#L74-L80
|
train
|
remind101/empire
|
pkg/dockerutil/dockerutil.go
|
Write
|
func (w *DecodedJSONMessageWriter) Write(b []byte) (int, error) {
err := jsonmessage.DisplayJSONMessagesStream(bytes.NewReader(b), w.w, w.fd, false, nil)
if err != nil {
if err, ok := err.(*jsonmessage.JSONError); ok {
w.err = err
return len(b), nil
}
}
return len(b), err
}
|
go
|
func (w *DecodedJSONMessageWriter) Write(b []byte) (int, error) {
err := jsonmessage.DisplayJSONMessagesStream(bytes.NewReader(b), w.w, w.fd, false, nil)
if err != nil {
if err, ok := err.(*jsonmessage.JSONError); ok {
w.err = err
return len(b), nil
}
}
return len(b), err
}
|
[
"func",
"(",
"w",
"*",
"DecodedJSONMessageWriter",
")",
"Write",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"err",
":=",
"jsonmessage",
".",
"DisplayJSONMessagesStream",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
")",
",",
"w",
".",
"w",
",",
"w",
".",
"fd",
",",
"false",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"jsonmessage",
".",
"JSONError",
")",
";",
"ok",
"{",
"w",
".",
"err",
"=",
"err",
"\n",
"return",
"len",
"(",
"b",
")",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"len",
"(",
"b",
")",
",",
"err",
"\n",
"}"
] |
// Write decodes the jsonmessage stream in the bytes, and writes the decoded
// plain text to the underlying io.Writer.
|
[
"Write",
"decodes",
"the",
"jsonmessage",
"stream",
"in",
"the",
"bytes",
"and",
"writes",
"the",
"decoded",
"plain",
"text",
"to",
"the",
"underlying",
"io",
".",
"Writer",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/dockerutil.go#L95-L104
|
train
|
remind101/empire
|
pkg/heroku/organization.go
|
OrganizationList
|
func (c *Client) OrganizationList(lr *ListRange) ([]Organization, error) {
req, err := c.NewRequest("GET", "/organizations", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationsRes []Organization
return organizationsRes, c.DoReq(req, &organizationsRes)
}
|
go
|
func (c *Client) OrganizationList(lr *ListRange) ([]Organization, error) {
req, err := c.NewRequest("GET", "/organizations", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationsRes []Organization
return organizationsRes, c.DoReq(req, &organizationsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Organization",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"organizationsRes",
"[",
"]",
"Organization",
"\n",
"return",
"organizationsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"organizationsRes",
")",
"\n",
"}"
] |
// List organizations in which you are a member.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results.
|
[
"List",
"organizations",
"in",
"which",
"you",
"are",
"a",
"member",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization.go#L30-L42
|
train
|
remind101/empire
|
pkg/heroku/organization.go
|
OrganizationUpdate
|
func (c *Client) OrganizationUpdate(organizationIdentity string, options *OrganizationUpdateOpts) (*Organization, error) {
var organizationRes Organization
return &organizationRes, c.Patch(&organizationRes, "/organizations/"+organizationIdentity, options)
}
|
go
|
func (c *Client) OrganizationUpdate(organizationIdentity string, options *OrganizationUpdateOpts) (*Organization, error) {
var organizationRes Organization
return &organizationRes, c.Patch(&organizationRes, "/organizations/"+organizationIdentity, options)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationUpdate",
"(",
"organizationIdentity",
"string",
",",
"options",
"*",
"OrganizationUpdateOpts",
")",
"(",
"*",
"Organization",
",",
"error",
")",
"{",
"var",
"organizationRes",
"Organization",
"\n",
"return",
"&",
"organizationRes",
",",
"c",
".",
"Patch",
"(",
"&",
"organizationRes",
",",
"\"",
"\"",
"+",
"organizationIdentity",
",",
"options",
")",
"\n",
"}"
] |
// Set or Unset the organization as your default organization.
//
// organizationIdentity is the unique identifier of the Organization. options is
// the struct of optional parameters for this action.
|
[
"Set",
"or",
"Unset",
"the",
"organization",
"as",
"your",
"default",
"organization",
".",
"organizationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Organization",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization.go#L48-L51
|
train
|
remind101/empire
|
pkg/heroku/account.go
|
AccountUpdate
|
func (c *Client) AccountUpdate(password string, options *AccountUpdateOpts) (*Account, error) {
params := struct {
Password string `json:"password"`
AllowTracking *bool `json:"allow_tracking,omitempty"`
Beta *bool `json:"beta,omitempty"`
Name *string `json:"name,omitempty"`
}{
Password: password,
}
if options != nil {
params.AllowTracking = options.AllowTracking
params.Beta = options.Beta
params.Name = options.Name
}
var accountRes Account
return &accountRes, c.Patch(&accountRes, "/account", params)
}
|
go
|
func (c *Client) AccountUpdate(password string, options *AccountUpdateOpts) (*Account, error) {
params := struct {
Password string `json:"password"`
AllowTracking *bool `json:"allow_tracking,omitempty"`
Beta *bool `json:"beta,omitempty"`
Name *string `json:"name,omitempty"`
}{
Password: password,
}
if options != nil {
params.AllowTracking = options.AllowTracking
params.Beta = options.Beta
params.Name = options.Name
}
var accountRes Account
return &accountRes, c.Patch(&accountRes, "/account", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AccountUpdate",
"(",
"password",
"string",
",",
"options",
"*",
"AccountUpdateOpts",
")",
"(",
"*",
"Account",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Password",
"string",
"`json:\"password\"`",
"\n",
"AllowTracking",
"*",
"bool",
"`json:\"allow_tracking,omitempty\"`",
"\n",
"Beta",
"*",
"bool",
"`json:\"beta,omitempty\"`",
"\n",
"Name",
"*",
"string",
"`json:\"name,omitempty\"`",
"\n",
"}",
"{",
"Password",
":",
"password",
",",
"}",
"\n",
"if",
"options",
"!=",
"nil",
"{",
"params",
".",
"AllowTracking",
"=",
"options",
".",
"AllowTracking",
"\n",
"params",
".",
"Beta",
"=",
"options",
".",
"Beta",
"\n",
"params",
".",
"Name",
"=",
"options",
".",
"Name",
"\n",
"}",
"\n",
"var",
"accountRes",
"Account",
"\n",
"return",
"&",
"accountRes",
",",
"c",
".",
"Patch",
"(",
"&",
"accountRes",
",",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Update account.
//
// password is the current password on the account. options is the struct of
// optional parameters for this action.
|
[
"Update",
"account",
".",
"password",
"is",
"the",
"current",
"password",
"on",
"the",
"account",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/account.go#L51-L67
|
train
|
remind101/empire
|
pkg/heroku/account.go
|
AccountChangeEmail
|
func (c *Client) AccountChangeEmail(password string, email string) (*Account, error) {
params := struct {
Password string `json:"password"`
Email string `json:"email"`
}{
Password: password,
Email: email,
}
var accountRes Account
return &accountRes, c.Patch(&accountRes, "/account", params)
}
|
go
|
func (c *Client) AccountChangeEmail(password string, email string) (*Account, error) {
params := struct {
Password string `json:"password"`
Email string `json:"email"`
}{
Password: password,
Email: email,
}
var accountRes Account
return &accountRes, c.Patch(&accountRes, "/account", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AccountChangeEmail",
"(",
"password",
"string",
",",
"email",
"string",
")",
"(",
"*",
"Account",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Password",
"string",
"`json:\"password\"`",
"\n",
"Email",
"string",
"`json:\"email\"`",
"\n",
"}",
"{",
"Password",
":",
"password",
",",
"Email",
":",
"email",
",",
"}",
"\n",
"var",
"accountRes",
"Account",
"\n",
"return",
"&",
"accountRes",
",",
"c",
".",
"Patch",
"(",
"&",
"accountRes",
",",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Change Email for account.
//
// password is the current password on the account. email is the unique email
// address of account.
|
[
"Change",
"Email",
"for",
"account",
".",
"password",
"is",
"the",
"current",
"password",
"on",
"the",
"account",
".",
"email",
"is",
"the",
"unique",
"email",
"address",
"of",
"account",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/account.go#L83-L93
|
train
|
remind101/empire
|
pkg/heroku/account.go
|
AccountChangePassword
|
func (c *Client) AccountChangePassword(newPassword string, password string) (*Account, error) {
params := struct {
NewPassword string `json:"new_password"`
Password string `json:"password"`
}{
NewPassword: newPassword,
Password: password,
}
var accountRes Account
return &accountRes, c.Patch(&accountRes, "/account", params)
}
|
go
|
func (c *Client) AccountChangePassword(newPassword string, password string) (*Account, error) {
params := struct {
NewPassword string `json:"new_password"`
Password string `json:"password"`
}{
NewPassword: newPassword,
Password: password,
}
var accountRes Account
return &accountRes, c.Patch(&accountRes, "/account", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AccountChangePassword",
"(",
"newPassword",
"string",
",",
"password",
"string",
")",
"(",
"*",
"Account",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"NewPassword",
"string",
"`json:\"new_password\"`",
"\n",
"Password",
"string",
"`json:\"password\"`",
"\n",
"}",
"{",
"NewPassword",
":",
"newPassword",
",",
"Password",
":",
"password",
",",
"}",
"\n",
"var",
"accountRes",
"Account",
"\n",
"return",
"&",
"accountRes",
",",
"c",
".",
"Patch",
"(",
"&",
"accountRes",
",",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Change Password for account.
//
// newPassword is the the new password for the account when changing the
// password. password is the current password on the account.
|
[
"Change",
"Password",
"for",
"account",
".",
"newPassword",
"is",
"the",
"the",
"new",
"password",
"for",
"the",
"account",
"when",
"changing",
"the",
"password",
".",
"password",
"is",
"the",
"current",
"password",
"on",
"the",
"account",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/account.go#L99-L109
|
train
|
remind101/empire
|
cmd/empire/context.go
|
newContext
|
func newContext(c *cli.Context) (ctx *Context, err error) {
ctx = &Context{
Context: c,
netCtx: context.Background(),
}
ctx.reporter, err = newReporter(ctx)
if err != nil {
return
}
ctx.logger, err = newLogger(ctx)
if err != nil {
return
}
ctx.stats, err = newStats(ctx)
if err != nil {
return
}
ctx.netCtx = ctx.embed(ctx.netCtx)
return
}
|
go
|
func newContext(c *cli.Context) (ctx *Context, err error) {
ctx = &Context{
Context: c,
netCtx: context.Background(),
}
ctx.reporter, err = newReporter(ctx)
if err != nil {
return
}
ctx.logger, err = newLogger(ctx)
if err != nil {
return
}
ctx.stats, err = newStats(ctx)
if err != nil {
return
}
ctx.netCtx = ctx.embed(ctx.netCtx)
return
}
|
[
"func",
"newContext",
"(",
"c",
"*",
"cli",
".",
"Context",
")",
"(",
"ctx",
"*",
"Context",
",",
"err",
"error",
")",
"{",
"ctx",
"=",
"&",
"Context",
"{",
"Context",
":",
"c",
",",
"netCtx",
":",
"context",
".",
"Background",
"(",
")",
",",
"}",
"\n\n",
"ctx",
".",
"reporter",
",",
"err",
"=",
"newReporter",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ctx",
".",
"logger",
",",
"err",
"=",
"newLogger",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ctx",
".",
"stats",
",",
"err",
"=",
"newStats",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"ctx",
".",
"netCtx",
"=",
"ctx",
".",
"embed",
"(",
"ctx",
".",
"netCtx",
")",
"\n\n",
"return",
"\n",
"}"
] |
// newContext builds a new base Context object.
|
[
"newContext",
"builds",
"a",
"new",
"base",
"Context",
"object",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/cmd/empire/context.go#L43-L67
|
train
|
remind101/empire
|
cmd/empire/context.go
|
ClientConfig
|
func (c *Context) ClientConfig(serviceName string, cfgs ...*aws.Config) client.Config {
if c.awsConfigProvider == nil {
c.awsConfigProvider = newConfigProvider(c)
}
return c.awsConfigProvider.ClientConfig(serviceName, cfgs...)
}
|
go
|
func (c *Context) ClientConfig(serviceName string, cfgs ...*aws.Config) client.Config {
if c.awsConfigProvider == nil {
c.awsConfigProvider = newConfigProvider(c)
}
return c.awsConfigProvider.ClientConfig(serviceName, cfgs...)
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"ClientConfig",
"(",
"serviceName",
"string",
",",
"cfgs",
"...",
"*",
"aws",
".",
"Config",
")",
"client",
".",
"Config",
"{",
"if",
"c",
".",
"awsConfigProvider",
"==",
"nil",
"{",
"c",
".",
"awsConfigProvider",
"=",
"newConfigProvider",
"(",
"c",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"awsConfigProvider",
".",
"ClientConfig",
"(",
"serviceName",
",",
"cfgs",
"...",
")",
"\n",
"}"
] |
// ClientConfig implements the client.ConfigProvider interface. This will return
// a mostly standard client.Config, but also includes middleware that will
// generate metrics for retried requests, and enables debug mode if
// `FlagAWSDebug` is set.
|
[
"ClientConfig",
"implements",
"the",
"client",
".",
"ConfigProvider",
"interface",
".",
"This",
"will",
"return",
"a",
"mostly",
"standard",
"client",
".",
"Config",
"but",
"also",
"includes",
"middleware",
"that",
"will",
"generate",
"metrics",
"for",
"retried",
"requests",
"and",
"enables",
"debug",
"mode",
"if",
"FlagAWSDebug",
"is",
"set",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/cmd/empire/context.go#L99-L105
|
train
|
remind101/empire
|
pkg/heroku/formation.go
|
FormationInfo
|
func (c *Client) FormationInfo(appIdentity string, formationIdentity string) (*Formation, error) {
var formation Formation
return &formation, c.Get(&formation, "/apps/"+appIdentity+"/formation/"+formationIdentity)
}
|
go
|
func (c *Client) FormationInfo(appIdentity string, formationIdentity string) (*Formation, error) {
var formation Formation
return &formation, c.Get(&formation, "/apps/"+appIdentity+"/formation/"+formationIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"FormationInfo",
"(",
"appIdentity",
"string",
",",
"formationIdentity",
"string",
")",
"(",
"*",
"Formation",
",",
"error",
")",
"{",
"var",
"formation",
"Formation",
"\n",
"return",
"&",
"formation",
",",
"c",
".",
"Get",
"(",
"&",
"formation",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"formationIdentity",
")",
"\n",
"}"
] |
// Info for a process type
//
// appIdentity is the unique identifier of the Formation's App.
// formationIdentity is the unique identifier of the Formation.
|
[
"Info",
"for",
"a",
"process",
"type",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Formation",
"s",
"App",
".",
"formationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Formation",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/formation.go#L42-L45
|
train
|
remind101/empire
|
pkg/heroku/formation.go
|
FormationList
|
func (c *Client) FormationList(appIdentity string, lr *ListRange) ([]Formation, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/formation", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var formationsRes []Formation
return formationsRes, c.DoReq(req, &formationsRes)
}
|
go
|
func (c *Client) FormationList(appIdentity string, lr *ListRange) ([]Formation, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/formation", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var formationsRes []Formation
return formationsRes, c.DoReq(req, &formationsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"FormationList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Formation",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"formationsRes",
"[",
"]",
"Formation",
"\n",
"return",
"formationsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"formationsRes",
")",
"\n",
"}"
] |
// List process type formation
//
// appIdentity is the unique identifier of the Formation's App. lr is an
// optional ListRange that sets the Range options for the paginated list of
// results.
|
[
"List",
"process",
"type",
"formation",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Formation",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/formation.go#L52-L64
|
train
|
remind101/empire
|
pkg/heroku/formation.go
|
FormationBatchUpdate
|
func (c *Client) FormationBatchUpdate(appIdentity string, updates []FormationBatchUpdateOpts, message string) ([]Formation, error) {
params := struct {
Updates []FormationBatchUpdateOpts `json:"updates"`
}{
Updates: updates,
}
rh := RequestHeaders{CommitMessage: message}
var formationsRes []Formation
return formationsRes, c.PatchWithHeaders(&formationsRes, "/apps/"+appIdentity+"/formation", params, rh.Headers())
}
|
go
|
func (c *Client) FormationBatchUpdate(appIdentity string, updates []FormationBatchUpdateOpts, message string) ([]Formation, error) {
params := struct {
Updates []FormationBatchUpdateOpts `json:"updates"`
}{
Updates: updates,
}
rh := RequestHeaders{CommitMessage: message}
var formationsRes []Formation
return formationsRes, c.PatchWithHeaders(&formationsRes, "/apps/"+appIdentity+"/formation", params, rh.Headers())
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"FormationBatchUpdate",
"(",
"appIdentity",
"string",
",",
"updates",
"[",
"]",
"FormationBatchUpdateOpts",
",",
"message",
"string",
")",
"(",
"[",
"]",
"Formation",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Updates",
"[",
"]",
"FormationBatchUpdateOpts",
"`json:\"updates\"`",
"\n",
"}",
"{",
"Updates",
":",
"updates",
",",
"}",
"\n",
"rh",
":=",
"RequestHeaders",
"{",
"CommitMessage",
":",
"message",
"}",
"\n",
"var",
"formationsRes",
"[",
"]",
"Formation",
"\n",
"return",
"formationsRes",
",",
"c",
".",
"PatchWithHeaders",
"(",
"&",
"formationsRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"params",
",",
"rh",
".",
"Headers",
"(",
")",
")",
"\n",
"}"
] |
// Batch update process types
//
// appIdentity is the unique identifier of the Formation's App. updates is the
// Array with formation updates. Each element must have "process", the id or
// name of the process type to be updated, and can optionally update its
// "quantity" or "size".
|
[
"Batch",
"update",
"process",
"types",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Formation",
"s",
"App",
".",
"updates",
"is",
"the",
"Array",
"with",
"formation",
"updates",
".",
"Each",
"element",
"must",
"have",
"process",
"the",
"id",
"or",
"name",
"of",
"the",
"process",
"type",
"to",
"be",
"updated",
"and",
"can",
"optionally",
"update",
"its",
"quantity",
"or",
"size",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/formation.go#L72-L81
|
train
|
remind101/empire
|
pkg/heroku/formation.go
|
FormationUpdate
|
func (c *Client) FormationUpdate(appIdentity string, formationIdentity string, options *FormationUpdateOpts) (*Formation, error) {
var formationRes Formation
return &formationRes, c.Patch(&formationRes, "/apps/"+appIdentity+"/formation/"+formationIdentity, options)
}
|
go
|
func (c *Client) FormationUpdate(appIdentity string, formationIdentity string, options *FormationUpdateOpts) (*Formation, error) {
var formationRes Formation
return &formationRes, c.Patch(&formationRes, "/apps/"+appIdentity+"/formation/"+formationIdentity, options)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"FormationUpdate",
"(",
"appIdentity",
"string",
",",
"formationIdentity",
"string",
",",
"options",
"*",
"FormationUpdateOpts",
")",
"(",
"*",
"Formation",
",",
"error",
")",
"{",
"var",
"formationRes",
"Formation",
"\n",
"return",
"&",
"formationRes",
",",
"c",
".",
"Patch",
"(",
"&",
"formationRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"formationIdentity",
",",
"options",
")",
"\n",
"}"
] |
// Update process type
//
// appIdentity is the unique identifier of the Formation's App.
// formationIdentity is the unique identifier of the Formation. options is the
// struct of optional parameters for this action.
|
[
"Update",
"process",
"type",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Formation",
"s",
"App",
".",
"formationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Formation",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/formation.go#L99-L102
|
train
|
remind101/empire
|
server/github/deployer.go
|
NotifyTugboat
|
func NotifyTugboat(d Deployer, url string) *TugboatDeployer {
c := tugboat.NewClient(nil)
c.URL = url
return &TugboatDeployer{
deployer: d,
client: c,
}
}
|
go
|
func NotifyTugboat(d Deployer, url string) *TugboatDeployer {
c := tugboat.NewClient(nil)
c.URL = url
return &TugboatDeployer{
deployer: d,
client: c,
}
}
|
[
"func",
"NotifyTugboat",
"(",
"d",
"Deployer",
",",
"url",
"string",
")",
"*",
"TugboatDeployer",
"{",
"c",
":=",
"tugboat",
".",
"NewClient",
"(",
"nil",
")",
"\n",
"c",
".",
"URL",
"=",
"url",
"\n",
"return",
"&",
"TugboatDeployer",
"{",
"deployer",
":",
"d",
",",
"client",
":",
"c",
",",
"}",
"\n",
"}"
] |
// NotifyTugboat wraps a Deployer to sent deployment logs and status updates to
// a Tugboat instance.
|
[
"NotifyTugboat",
"wraps",
"a",
"Deployer",
"to",
"sent",
"deployment",
"logs",
"and",
"status",
"updates",
"to",
"a",
"Tugboat",
"instance",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/github/deployer.go#L88-L95
|
train
|
remind101/empire
|
server/github/deployer.go
|
DeployAsync
|
func DeployAsync(d Deployer) Deployer {
return DeployerFunc(func(ctx context.Context, event events.Deployment, w io.Writer) error {
go d.Deploy(ctx, event, w)
return nil
})
}
|
go
|
func DeployAsync(d Deployer) Deployer {
return DeployerFunc(func(ctx context.Context, event events.Deployment, w io.Writer) error {
go d.Deploy(ctx, event, w)
return nil
})
}
|
[
"func",
"DeployAsync",
"(",
"d",
"Deployer",
")",
"Deployer",
"{",
"return",
"DeployerFunc",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"events",
".",
"Deployment",
",",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"go",
"d",
".",
"Deploy",
"(",
"ctx",
",",
"event",
",",
"w",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] |
// DeployAsync wraps a Deployer to perform the Deploy within a goroutine.
|
[
"DeployAsync",
"wraps",
"a",
"Deployer",
"to",
"perform",
"the",
"Deploy",
"within",
"a",
"goroutine",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/github/deployer.go#L128-L133
|
train
|
remind101/empire
|
pkg/heroku/addon.go
|
AddonCreate
|
func (c *Client) AddonCreate(appIdentity string, plan string, options *AddonCreateOpts) (*Addon, error) {
params := struct {
Plan string `json:"plan"`
Config *map[string]string `json:"config,omitempty"`
}{
Plan: plan,
}
if options != nil {
params.Config = options.Config
}
var addonRes Addon
return &addonRes, c.Post(&addonRes, "/apps/"+appIdentity+"/addons", params)
}
|
go
|
func (c *Client) AddonCreate(appIdentity string, plan string, options *AddonCreateOpts) (*Addon, error) {
params := struct {
Plan string `json:"plan"`
Config *map[string]string `json:"config,omitempty"`
}{
Plan: plan,
}
if options != nil {
params.Config = options.Config
}
var addonRes Addon
return &addonRes, c.Post(&addonRes, "/apps/"+appIdentity+"/addons", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AddonCreate",
"(",
"appIdentity",
"string",
",",
"plan",
"string",
",",
"options",
"*",
"AddonCreateOpts",
")",
"(",
"*",
"Addon",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Plan",
"string",
"`json:\"plan\"`",
"\n",
"Config",
"*",
"map",
"[",
"string",
"]",
"string",
"`json:\"config,omitempty\"`",
"\n",
"}",
"{",
"Plan",
":",
"plan",
",",
"}",
"\n",
"if",
"options",
"!=",
"nil",
"{",
"params",
".",
"Config",
"=",
"options",
".",
"Config",
"\n",
"}",
"\n",
"var",
"addonRes",
"Addon",
"\n",
"return",
"&",
"addonRes",
",",
"c",
".",
"Post",
"(",
"&",
"addonRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new add-on.
//
// appIdentity is the unique identifier of the Addon's App. plan is the unique
// identifier of this plan or unique name of this plan. options is the struct of
// optional parameters for this action.
|
[
"Create",
"a",
"new",
"add",
"-",
"on",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Addon",
"s",
"App",
".",
"plan",
"is",
"the",
"unique",
"identifier",
"of",
"this",
"plan",
"or",
"unique",
"name",
"of",
"this",
"plan",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/addon.go#L43-L55
|
train
|
remind101/empire
|
pkg/heroku/addon.go
|
AddonDelete
|
func (c *Client) AddonDelete(appIdentity string, addonIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/addons/" + addonIdentity)
}
|
go
|
func (c *Client) AddonDelete(appIdentity string, addonIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/addons/" + addonIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AddonDelete",
"(",
"appIdentity",
"string",
",",
"addonIdentity",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Delete",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"addonIdentity",
")",
"\n",
"}"
] |
// Delete an existing add-on.
//
// appIdentity is the unique identifier of the Addon's App. addonIdentity is the
// unique identifier of the Addon.
|
[
"Delete",
"an",
"existing",
"add",
"-",
"on",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Addon",
"s",
"App",
".",
"addonIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Addon",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/addon.go#L67-L69
|
train
|
remind101/empire
|
pkg/heroku/addon.go
|
AddonInfo
|
func (c *Client) AddonInfo(appIdentity string, addonIdentity string) (*Addon, error) {
var addon Addon
return &addon, c.Get(&addon, "/apps/"+appIdentity+"/addons/"+addonIdentity)
}
|
go
|
func (c *Client) AddonInfo(appIdentity string, addonIdentity string) (*Addon, error) {
var addon Addon
return &addon, c.Get(&addon, "/apps/"+appIdentity+"/addons/"+addonIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AddonInfo",
"(",
"appIdentity",
"string",
",",
"addonIdentity",
"string",
")",
"(",
"*",
"Addon",
",",
"error",
")",
"{",
"var",
"addon",
"Addon",
"\n",
"return",
"&",
"addon",
",",
"c",
".",
"Get",
"(",
"&",
"addon",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"addonIdentity",
")",
"\n",
"}"
] |
// Info for an existing add-on.
//
// appIdentity is the unique identifier of the Addon's App. addonIdentity is the
// unique identifier of the Addon.
|
[
"Info",
"for",
"an",
"existing",
"add",
"-",
"on",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Addon",
"s",
"App",
".",
"addonIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Addon",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/addon.go#L75-L78
|
train
|
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.