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
pkg/heroku/addon.go
AddonList
func (c *Client) AddonList(appIdentity string, lr *ListRange) ([]Addon, error) { req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/addons", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var addonsRes []Addon return addonsRes, c.DoReq(req, &addonsRes) }
go
func (c *Client) AddonList(appIdentity string, lr *ListRange) ([]Addon, error) { req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/addons", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var addonsRes []Addon return addonsRes, c.DoReq(req, &addonsRes) }
[ "func", "(", "c", "*", "Client", ")", "AddonList", "(", "appIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "[", "]", "Addon", ",", "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", "addonsRes", "[", "]", "Addon", "\n", "return", "addonsRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "addonsRes", ")", "\n", "}" ]
// List existing add-ons. // // appIdentity is the unique identifier of the Addon's App. lr is an optional // ListRange that sets the Range options for the paginated list of results.
[ "List", "existing", "add", "-", "ons", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "Addon", "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/addon.go#L84-L96
train
remind101/empire
pkg/heroku/addon.go
AddonUpdate
func (c *Client) AddonUpdate(appIdentity string, addonIdentity string, plan string) (*Addon, error) { params := struct { Plan string `json:"plan"` }{ Plan: plan, } var addonRes Addon return &addonRes, c.Patch(&addonRes, "/apps/"+appIdentity+"/addons/"+addonIdentity, params) }
go
func (c *Client) AddonUpdate(appIdentity string, addonIdentity string, plan string) (*Addon, error) { params := struct { Plan string `json:"plan"` }{ Plan: plan, } var addonRes Addon return &addonRes, c.Patch(&addonRes, "/apps/"+appIdentity+"/addons/"+addonIdentity, params) }
[ "func", "(", "c", "*", "Client", ")", "AddonUpdate", "(", "appIdentity", "string", ",", "addonIdentity", "string", ",", "plan", "string", ")", "(", "*", "Addon", ",", "error", ")", "{", "params", ":=", "struct", "{", "Plan", "string", "`json:\"plan\"`", "\n", "}", "{", "Plan", ":", "plan", ",", "}", "\n", "var", "addonRes", "Addon", "\n", "return", "&", "addonRes", ",", "c", ".", "Patch", "(", "&", "addonRes", ",", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", "+", "addonIdentity", ",", "params", ")", "\n", "}" ]
// Change add-on plan. Some add-ons may not support changing plans. In that // case, an error will be returned. // // appIdentity is the unique identifier of the Addon's App. addonIdentity is the // unique identifier of the Addon. plan is the unique identifier of this plan or // unique name of this plan.
[ "Change", "add", "-", "on", "plan", ".", "Some", "add", "-", "ons", "may", "not", "support", "changing", "plans", ".", "In", "that", "case", "an", "error", "will", "be", "returned", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "Addon", "s", "App", ".", "addonIdentity", "is", "the", "unique", "identifier", "of", "the", "Addon", ".", "plan", "is", "the", "unique", "identifier", "of", "this", "plan", "or", "unique", "name", "of", "this", "plan", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/addon.go#L104-L112
train
remind101/empire
pkg/heroku/stack.go
StackInfo
func (c *Client) StackInfo(stackIdentity string) (*Stack, error) { var stack Stack return &stack, c.Get(&stack, "/stacks/"+stackIdentity) }
go
func (c *Client) StackInfo(stackIdentity string) (*Stack, error) { var stack Stack return &stack, c.Get(&stack, "/stacks/"+stackIdentity) }
[ "func", "(", "c", "*", "Client", ")", "StackInfo", "(", "stackIdentity", "string", ")", "(", "*", "Stack", ",", "error", ")", "{", "var", "stack", "Stack", "\n", "return", "&", "stack", ",", "c", ".", "Get", "(", "&", "stack", ",", "\"", "\"", "+", "stackIdentity", ")", "\n", "}" ]
// Stack info. // // stackIdentity is the unique identifier of the Stack.
[ "Stack", "info", ".", "stackIdentity", "is", "the", "unique", "identifier", "of", "the", "Stack", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/stack.go#L33-L36
train
remind101/empire
pkg/heroku/stack.go
StackList
func (c *Client) StackList(lr *ListRange) ([]Stack, error) { req, err := c.NewRequest("GET", "/stacks", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var stacksRes []Stack return stacksRes, c.DoReq(req, &stacksRes) }
go
func (c *Client) StackList(lr *ListRange) ([]Stack, error) { req, err := c.NewRequest("GET", "/stacks", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var stacksRes []Stack return stacksRes, c.DoReq(req, &stacksRes) }
[ "func", "(", "c", "*", "Client", ")", "StackList", "(", "lr", "*", "ListRange", ")", "(", "[", "]", "Stack", ",", "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", "stacksRes", "[", "]", "Stack", "\n", "return", "stacksRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "stacksRes", ")", "\n", "}" ]
// List available stacks. // // lr is an optional ListRange that sets the Range options for the paginated // list of results.
[ "List", "available", "stacks", ".", "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/stack.go#L42-L54
train
remind101/empire
slugs.go
ParsedProcfile
func (s *Slug) ParsedProcfile() (procfile.Procfile, error) { return procfile.ParseProcfile(s.Procfile) }
go
func (s *Slug) ParsedProcfile() (procfile.Procfile, error) { return procfile.ParseProcfile(s.Procfile) }
[ "func", "(", "s", "*", "Slug", ")", "ParsedProcfile", "(", ")", "(", "procfile", ".", "Procfile", ",", "error", ")", "{", "return", "procfile", ".", "ParseProcfile", "(", "s", ".", "Procfile", ")", "\n", "}" ]
// ParsedProcfile returns the parsed Procfile.
[ "ParsedProcfile", "returns", "the", "parsed", "Procfile", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/slugs.go#L25-L27
train
remind101/empire
slugs.go
Formation
func (s *Slug) Formation() (Formation, error) { p, err := s.ParsedProcfile() if err != nil { return nil, err } return formationFromProcfile(p) }
go
func (s *Slug) Formation() (Formation, error) { p, err := s.ParsedProcfile() if err != nil { return nil, err } return formationFromProcfile(p) }
[ "func", "(", "s", "*", "Slug", ")", "Formation", "(", ")", "(", "Formation", ",", "error", ")", "{", "p", ",", "err", ":=", "s", ".", "ParsedProcfile", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "formationFromProcfile", "(", "p", ")", "\n", "}" ]
// Formation returns a new Formation built from the extracted Procfile.
[ "Formation", "returns", "a", "new", "Formation", "built", "from", "the", "extracted", "Procfile", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/slugs.go#L30-L37
train
remind101/empire
slugs.go
Create
func (s *slugsService) Create(ctx context.Context, db *gorm.DB, img image.Image, w *DeploymentStream) (*Slug, error) { return slugsCreateByImage(ctx, db, s.ImageRegistry, img, w) }
go
func (s *slugsService) Create(ctx context.Context, db *gorm.DB, img image.Image, w *DeploymentStream) (*Slug, error) { return slugsCreateByImage(ctx, db, s.ImageRegistry, img, w) }
[ "func", "(", "s", "*", "slugsService", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "db", "*", "gorm", ".", "DB", ",", "img", "image", ".", "Image", ",", "w", "*", "DeploymentStream", ")", "(", "*", "Slug", ",", "error", ")", "{", "return", "slugsCreateByImage", "(", "ctx", ",", "db", ",", "s", ".", "ImageRegistry", ",", "img", ",", "w", ")", "\n", "}" ]
// SlugsCreateByImage creates a Slug for the given image.
[ "SlugsCreateByImage", "creates", "a", "Slug", "for", "the", "given", "image", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/slugs.go#L45-L47
train
remind101/empire
slugs.go
slugsCreate
func slugsCreate(db *gorm.DB, slug *Slug) (*Slug, error) { return slug, db.Create(slug).Error }
go
func slugsCreate(db *gorm.DB, slug *Slug) (*Slug, error) { return slug, db.Create(slug).Error }
[ "func", "slugsCreate", "(", "db", "*", "gorm", ".", "DB", ",", "slug", "*", "Slug", ")", "(", "*", "Slug", ",", "error", ")", "{", "return", "slug", ",", "db", ".", "Create", "(", "slug", ")", ".", "Error", "\n", "}" ]
// slugsCreate inserts a Slug into the database.
[ "slugsCreate", "inserts", "a", "Slug", "into", "the", "database", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/slugs.go#L50-L52
train
remind101/empire
slugs.go
slugsCreateByImage
func slugsCreateByImage(ctx context.Context, db *gorm.DB, r ImageRegistry, img image.Image, w *DeploymentStream) (*Slug, error) { var ( slug Slug err error ) slug.Image, err = r.Resolve(ctx, img, w.Stream) if err != nil { return nil, fmt.Errorf("resolving %s: %v", img, err) } slug.Procfile, err = r.ExtractProcfile(ctx, slug.Image, w.Stream) if err != nil { return nil, fmt.Errorf("extracting Procfile from %s: %v", slug.Image, err) } return slugsCreate(db, &slug) }
go
func slugsCreateByImage(ctx context.Context, db *gorm.DB, r ImageRegistry, img image.Image, w *DeploymentStream) (*Slug, error) { var ( slug Slug err error ) slug.Image, err = r.Resolve(ctx, img, w.Stream) if err != nil { return nil, fmt.Errorf("resolving %s: %v", img, err) } slug.Procfile, err = r.ExtractProcfile(ctx, slug.Image, w.Stream) if err != nil { return nil, fmt.Errorf("extracting Procfile from %s: %v", slug.Image, err) } return slugsCreate(db, &slug) }
[ "func", "slugsCreateByImage", "(", "ctx", "context", ".", "Context", ",", "db", "*", "gorm", ".", "DB", ",", "r", "ImageRegistry", ",", "img", "image", ".", "Image", ",", "w", "*", "DeploymentStream", ")", "(", "*", "Slug", ",", "error", ")", "{", "var", "(", "slug", "Slug", "\n", "err", "error", "\n", ")", "\n\n", "slug", ".", "Image", ",", "err", "=", "r", ".", "Resolve", "(", "ctx", ",", "img", ",", "w", ".", "Stream", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "img", ",", "err", ")", "\n", "}", "\n\n", "slug", ".", "Procfile", ",", "err", "=", "r", ".", "ExtractProcfile", "(", "ctx", ",", "slug", ".", "Image", ",", "w", ".", "Stream", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "slug", ".", "Image", ",", "err", ")", "\n", "}", "\n\n", "return", "slugsCreate", "(", "db", ",", "&", "slug", ")", "\n", "}" ]
// SlugsCreateByImage first attempts to find a matching slug for the image. If // it's not found, it will fallback to extracting the process types using the // provided extractor, then create a slug.
[ "SlugsCreateByImage", "first", "attempts", "to", "find", "a", "matching", "slug", "for", "the", "image", ".", "If", "it", "s", "not", "found", "it", "will", "fallback", "to", "extracting", "the", "process", "types", "using", "the", "provided", "extractor", "then", "create", "a", "slug", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/slugs.go#L57-L74
train
remind101/empire
server/cloudformation/ports.go
Get
func (a *dbPortAllocator) Get() (int64, error) { sql := `UPDATE ports SET taken = true WHERE port = (SELECT port FROM ports WHERE taken IS NULL ORDER BY port ASC LIMIT 1) RETURNING port` var port int64 err := a.db.QueryRow(sql).Scan(&port) return port, err }
go
func (a *dbPortAllocator) Get() (int64, error) { sql := `UPDATE ports SET taken = true WHERE port = (SELECT port FROM ports WHERE taken IS NULL ORDER BY port ASC LIMIT 1) RETURNING port` var port int64 err := a.db.QueryRow(sql).Scan(&port) return port, err }
[ "func", "(", "a", "*", "dbPortAllocator", ")", "Get", "(", ")", "(", "int64", ",", "error", ")", "{", "sql", ":=", "`UPDATE ports SET taken = true WHERE port = (SELECT port FROM ports WHERE taken IS NULL ORDER BY port ASC LIMIT 1) RETURNING port`", "\n", "var", "port", "int64", "\n", "err", ":=", "a", ".", "db", ".", "QueryRow", "(", "sql", ")", ".", "Scan", "(", "&", "port", ")", "\n", "return", "port", ",", "err", "\n", "}" ]
// Get finds an existing allocated port from the `ports` table. If one is not // allocated for the process, it allocates one and returns it.
[ "Get", "finds", "an", "existing", "allocated", "port", "from", "the", "ports", "table", ".", "If", "one", "is", "not", "allocated", "for", "the", "process", "it", "allocates", "one", "and", "returns", "it", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/ports.go#L63-L68
train
remind101/empire
server/cloudformation/ports.go
Put
func (a *dbPortAllocator) Put(port int64) error { sql := `UPDATE ports SET taken = NULL WHERE port = $1` _, err := a.db.Exec(sql, port) return err }
go
func (a *dbPortAllocator) Put(port int64) error { sql := `UPDATE ports SET taken = NULL WHERE port = $1` _, err := a.db.Exec(sql, port) return err }
[ "func", "(", "a", "*", "dbPortAllocator", ")", "Put", "(", "port", "int64", ")", "error", "{", "sql", ":=", "`UPDATE ports SET taken = NULL WHERE port = $1`", "\n", "_", ",", "err", ":=", "a", ".", "db", ".", "Exec", "(", "sql", ",", "port", ")", "\n", "return", "err", "\n", "}" ]
// Put releases any allocated port for the process, returning it back to the // pool.
[ "Put", "releases", "any", "allocated", "port", "for", "the", "process", "returning", "it", "back", "to", "the", "pool", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/ports.go#L72-L76
train
remind101/empire
server/cloudformation/ecs.go
newECSClient
func newECSClient(config client.ConfigProvider) *ecs.ECS { return ecs.New(config, &aws.Config{ Retryer: newRetryer(), }) }
go
func newECSClient(config client.ConfigProvider) *ecs.ECS { return ecs.New(config, &aws.Config{ Retryer: newRetryer(), }) }
[ "func", "newECSClient", "(", "config", "client", ".", "ConfigProvider", ")", "*", "ecs", ".", "ECS", "{", "return", "ecs", ".", "New", "(", "config", ",", "&", "aws", ".", "Config", "{", "Retryer", ":", "newRetryer", "(", ")", ",", "}", ")", "\n", "}" ]
// newECSClient returns a new ecs.ECS instance, that has more relaxed retry // timeouts.
[ "newECSClient", "returns", "a", "new", "ecs", ".", "ECS", "instance", "that", "has", "more", "relaxed", "retry", "timeouts", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/ecs.go#L33-L37
train
remind101/empire
server/heroku/heroku.go
New
func New(e *empire.Empire) *Server { r := &Server{ Empire: e, mux: mux.NewRouter(), } // Apps r.handle("GET", "/apps", r.GetApps) // hk apps r.handle("GET", "/apps/{app}", r.GetAppInfo) // hk info r.handle("DELETE", "/apps/{app}", r.DeleteApp) // hk destroy r.handle("PATCH", "/apps/{app}", r.PatchApp) // hk destroy r.handle("POST", "/apps/{app}/deploys", r.DeployApp) // Deploy an image to an app r.handle("POST", "/apps", r.PostApps) // hk create r.handle("POST", "/organizations/apps", r.PostApps) // hk create // Domains r.handle("GET", "/apps/{app}/domains", r.GetDomains) // hk domains r.handle("POST", "/apps/{app}/domains", r.PostDomains) // hk domain-add r.handle("DELETE", "/apps/{app}/domains/{hostname}", r.DeleteDomain) // hk domain-remove // Deploys r.handle("POST", "/deploys", r.PostDeploys) // Deploy an app // Releases r.handle("GET", "/apps/{app}/releases", r.GetReleases) // hk releases r.handle("GET", "/apps/{app}/releases/{version}", r.GetRelease) // hk release-info r.handle("POST", "/apps/{app}/releases", r.PostReleases) // hk rollback // Configs r.handle("GET", "/apps/{app}/config-vars", r.GetConfigs) // hk env, hk get r.handle("GET", "/apps/{app}/config-vars/{version}", r.GetConfigsByRelease) // hk env v1, hk get v1 r.handle("PATCH", "/apps/{app}/config-vars", r.PatchConfigs) // hk set, hk unset // Processes r.handle("GET", "/apps/{app}/dynos", r.GetProcesses) // hk dynos r.handle("POST", "/apps/{app}/dynos", r.PostProcess) // hk run r.handle("DELETE", "/apps/{app}/dynos", r.DeleteProcesses) // hk restart r.handle("DELETE", "/apps/{app}/dynos/{ptype}.{pid}", r.DeleteProcesses) // hk restart web.1 r.handle("DELETE", "/apps/{app}/dynos/{pid}", r.DeleteProcesses) // hk restart web // Formations r.handle("GET", "/apps/{app}/formation", r.GetFormation) // hk scale -l r.handle("PATCH", "/apps/{app}/formation", r.PatchFormation) // hk scale // OAuth r.handle("POST", "/oauth/authorizations", r.PostAuthorizations). // Authentication for this endpoint is handled directly in the // handler. AuthWith(auth.StrategyUsernamePassword) // Certs r.handle("POST", "/apps/{app}/certs", r.PostCerts) // SSL sslRemoved := errHandler(ErrSSLRemoved) r.handle("GET", "/apps/{app}/ssl-endpoints", sslRemoved) // hk ssl r.handle("POST", "/apps/{app}/ssl-endpoints", sslRemoved) // hk ssl-cert-add r.handle("PATCH", "/apps/{app}/ssl-endpoints/{cert}", sslRemoved) // hk ssl-cert-add, hk ssl-cert-rollback r.handle("DELETE", "/apps/{app}/ssl-endpoints/{cert}", sslRemoved) // hk ssl-destroy // Logs r.handle("POST", "/apps/{app}/log-sessions", r.PostLogs) // hk log return r }
go
func New(e *empire.Empire) *Server { r := &Server{ Empire: e, mux: mux.NewRouter(), } // Apps r.handle("GET", "/apps", r.GetApps) // hk apps r.handle("GET", "/apps/{app}", r.GetAppInfo) // hk info r.handle("DELETE", "/apps/{app}", r.DeleteApp) // hk destroy r.handle("PATCH", "/apps/{app}", r.PatchApp) // hk destroy r.handle("POST", "/apps/{app}/deploys", r.DeployApp) // Deploy an image to an app r.handle("POST", "/apps", r.PostApps) // hk create r.handle("POST", "/organizations/apps", r.PostApps) // hk create // Domains r.handle("GET", "/apps/{app}/domains", r.GetDomains) // hk domains r.handle("POST", "/apps/{app}/domains", r.PostDomains) // hk domain-add r.handle("DELETE", "/apps/{app}/domains/{hostname}", r.DeleteDomain) // hk domain-remove // Deploys r.handle("POST", "/deploys", r.PostDeploys) // Deploy an app // Releases r.handle("GET", "/apps/{app}/releases", r.GetReleases) // hk releases r.handle("GET", "/apps/{app}/releases/{version}", r.GetRelease) // hk release-info r.handle("POST", "/apps/{app}/releases", r.PostReleases) // hk rollback // Configs r.handle("GET", "/apps/{app}/config-vars", r.GetConfigs) // hk env, hk get r.handle("GET", "/apps/{app}/config-vars/{version}", r.GetConfigsByRelease) // hk env v1, hk get v1 r.handle("PATCH", "/apps/{app}/config-vars", r.PatchConfigs) // hk set, hk unset // Processes r.handle("GET", "/apps/{app}/dynos", r.GetProcesses) // hk dynos r.handle("POST", "/apps/{app}/dynos", r.PostProcess) // hk run r.handle("DELETE", "/apps/{app}/dynos", r.DeleteProcesses) // hk restart r.handle("DELETE", "/apps/{app}/dynos/{ptype}.{pid}", r.DeleteProcesses) // hk restart web.1 r.handle("DELETE", "/apps/{app}/dynos/{pid}", r.DeleteProcesses) // hk restart web // Formations r.handle("GET", "/apps/{app}/formation", r.GetFormation) // hk scale -l r.handle("PATCH", "/apps/{app}/formation", r.PatchFormation) // hk scale // OAuth r.handle("POST", "/oauth/authorizations", r.PostAuthorizations). // Authentication for this endpoint is handled directly in the // handler. AuthWith(auth.StrategyUsernamePassword) // Certs r.handle("POST", "/apps/{app}/certs", r.PostCerts) // SSL sslRemoved := errHandler(ErrSSLRemoved) r.handle("GET", "/apps/{app}/ssl-endpoints", sslRemoved) // hk ssl r.handle("POST", "/apps/{app}/ssl-endpoints", sslRemoved) // hk ssl-cert-add r.handle("PATCH", "/apps/{app}/ssl-endpoints/{cert}", sslRemoved) // hk ssl-cert-add, hk ssl-cert-rollback r.handle("DELETE", "/apps/{app}/ssl-endpoints/{cert}", sslRemoved) // hk ssl-destroy // Logs r.handle("POST", "/apps/{app}/log-sessions", r.PostLogs) // hk log return r }
[ "func", "New", "(", "e", "*", "empire", ".", "Empire", ")", "*", "Server", "{", "r", ":=", "&", "Server", "{", "Empire", ":", "e", ",", "mux", ":", "mux", ".", "NewRouter", "(", ")", ",", "}", "\n\n", "// Apps", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetApps", ")", "// hk apps", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetAppInfo", ")", "// hk info", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "DeleteApp", ")", "// hk destroy", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PatchApp", ")", "// hk destroy", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "DeployApp", ")", "// Deploy an image to an app", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostApps", ")", "// hk create", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostApps", ")", "// hk create", "\n\n", "// Domains", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetDomains", ")", "// hk domains", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostDomains", ")", "// hk domain-add", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "DeleteDomain", ")", "// hk domain-remove", "\n\n", "// Deploys", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostDeploys", ")", "// Deploy an app", "\n\n", "// Releases", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetReleases", ")", "// hk releases", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetRelease", ")", "// hk release-info", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostReleases", ")", "// hk rollback", "\n\n", "// Configs", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetConfigs", ")", "// hk env, hk get", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetConfigsByRelease", ")", "// hk env v1, hk get v1", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PatchConfigs", ")", "// hk set, hk unset", "\n\n", "// Processes", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetProcesses", ")", "// hk dynos", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostProcess", ")", "// hk run", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "DeleteProcesses", ")", "// hk restart", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "DeleteProcesses", ")", "// hk restart web.1", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "DeleteProcesses", ")", "// hk restart web", "\n\n", "// Formations", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "GetFormation", ")", "// hk scale -l", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PatchFormation", ")", "// hk scale", "\n\n", "// OAuth", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostAuthorizations", ")", ".", "// Authentication for this endpoint is handled directly in the", "// handler.", "AuthWith", "(", "auth", ".", "StrategyUsernamePassword", ")", "\n\n", "// Certs", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostCerts", ")", "\n\n", "// SSL", "sslRemoved", ":=", "errHandler", "(", "ErrSSLRemoved", ")", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "sslRemoved", ")", "// hk ssl", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "sslRemoved", ")", "// hk ssl-cert-add", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "sslRemoved", ")", "// hk ssl-cert-add, hk ssl-cert-rollback", "\n", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "sslRemoved", ")", "// hk ssl-destroy", "\n\n", "// Logs", "r", ".", "handle", "(", "\"", "\"", ",", "\"", "\"", ",", "r", ".", "PostLogs", ")", "// hk log", "\n\n", "return", "r", "\n", "}" ]
// New returns a new Server instance to serve the Heroku compatible API.
[ "New", "returns", "a", "new", "Server", "instance", "to", "serve", "the", "Heroku", "compatible", "API", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L52-L116
train
remind101/empire
server/heroku/heroku.go
AuthWith
func (r *route) AuthWith(strategies ...string) *route { r.authStrategies = strategies return r }
go
func (r *route) AuthWith(strategies ...string) *route { r.authStrategies = strategies return r }
[ "func", "(", "r", "*", "route", ")", "AuthWith", "(", "strategies", "...", "string", ")", "*", "route", "{", "r", ".", "authStrategies", "=", "strategies", "\n", "return", "r", "\n", "}" ]
// AuthWith sets the explicit strategies used to authenticate this route.
[ "AuthWith", "sets", "the", "explicit", "strategies", "used", "to", "authenticate", "this", "route", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L136-L139
train
remind101/empire
server/heroku/heroku.go
handle
func (s *Server) handle(method, path string, h handlerFunc, authStrategy ...string) *route { r := s.route(h) s.mux.Handle(path, r).Methods(method) return r }
go
func (s *Server) handle(method, path string, h handlerFunc, authStrategy ...string) *route { r := s.route(h) s.mux.Handle(path, r).Methods(method) return r }
[ "func", "(", "s", "*", "Server", ")", "handle", "(", "method", ",", "path", "string", ",", "h", "handlerFunc", ",", "authStrategy", "...", "string", ")", "*", "route", "{", "r", ":=", "s", ".", "route", "(", "h", ")", "\n", "s", ".", "mux", ".", "Handle", "(", "path", ",", "r", ")", ".", "Methods", "(", "method", ")", "\n", "return", "r", "\n", "}" ]
// handle adds a new handler to the router, which also increments a counter.
[ "handle", "adds", "a", "new", "handler", "to", "the", "router", "which", "also", "increments", "a", "counter", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L167-L171
train
remind101/empire
server/heroku/heroku.go
route
func (s *Server) route(h handlerFunc) *route { name := handlerName(h) return &route{Name: name, handler: h, s: s} }
go
func (s *Server) route(h handlerFunc) *route { name := handlerName(h) return &route{Name: name, handler: h, s: s} }
[ "func", "(", "s", "*", "Server", ")", "route", "(", "h", "handlerFunc", ")", "*", "route", "{", "name", ":=", "handlerName", "(", "h", ")", "\n", "return", "&", "route", "{", "Name", ":", "name", ",", "handler", ":", "h", ",", "s", ":", "s", "}", "\n", "}" ]
// route creates a new route object for the given handler.
[ "route", "creates", "a", "new", "route", "object", "for", "the", "given", "handler", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L174-L177
train
remind101/empire
server/heroku/heroku.go
Encode
func Encode(w http.ResponseWriter, v interface{}) error { if v == nil { // Empty JSON body "{}" v = map[string]interface{}{} } return json.NewEncoder(w).Encode(v) }
go
func Encode(w http.ResponseWriter, v interface{}) error { if v == nil { // Empty JSON body "{}" v = map[string]interface{}{} } return json.NewEncoder(w).Encode(v) }
[ "func", "Encode", "(", "w", "http", ".", "ResponseWriter", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "v", "==", "nil", "{", "// Empty JSON body \"{}\"", "v", "=", "map", "[", "string", "]", "interface", "{", "}", "{", "}", "\n", "}", "\n\n", "return", "json", ".", "NewEncoder", "(", "w", ")", ".", "Encode", "(", "v", ")", "\n", "}" ]
// Encode json encodes v into w.
[ "Encode", "json", "encodes", "v", "into", "w", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L180-L187
train
remind101/empire
server/heroku/heroku.go
DecodeRequest
func DecodeRequest(r *http.Request, v interface{}, ignoreEOF bool) error { if err := json.NewDecoder(r.Body).Decode(v); err != nil { if err == io.EOF && ignoreEOF { return nil } return fmt.Errorf("error decoding request body: %v", err) } return nil }
go
func DecodeRequest(r *http.Request, v interface{}, ignoreEOF bool) error { if err := json.NewDecoder(r.Body).Decode(v); err != nil { if err == io.EOF && ignoreEOF { return nil } return fmt.Errorf("error decoding request body: %v", err) } return nil }
[ "func", "DecodeRequest", "(", "r", "*", "http", ".", "Request", ",", "v", "interface", "{", "}", ",", "ignoreEOF", "bool", ")", "error", "{", "if", "err", ":=", "json", ".", "NewDecoder", "(", "r", ".", "Body", ")", ".", "Decode", "(", "v", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "&&", "ignoreEOF", "{", "return", "nil", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DecodeRequest json decodes the request body into v, optionally ignoring EOF // errors to handle cases where the request body might be empty.
[ "DecodeRequest", "json", "decodes", "the", "request", "body", "into", "v", "optionally", "ignoring", "EOF", "errors", "to", "handle", "cases", "where", "the", "request", "body", "might", "be", "empty", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L191-L199
train
remind101/empire
server/heroku/heroku.go
Decode
func Decode(r *http.Request, v interface{}) error { return DecodeRequest(r, v, false) }
go
func Decode(r *http.Request, v interface{}) error { return DecodeRequest(r, v, false) }
[ "func", "Decode", "(", "r", "*", "http", ".", "Request", ",", "v", "interface", "{", "}", ")", "error", "{", "return", "DecodeRequest", "(", "r", ",", "v", ",", "false", ")", "\n", "}" ]
// Decode json decodes the request body into v.
[ "Decode", "json", "decodes", "the", "request", "body", "into", "v", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L202-L204
train
remind101/empire
server/heroku/heroku.go
Stream
func Stream(w http.ResponseWriter, v interface{}) error { if err := Encode(w, v); err != nil { return err } if f, ok := w.(http.Flusher); ok { f.Flush() } return nil }
go
func Stream(w http.ResponseWriter, v interface{}) error { if err := Encode(w, v); err != nil { return err } if f, ok := w.(http.Flusher); ok { f.Flush() } return nil }
[ "func", "Stream", "(", "w", "http", ".", "ResponseWriter", ",", "v", "interface", "{", "}", ")", "error", "{", "if", "err", ":=", "Encode", "(", "w", ",", "v", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "f", ",", "ok", ":=", "w", ".", "(", "http", ".", "Flusher", ")", ";", "ok", "{", "f", ".", "Flush", "(", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Stream encodes and flushes data to the client.
[ "Stream", "encodes", "and", "flushes", "data", "to", "the", "client", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L207-L217
train
remind101/empire
server/heroku/heroku.go
NoContent
func NoContent(w http.ResponseWriter) error { w.WriteHeader(http.StatusNoContent) return nil }
go
func NoContent(w http.ResponseWriter) error { w.WriteHeader(http.StatusNoContent) return nil }
[ "func", "NoContent", "(", "w", "http", ".", "ResponseWriter", ")", "error", "{", "w", ".", "WriteHeader", "(", "http", ".", "StatusNoContent", ")", "\n", "return", "nil", "\n", "}" ]
// NoContent responds with a 404 and an empty body.
[ "NoContent", "responds", "with", "a", "404", "and", "an", "empty", "body", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L239-L242
train
remind101/empire
server/heroku/heroku.go
RangeHeader
func RangeHeader(r *http.Request) (headerutil.Range, error) { header := r.Header.Get("Range") if header == "" { return headerutil.Range{}, nil } rangeHeader, err := headerutil.ParseRange(header) if err != nil { return headerutil.Range{}, err } return *rangeHeader, nil }
go
func RangeHeader(r *http.Request) (headerutil.Range, error) { header := r.Header.Get("Range") if header == "" { return headerutil.Range{}, nil } rangeHeader, err := headerutil.ParseRange(header) if err != nil { return headerutil.Range{}, err } return *rangeHeader, nil }
[ "func", "RangeHeader", "(", "r", "*", "http", ".", "Request", ")", "(", "headerutil", ".", "Range", ",", "error", ")", "{", "header", ":=", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "\n", "if", "header", "==", "\"", "\"", "{", "return", "headerutil", ".", "Range", "{", "}", ",", "nil", "\n", "}", "\n\n", "rangeHeader", ",", "err", ":=", "headerutil", ".", "ParseRange", "(", "header", ")", "\n", "if", "err", "!=", "nil", "{", "return", "headerutil", ".", "Range", "{", "}", ",", "err", "\n", "}", "\n", "return", "*", "rangeHeader", ",", "nil", "\n", "}" ]
// RangeHeader parses the Range header and returns an headerutil.Range.
[ "RangeHeader", "parses", "the", "Range", "header", "and", "returns", "an", "headerutil", ".", "Range", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L245-L256
train
remind101/empire
server/heroku/heroku.go
handlerName
func handlerName(h handlerFunc) string { name := runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name() parts := nameRegexp.FindStringSubmatch(name) if len(parts) != 2 { return "" } return parts[1] }
go
func handlerName(h handlerFunc) string { name := runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name() parts := nameRegexp.FindStringSubmatch(name) if len(parts) != 2 { return "" } return parts[1] }
[ "func", "handlerName", "(", "h", "handlerFunc", ")", "string", "{", "name", ":=", "runtime", ".", "FuncForPC", "(", "reflect", ".", "ValueOf", "(", "h", ")", ".", "Pointer", "(", ")", ")", ".", "Name", "(", ")", "\n", "parts", ":=", "nameRegexp", ".", "FindStringSubmatch", "(", "name", ")", "\n", "if", "len", "(", "parts", ")", "!=", "2", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "parts", "[", "1", "]", "\n", "}" ]
// handlerName returns the name of the handler, which can be used as a metrics // postfix.
[ "handlerName", "returns", "the", "name", "of", "the", "handler", "which", "can", "be", "used", "as", "a", "metrics", "postfix", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/heroku.go#L267-L274
train
remind101/empire
server/saml.go
SAMLLogin
func (s *Server) SAMLLogin(w http.ResponseWriter, r *http.Request) { if s.ServiceProvider == nil { http.NotFound(w, r) return } // TODO(ejholmes): Handle error _ = s.ServiceProvider.InitiateLogin(w) }
go
func (s *Server) SAMLLogin(w http.ResponseWriter, r *http.Request) { if s.ServiceProvider == nil { http.NotFound(w, r) return } // TODO(ejholmes): Handle error _ = s.ServiceProvider.InitiateLogin(w) }
[ "func", "(", "s", "*", "Server", ")", "SAMLLogin", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "s", ".", "ServiceProvider", "==", "nil", "{", "http", ".", "NotFound", "(", "w", ",", "r", ")", "\n", "return", "\n", "}", "\n\n", "// TODO(ejholmes): Handle error", "_", "=", "s", ".", "ServiceProvider", ".", "InitiateLogin", "(", "w", ")", "\n", "}" ]
// SAMLLogin starts a Service Provider initiated login. It generates an // AuthnRequest, signs the generated id and stores it in a cookie, then starts // the login with the IdP.
[ "SAMLLogin", "starts", "a", "Service", "Provider", "initiated", "login", ".", "It", "generates", "an", "AuthnRequest", "signs", "the", "generated", "id", "and", "stores", "it", "in", "a", "cookie", "then", "starts", "the", "login", "with", "the", "IdP", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/saml.go#L19-L27
train
remind101/empire
server/saml.go
SAMLACS
func (s *Server) SAMLACS(w http.ResponseWriter, r *http.Request) { if s.ServiceProvider == nil { http.NotFound(w, r) return } assertion, err := s.ServiceProvider.Parse(w, r) if err != nil { if err, ok := err.(*saml.InvalidResponseError); ok { reporter.Report(r.Context(), err.PrivateErr) } http.Error(w, err.Error(), 403) return } session := samlauth.SessionFromAssertion(assertion) // Create an Access Token for the API. at, err := s.Heroku.AccessTokensCreate(&heroku.AccessToken{ ExpiresAt: session.ExpiresAt, User: session.User, }) if err != nil { http.Error(w, err.Error(), 403) return } switch r.Header.Get("Accept") { case "text/plain": w.Header().Set("Content-Type", "text/plain") io.WriteString(w, at.Token) default: w.Header().Set("Content-Type", "text/html") instructionsTemplate.Execute(w, &instructionsData{ URL: s.URL, User: session.User, Token: at, }) } }
go
func (s *Server) SAMLACS(w http.ResponseWriter, r *http.Request) { if s.ServiceProvider == nil { http.NotFound(w, r) return } assertion, err := s.ServiceProvider.Parse(w, r) if err != nil { if err, ok := err.(*saml.InvalidResponseError); ok { reporter.Report(r.Context(), err.PrivateErr) } http.Error(w, err.Error(), 403) return } session := samlauth.SessionFromAssertion(assertion) // Create an Access Token for the API. at, err := s.Heroku.AccessTokensCreate(&heroku.AccessToken{ ExpiresAt: session.ExpiresAt, User: session.User, }) if err != nil { http.Error(w, err.Error(), 403) return } switch r.Header.Get("Accept") { case "text/plain": w.Header().Set("Content-Type", "text/plain") io.WriteString(w, at.Token) default: w.Header().Set("Content-Type", "text/html") instructionsTemplate.Execute(w, &instructionsData{ URL: s.URL, User: session.User, Token: at, }) } }
[ "func", "(", "s", "*", "Server", ")", "SAMLACS", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "{", "if", "s", ".", "ServiceProvider", "==", "nil", "{", "http", ".", "NotFound", "(", "w", ",", "r", ")", "\n", "return", "\n", "}", "\n\n", "assertion", ",", "err", ":=", "s", ".", "ServiceProvider", ".", "Parse", "(", "w", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", ",", "ok", ":=", "err", ".", "(", "*", "saml", ".", "InvalidResponseError", ")", ";", "ok", "{", "reporter", ".", "Report", "(", "r", ".", "Context", "(", ")", ",", "err", ".", "PrivateErr", ")", "\n", "}", "\n", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "403", ")", "\n", "return", "\n", "}", "\n\n", "session", ":=", "samlauth", ".", "SessionFromAssertion", "(", "assertion", ")", "\n\n", "// Create an Access Token for the API.", "at", ",", "err", ":=", "s", ".", "Heroku", ".", "AccessTokensCreate", "(", "&", "heroku", ".", "AccessToken", "{", "ExpiresAt", ":", "session", ".", "ExpiresAt", ",", "User", ":", "session", ".", "User", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "w", ",", "err", ".", "Error", "(", ")", ",", "403", ")", "\n", "return", "\n", "}", "\n\n", "switch", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", "{", "case", "\"", "\"", ":", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "io", ".", "WriteString", "(", "w", ",", "at", ".", "Token", ")", "\n", "default", ":", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "instructionsTemplate", ".", "Execute", "(", "w", ",", "&", "instructionsData", "{", "URL", ":", "s", ".", "URL", ",", "User", ":", "session", ".", "User", ",", "Token", ":", "at", ",", "}", ")", "\n", "}", "\n", "}" ]
// SAMLACS handles the SAML Response call. It will validate the SAML Response // and assertions, generate an API token, then present the token to the user.
[ "SAMLACS", "handles", "the", "SAML", "Response", "call", ".", "It", "will", "validate", "the", "SAML", "Response", "and", "assertions", "generate", "an", "API", "token", "then", "present", "the", "token", "to", "the", "user", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/saml.go#L31-L70
train
remind101/empire
pkg/heroku/ssl_endpoint.go
SSLEndpointDelete
func (c *Client) SSLEndpointDelete(appIdentity string, sslEndpointIdentity string) error { return c.Delete("/apps/" + appIdentity + "/ssl-endpoints/" + sslEndpointIdentity) }
go
func (c *Client) SSLEndpointDelete(appIdentity string, sslEndpointIdentity string) error { return c.Delete("/apps/" + appIdentity + "/ssl-endpoints/" + sslEndpointIdentity) }
[ "func", "(", "c", "*", "Client", ")", "SSLEndpointDelete", "(", "appIdentity", "string", ",", "sslEndpointIdentity", "string", ")", "error", "{", "return", "c", ".", "Delete", "(", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", "+", "sslEndpointIdentity", ")", "\n", "}" ]
// Delete existing SSL endpoint. // // appIdentity is the unique identifier of the SSLEndpoint's App. // sslEndpointIdentity is the unique identifier of the SSLEndpoint.
[ "Delete", "existing", "SSL", "endpoint", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", "s", "App", ".", "sslEndpointIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/ssl_endpoint.go#L66-L68
train
remind101/empire
pkg/heroku/ssl_endpoint.go
SSLEndpointInfo
func (c *Client) SSLEndpointInfo(appIdentity string, sslEndpointIdentity string) (*SSLEndpoint, error) { var sslEndpoint SSLEndpoint return &sslEndpoint, c.Get(&sslEndpoint, "/apps/"+appIdentity+"/ssl-endpoints/"+sslEndpointIdentity) }
go
func (c *Client) SSLEndpointInfo(appIdentity string, sslEndpointIdentity string) (*SSLEndpoint, error) { var sslEndpoint SSLEndpoint return &sslEndpoint, c.Get(&sslEndpoint, "/apps/"+appIdentity+"/ssl-endpoints/"+sslEndpointIdentity) }
[ "func", "(", "c", "*", "Client", ")", "SSLEndpointInfo", "(", "appIdentity", "string", ",", "sslEndpointIdentity", "string", ")", "(", "*", "SSLEndpoint", ",", "error", ")", "{", "var", "sslEndpoint", "SSLEndpoint", "\n", "return", "&", "sslEndpoint", ",", "c", ".", "Get", "(", "&", "sslEndpoint", ",", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", "+", "sslEndpointIdentity", ")", "\n", "}" ]
// Info for existing SSL endpoint. // // appIdentity is the unique identifier of the SSLEndpoint's App. // sslEndpointIdentity is the unique identifier of the SSLEndpoint.
[ "Info", "for", "existing", "SSL", "endpoint", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", "s", "App", ".", "sslEndpointIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/ssl_endpoint.go#L74-L77
train
remind101/empire
pkg/heroku/ssl_endpoint.go
SSLEndpointList
func (c *Client) SSLEndpointList(appIdentity string, lr *ListRange) ([]SSLEndpoint, error) { req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/ssl-endpoints", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var sslEndpointsRes []SSLEndpoint return sslEndpointsRes, c.DoReq(req, &sslEndpointsRes) }
go
func (c *Client) SSLEndpointList(appIdentity string, lr *ListRange) ([]SSLEndpoint, error) { req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/ssl-endpoints", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var sslEndpointsRes []SSLEndpoint return sslEndpointsRes, c.DoReq(req, &sslEndpointsRes) }
[ "func", "(", "c", "*", "Client", ")", "SSLEndpointList", "(", "appIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "[", "]", "SSLEndpoint", ",", "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", "sslEndpointsRes", "[", "]", "SSLEndpoint", "\n", "return", "sslEndpointsRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "sslEndpointsRes", ")", "\n", "}" ]
// List existing SSL endpoints. // // appIdentity is the unique identifier of the SSLEndpoint's App. lr is an // optional ListRange that sets the Range options for the paginated list of // results.
[ "List", "existing", "SSL", "endpoints", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", "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/ssl_endpoint.go#L84-L96
train
remind101/empire
pkg/heroku/ssl_endpoint.go
SSLEndpointUpdate
func (c *Client) SSLEndpointUpdate(appIdentity string, sslEndpointIdentity string, options *SSLEndpointUpdateOpts) (*SSLEndpoint, error) { var sslEndpointRes SSLEndpoint return &sslEndpointRes, c.Patch(&sslEndpointRes, "/apps/"+appIdentity+"/ssl-endpoints/"+sslEndpointIdentity, options) }
go
func (c *Client) SSLEndpointUpdate(appIdentity string, sslEndpointIdentity string, options *SSLEndpointUpdateOpts) (*SSLEndpoint, error) { var sslEndpointRes SSLEndpoint return &sslEndpointRes, c.Patch(&sslEndpointRes, "/apps/"+appIdentity+"/ssl-endpoints/"+sslEndpointIdentity, options) }
[ "func", "(", "c", "*", "Client", ")", "SSLEndpointUpdate", "(", "appIdentity", "string", ",", "sslEndpointIdentity", "string", ",", "options", "*", "SSLEndpointUpdateOpts", ")", "(", "*", "SSLEndpoint", ",", "error", ")", "{", "var", "sslEndpointRes", "SSLEndpoint", "\n", "return", "&", "sslEndpointRes", ",", "c", ".", "Patch", "(", "&", "sslEndpointRes", ",", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", "+", "sslEndpointIdentity", ",", "options", ")", "\n", "}" ]
// Update an existing SSL endpoint. // // appIdentity is the unique identifier of the SSLEndpoint's App. // sslEndpointIdentity is the unique identifier of the SSLEndpoint. options is // the struct of optional parameters for this action.
[ "Update", "an", "existing", "SSL", "endpoint", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", "s", "App", ".", "sslEndpointIdentity", "is", "the", "unique", "identifier", "of", "the", "SSLEndpoint", ".", "options", "is", "the", "struct", "of", "optional", "parameters", "for", "this", "action", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/ssl_endpoint.go#L103-L106
train
remind101/empire
server/heroku/formations.go
GetFormation
func (h *Server) GetFormation(w http.ResponseWriter, r *http.Request) error { ctx := r.Context() app, err := h.findApp(r) if err != nil { return err } formation, err := h.ListScale(ctx, app) if err != nil { return err } var resp []*Formation for name, proc := range formation { resp = append(resp, &Formation{ Type: name, Quantity: proc.Quantity, Size: proc.Constraints().String(), }) } w.WriteHeader(200) return Encode(w, resp) }
go
func (h *Server) GetFormation(w http.ResponseWriter, r *http.Request) error { ctx := r.Context() app, err := h.findApp(r) if err != nil { return err } formation, err := h.ListScale(ctx, app) if err != nil { return err } var resp []*Formation for name, proc := range formation { resp = append(resp, &Formation{ Type: name, Quantity: proc.Quantity, Size: proc.Constraints().String(), }) } w.WriteHeader(200) return Encode(w, resp) }
[ "func", "(", "h", "*", "Server", ")", "GetFormation", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "ctx", ":=", "r", ".", "Context", "(", ")", "\n\n", "app", ",", "err", ":=", "h", ".", "findApp", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "formation", ",", "err", ":=", "h", ".", "ListScale", "(", "ctx", ",", "app", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "resp", "[", "]", "*", "Formation", "\n", "for", "name", ",", "proc", ":=", "range", "formation", "{", "resp", "=", "append", "(", "resp", ",", "&", "Formation", "{", "Type", ":", "name", ",", "Quantity", ":", "proc", ".", "Quantity", ",", "Size", ":", "proc", ".", "Constraints", "(", ")", ".", "String", "(", ")", ",", "}", ")", "\n", "}", "\n\n", "w", ".", "WriteHeader", "(", "200", ")", "\n", "return", "Encode", "(", "w", ",", "resp", ")", "\n", "}" ]
// ServeHTTPContext handles the http response
[ "ServeHTTPContext", "handles", "the", "http", "response" ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/formations.go#L73-L97
train
remind101/empire
pkg/headerutil/headerutil.go
WithDefaults
func (r *Range) WithDefaults(d Range) Range { if r == nil { return d } // Make a copy. c := *r if c.Max == nil { c.Max = d.Max } if c.Sort == nil { c.Sort = d.Sort } if c.Order == nil { c.Order = d.Order } return c }
go
func (r *Range) WithDefaults(d Range) Range { if r == nil { return d } // Make a copy. c := *r if c.Max == nil { c.Max = d.Max } if c.Sort == nil { c.Sort = d.Sort } if c.Order == nil { c.Order = d.Order } return c }
[ "func", "(", "r", "*", "Range", ")", "WithDefaults", "(", "d", "Range", ")", "Range", "{", "if", "r", "==", "nil", "{", "return", "d", "\n", "}", "\n\n", "// Make a copy.", "c", ":=", "*", "r", "\n\n", "if", "c", ".", "Max", "==", "nil", "{", "c", ".", "Max", "=", "d", ".", "Max", "\n", "}", "\n\n", "if", "c", ".", "Sort", "==", "nil", "{", "c", ".", "Sort", "=", "d", ".", "Sort", "\n", "}", "\n\n", "if", "c", ".", "Order", "==", "nil", "{", "c", ".", "Order", "=", "d", ".", "Order", "\n", "}", "\n\n", "return", "c", "\n", "}" ]
// WithDefaults returns a new Range instance with the defaults taken from d.
[ "WithDefaults", "returns", "a", "new", "Range", "instance", "with", "the", "defaults", "taken", "from", "d", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/headerutil/headerutil.go#L51-L72
train
remind101/empire
pkg/heroku/plan.go
PlanInfo
func (c *Client) PlanInfo(addonServiceIdentity string, planIdentity string) (*Plan, error) { var plan Plan return &plan, c.Get(&plan, "/addon-services/"+addonServiceIdentity+"/plans/"+planIdentity) }
go
func (c *Client) PlanInfo(addonServiceIdentity string, planIdentity string) (*Plan, error) { var plan Plan return &plan, c.Get(&plan, "/addon-services/"+addonServiceIdentity+"/plans/"+planIdentity) }
[ "func", "(", "c", "*", "Client", ")", "PlanInfo", "(", "addonServiceIdentity", "string", ",", "planIdentity", "string", ")", "(", "*", "Plan", ",", "error", ")", "{", "var", "plan", "Plan", "\n", "return", "&", "plan", ",", "c", ".", "Get", "(", "&", "plan", ",", "\"", "\"", "+", "addonServiceIdentity", "+", "\"", "\"", "+", "planIdentity", ")", "\n", "}" ]
// Info for existing plan. // // addonServiceIdentity is the unique identifier of the Plan's AddonService. // planIdentity is the unique identifier of the Plan.
[ "Info", "for", "existing", "plan", ".", "addonServiceIdentity", "is", "the", "unique", "identifier", "of", "the", "Plan", "s", "AddonService", ".", "planIdentity", "is", "the", "unique", "identifier", "of", "the", "Plan", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/plan.go#L46-L49
train
remind101/empire
pkg/heroku/plan.go
PlanList
func (c *Client) PlanList(addonServiceIdentity string, lr *ListRange) ([]Plan, error) { req, err := c.NewRequest("GET", "/addon-services/"+addonServiceIdentity+"/plans", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var plansRes []Plan return plansRes, c.DoReq(req, &plansRes) }
go
func (c *Client) PlanList(addonServiceIdentity string, lr *ListRange) ([]Plan, error) { req, err := c.NewRequest("GET", "/addon-services/"+addonServiceIdentity+"/plans", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var plansRes []Plan return plansRes, c.DoReq(req, &plansRes) }
[ "func", "(", "c", "*", "Client", ")", "PlanList", "(", "addonServiceIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "[", "]", "Plan", ",", "error", ")", "{", "req", ",", "err", ":=", "c", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", "+", "addonServiceIdentity", "+", "\"", "\"", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "lr", "!=", "nil", "{", "lr", ".", "SetHeader", "(", "req", ")", "\n", "}", "\n\n", "var", "plansRes", "[", "]", "Plan", "\n", "return", "plansRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "plansRes", ")", "\n", "}" ]
// List existing plans. // // addonServiceIdentity is the unique identifier of the Plan's AddonService. lr // is an optional ListRange that sets the Range options for the paginated list // of results.
[ "List", "existing", "plans", ".", "addonServiceIdentity", "is", "the", "unique", "identifier", "of", "the", "Plan", "s", "AddonService", ".", "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/plan.go#L56-L68
train
remind101/empire
pkg/cloudformation/customresources/customresources.go
Hash
func (r *Request) Hash() string { h := fnv.New64() h.Write([]byte(fmt.Sprintf("%s.%s", r.StackId, r.RequestId))) return base62.Encode(h.Sum64()) }
go
func (r *Request) Hash() string { h := fnv.New64() h.Write([]byte(fmt.Sprintf("%s.%s", r.StackId, r.RequestId))) return base62.Encode(h.Sum64()) }
[ "func", "(", "r", "*", "Request", ")", "Hash", "(", ")", "string", "{", "h", ":=", "fnv", ".", "New64", "(", ")", "\n", "h", ".", "Write", "(", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ".", "StackId", ",", "r", ".", "RequestId", ")", ")", ")", "\n", "return", "base62", ".", "Encode", "(", "h", ".", "Sum64", "(", ")", ")", "\n", "}" ]
// Hash returns a compact unique identifier for the request.
[ "Hash", "returns", "a", "compact", "unique", "identifier", "for", "the", "request", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/customresources.go#L103-L107
train
remind101/empire
pkg/cloudformation/customresources/customresources.go
NewResponseFromRequest
func NewResponseFromRequest(req Request) Response { return Response{ StackId: req.StackId, RequestId: req.RequestId, LogicalResourceId: req.LogicalResourceId, } }
go
func NewResponseFromRequest(req Request) Response { return Response{ StackId: req.StackId, RequestId: req.RequestId, LogicalResourceId: req.LogicalResourceId, } }
[ "func", "NewResponseFromRequest", "(", "req", "Request", ")", "Response", "{", "return", "Response", "{", "StackId", ":", "req", ".", "StackId", ",", "RequestId", ":", "req", ".", "RequestId", ",", "LogicalResourceId", ":", "req", ".", "LogicalResourceId", ",", "}", "\n", "}" ]
// NewResponseFromRequest initializes a new Response from a Request, filling in // the required verbatim fields.
[ "NewResponseFromRequest", "initializes", "a", "new", "Response", "from", "a", "Request", "filling", "in", "the", "required", "verbatim", "fields", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/customresources.go#L152-L158
train
remind101/empire
pkg/cloudformation/customresources/customresources.go
SendResponse
func SendResponse(req Request, response Response) error { return SendResponseWithClient(http.DefaultClient, req, response) }
go
func SendResponse(req Request, response Response) error { return SendResponseWithClient(http.DefaultClient, req, response) }
[ "func", "SendResponse", "(", "req", "Request", ",", "response", "Response", ")", "error", "{", "return", "SendResponseWithClient", "(", "http", ".", "DefaultClient", ",", "req", ",", "response", ")", "\n", "}" ]
// SendResponse sends the response the Response to the requests response url
[ "SendResponse", "sends", "the", "response", "the", "Response", "to", "the", "requests", "response", "url" ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/customresources.go#L161-L163
train
remind101/empire
pkg/cloudformation/customresources/customresources.go
SendResponseWithClient
func SendResponseWithClient(client interface { Do(*http.Request) (*http.Response, error) }, req Request, response Response) error { c := ResponseClient{client} return c.SendResponse(req, response) }
go
func SendResponseWithClient(client interface { Do(*http.Request) (*http.Response, error) }, req Request, response Response) error { c := ResponseClient{client} return c.SendResponse(req, response) }
[ "func", "SendResponseWithClient", "(", "client", "interface", "{", "Do", "(", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "\n", "}", ",", "req", "Request", ",", "response", "Response", ")", "error", "{", "c", ":=", "ResponseClient", "{", "client", "}", "\n", "return", "c", ".", "SendResponse", "(", "req", ",", "response", ")", "\n", "}" ]
// SendResponseWithClient uploads the response to the requests signed // ResponseURL.
[ "SendResponseWithClient", "uploads", "the", "response", "to", "the", "requests", "signed", "ResponseURL", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/customresources.go#L167-L172
train
remind101/empire
pkg/cloudformation/customresources/customresources.go
SendResponse
func (c *ResponseClient) SendResponse(req Request, response Response) error { raw, err := json.Marshal(response) if err != nil { return err } r, err := http.NewRequest("PUT", req.ResponseURL, bytes.NewReader(raw)) if err != nil { return err } resp, err := c.client.Do(r) if err != nil { return err } defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) if code := resp.StatusCode; code/100 != 2 { return fmt.Errorf("unexpected response from pre-signed url: %v: %v", code, string(body)) } return nil }
go
func (c *ResponseClient) SendResponse(req Request, response Response) error { raw, err := json.Marshal(response) if err != nil { return err } r, err := http.NewRequest("PUT", req.ResponseURL, bytes.NewReader(raw)) if err != nil { return err } resp, err := c.client.Do(r) if err != nil { return err } defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) if code := resp.StatusCode; code/100 != 2 { return fmt.Errorf("unexpected response from pre-signed url: %v: %v", code, string(body)) } return nil }
[ "func", "(", "c", "*", "ResponseClient", ")", "SendResponse", "(", "req", "Request", ",", "response", "Response", ")", "error", "{", "raw", ",", "err", ":=", "json", ".", "Marshal", "(", "response", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "r", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "req", ".", "ResponseURL", ",", "bytes", ".", "NewReader", "(", "raw", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "Do", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n", "body", ",", "_", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n\n", "if", "code", ":=", "resp", ".", "StatusCode", ";", "code", "/", "100", "!=", "2", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "code", ",", "string", "(", "body", ")", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SendResponse sends the response to the request's ResponseURL.
[ "SendResponse", "sends", "the", "response", "to", "the", "request", "s", "ResponseURL", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/customresources.go#L182-L205
train
remind101/empire
pkg/cloudformation/customresources/customresources.go
WithTimeout
func WithTimeout(p Provisioner, timeout time.Duration, grace time.Duration) Provisioner { return &timeoutProvisioner{ Provisioner: p, timeout: timeout, grace: grace, } }
go
func WithTimeout(p Provisioner, timeout time.Duration, grace time.Duration) Provisioner { return &timeoutProvisioner{ Provisioner: p, timeout: timeout, grace: grace, } }
[ "func", "WithTimeout", "(", "p", "Provisioner", ",", "timeout", "time", ".", "Duration", ",", "grace", "time", ".", "Duration", ")", "Provisioner", "{", "return", "&", "timeoutProvisioner", "{", "Provisioner", ":", "p", ",", "timeout", ":", "timeout", ",", "grace", ":", "grace", ",", "}", "\n", "}" ]
// WithTimeout wraps a Provisioner with a context.WithTimeout.
[ "WithTimeout", "wraps", "a", "Provisioner", "with", "a", "context", ".", "WithTimeout", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/customresources.go#L208-L214
train
remind101/empire
pkg/cloudformation/customresources/types.go
Eq
func (i *IntValue) Eq(other *IntValue) bool { if i == nil { return other == nil } if other == nil { return i == nil } return *i == *other }
go
func (i *IntValue) Eq(other *IntValue) bool { if i == nil { return other == nil } if other == nil { return i == nil } return *i == *other }
[ "func", "(", "i", "*", "IntValue", ")", "Eq", "(", "other", "*", "IntValue", ")", "bool", "{", "if", "i", "==", "nil", "{", "return", "other", "==", "nil", "\n", "}", "\n\n", "if", "other", "==", "nil", "{", "return", "i", "==", "nil", "\n", "}", "\n\n", "return", "*", "i", "==", "*", "other", "\n", "}" ]
// Eq returns true of other is the same _value_ as i.
[ "Eq", "returns", "true", "of", "other", "is", "the", "same", "_value_", "as", "i", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/cloudformation/customresources/types.go#L20-L30
train
remind101/empire
stats/runtime.go
SampleEvery
func SampleEvery(stats Stats, t time.Duration) { c := time.Tick(t) for _ = range c { r := newRuntimeSample() r.drain(stats) } }
go
func SampleEvery(stats Stats, t time.Duration) { c := time.Tick(t) for _ = range c { r := newRuntimeSample() r.drain(stats) } }
[ "func", "SampleEvery", "(", "stats", "Stats", ",", "t", "time", ".", "Duration", ")", "{", "c", ":=", "time", ".", "Tick", "(", "t", ")", "\n", "for", "_", "=", "range", "c", "{", "r", ":=", "newRuntimeSample", "(", ")", "\n", "r", ".", "drain", "(", "stats", ")", "\n", "}", "\n", "}" ]
// SampleEvery enters a loop, sampling at the specified interval
[ "SampleEvery", "enters", "a", "loop", "sampling", "at", "the", "specified", "interval" ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/runtime.go#L14-L20
train
remind101/empire
stats/runtime.go
newRuntimeSample
func newRuntimeSample() *runtimeSample { r := &runtimeSample{MemStats: &runtime.MemStats{}} runtime.ReadMemStats(r.MemStats) r.NumGoroutine = runtime.NumGoroutine() return r }
go
func newRuntimeSample() *runtimeSample { r := &runtimeSample{MemStats: &runtime.MemStats{}} runtime.ReadMemStats(r.MemStats) r.NumGoroutine = runtime.NumGoroutine() return r }
[ "func", "newRuntimeSample", "(", ")", "*", "runtimeSample", "{", "r", ":=", "&", "runtimeSample", "{", "MemStats", ":", "&", "runtime", ".", "MemStats", "{", "}", "}", "\n", "runtime", ".", "ReadMemStats", "(", "r", ".", "MemStats", ")", "\n", "r", ".", "NumGoroutine", "=", "runtime", ".", "NumGoroutine", "(", ")", "\n", "return", "r", "\n", "}" ]
// newRuntimeSample samples the current runtime and returns a RuntimeSample.
[ "newRuntimeSample", "samples", "the", "current", "runtime", "and", "returns", "a", "RuntimeSample", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/runtime.go#L29-L34
train
remind101/empire
stats/runtime.go
drain
func (r *runtimeSample) drain(stats Stats) { stats.Gauge("runtime.NumGoroutine", float32(r.NumGoroutine), 1.0, nil) stats.Gauge("runtime.MemStats.Alloc", float32(r.MemStats.Alloc), 1.0, nil) stats.Gauge("runtime.MemStats.Frees", float32(r.MemStats.Frees), 1.0, nil) stats.Gauge("runtime.MemStats.HeapAlloc", float32(r.MemStats.HeapAlloc), 1.0, nil) stats.Gauge("runtime.MemStats.HeapIdle", float32(r.MemStats.HeapIdle), 1.0, nil) stats.Gauge("runtime.MemStats.HeapObjects", float32(r.MemStats.HeapObjects), 1.0, nil) stats.Gauge("runtime.MemStats.HeapReleased", float32(r.MemStats.HeapReleased), 1.0, nil) stats.Gauge("runtime.MemStats.HeapSys", float32(r.MemStats.HeapSys), 1.0, nil) stats.Gauge("runtime.MemStats.LastGC", float32(r.MemStats.LastGC), 1.0, nil) stats.Gauge("runtime.MemStats.Lookups", float32(r.MemStats.Lookups), 1.0, nil) stats.Gauge("runtime.MemStats.Mallocs", float32(r.MemStats.Mallocs), 1.0, nil) stats.Gauge("runtime.MemStats.MCacheInuse", float32(r.MemStats.MCacheInuse), 1.0, nil) stats.Gauge("runtime.MemStats.MCacheSys", float32(r.MemStats.MCacheSys), 1.0, nil) stats.Gauge("runtime.MemStats.MSpanInuse", float32(r.MemStats.MSpanInuse), 1.0, nil) stats.Gauge("runtime.MemStats.MSpanSys", float32(r.MemStats.MSpanSys), 1.0, nil) stats.Gauge("runtime.MemStats.NextGC", float32(r.MemStats.NextGC), 1.0, nil) stats.Gauge("runtime.MemStats.NumGC", float32(r.MemStats.NumGC), 1.0, nil) stats.Gauge("runtime.MemStats.StackInuse", float32(r.MemStats.StackInuse), 1.0, nil) }
go
func (r *runtimeSample) drain(stats Stats) { stats.Gauge("runtime.NumGoroutine", float32(r.NumGoroutine), 1.0, nil) stats.Gauge("runtime.MemStats.Alloc", float32(r.MemStats.Alloc), 1.0, nil) stats.Gauge("runtime.MemStats.Frees", float32(r.MemStats.Frees), 1.0, nil) stats.Gauge("runtime.MemStats.HeapAlloc", float32(r.MemStats.HeapAlloc), 1.0, nil) stats.Gauge("runtime.MemStats.HeapIdle", float32(r.MemStats.HeapIdle), 1.0, nil) stats.Gauge("runtime.MemStats.HeapObjects", float32(r.MemStats.HeapObjects), 1.0, nil) stats.Gauge("runtime.MemStats.HeapReleased", float32(r.MemStats.HeapReleased), 1.0, nil) stats.Gauge("runtime.MemStats.HeapSys", float32(r.MemStats.HeapSys), 1.0, nil) stats.Gauge("runtime.MemStats.LastGC", float32(r.MemStats.LastGC), 1.0, nil) stats.Gauge("runtime.MemStats.Lookups", float32(r.MemStats.Lookups), 1.0, nil) stats.Gauge("runtime.MemStats.Mallocs", float32(r.MemStats.Mallocs), 1.0, nil) stats.Gauge("runtime.MemStats.MCacheInuse", float32(r.MemStats.MCacheInuse), 1.0, nil) stats.Gauge("runtime.MemStats.MCacheSys", float32(r.MemStats.MCacheSys), 1.0, nil) stats.Gauge("runtime.MemStats.MSpanInuse", float32(r.MemStats.MSpanInuse), 1.0, nil) stats.Gauge("runtime.MemStats.MSpanSys", float32(r.MemStats.MSpanSys), 1.0, nil) stats.Gauge("runtime.MemStats.NextGC", float32(r.MemStats.NextGC), 1.0, nil) stats.Gauge("runtime.MemStats.NumGC", float32(r.MemStats.NumGC), 1.0, nil) stats.Gauge("runtime.MemStats.StackInuse", float32(r.MemStats.StackInuse), 1.0, nil) }
[ "func", "(", "r", "*", "runtimeSample", ")", "drain", "(", "stats", "Stats", ")", "{", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "NumGoroutine", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "Alloc", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "Frees", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "HeapAlloc", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "HeapIdle", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "HeapObjects", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "HeapReleased", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "HeapSys", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "LastGC", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "Lookups", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "Mallocs", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "MCacheInuse", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "MCacheSys", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "MSpanInuse", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "MSpanSys", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "NextGC", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "NumGC", ")", ",", "1.0", ",", "nil", ")", "\n", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float32", "(", "r", ".", "MemStats", ".", "StackInuse", ")", ",", "1.0", ",", "nil", ")", "\n", "}" ]
// drain drains all of the metrics.
[ "drain", "drains", "all", "of", "the", "metrics", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/runtime.go#L37-L56
train
remind101/empire
pkg/heroku/app_transfer.go
AppTransferCreate
func (c *Client) AppTransferCreate(app string, recipient string) (*AppTransfer, error) { params := struct { App string `json:"app"` Recipient string `json:"recipient"` }{ App: app, Recipient: recipient, } var appTransferRes AppTransfer return &appTransferRes, c.Post(&appTransferRes, "/account/app-transfers", params) }
go
func (c *Client) AppTransferCreate(app string, recipient string) (*AppTransfer, error) { params := struct { App string `json:"app"` Recipient string `json:"recipient"` }{ App: app, Recipient: recipient, } var appTransferRes AppTransfer return &appTransferRes, c.Post(&appTransferRes, "/account/app-transfers", params) }
[ "func", "(", "c", "*", "Client", ")", "AppTransferCreate", "(", "app", "string", ",", "recipient", "string", ")", "(", "*", "AppTransfer", ",", "error", ")", "{", "params", ":=", "struct", "{", "App", "string", "`json:\"app\"`", "\n", "Recipient", "string", "`json:\"recipient\"`", "\n", "}", "{", "App", ":", "app", ",", "Recipient", ":", "recipient", ",", "}", "\n", "var", "appTransferRes", "AppTransfer", "\n", "return", "&", "appTransferRes", ",", "c", ".", "Post", "(", "&", "appTransferRes", ",", "\"", "\"", ",", "params", ")", "\n", "}" ]
// Create a new app transfer. // // app is the unique identifier of app or unique name of app. recipient is the // unique email address of account or unique identifier of an account.
[ "Create", "a", "new", "app", "transfer", ".", "app", "is", "the", "unique", "identifier", "of", "app", "or", "unique", "name", "of", "app", ".", "recipient", "is", "the", "unique", "email", "address", "of", "account", "or", "unique", "identifier", "of", "an", "account", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app_transfer.go#L49-L59
train
remind101/empire
pkg/heroku/app_transfer.go
AppTransferInfo
func (c *Client) AppTransferInfo(appTransferIdentity string) (*AppTransfer, error) { var appTransfer AppTransfer return &appTransfer, c.Get(&appTransfer, "/account/app-transfers/"+appTransferIdentity) }
go
func (c *Client) AppTransferInfo(appTransferIdentity string) (*AppTransfer, error) { var appTransfer AppTransfer return &appTransfer, c.Get(&appTransfer, "/account/app-transfers/"+appTransferIdentity) }
[ "func", "(", "c", "*", "Client", ")", "AppTransferInfo", "(", "appTransferIdentity", "string", ")", "(", "*", "AppTransfer", ",", "error", ")", "{", "var", "appTransfer", "AppTransfer", "\n", "return", "&", "appTransfer", ",", "c", ".", "Get", "(", "&", "appTransfer", ",", "\"", "\"", "+", "appTransferIdentity", ")", "\n", "}" ]
// Info for existing app transfer. // // appTransferIdentity is the unique identifier of the AppTransfer.
[ "Info", "for", "existing", "app", "transfer", ".", "appTransferIdentity", "is", "the", "unique", "identifier", "of", "the", "AppTransfer", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app_transfer.go#L71-L74
train
remind101/empire
pkg/heroku/app_transfer.go
AppTransferList
func (c *Client) AppTransferList(lr *ListRange) ([]AppTransfer, error) { req, err := c.NewRequest("GET", "/account/app-transfers", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var appTransfersRes []AppTransfer return appTransfersRes, c.DoReq(req, &appTransfersRes) }
go
func (c *Client) AppTransferList(lr *ListRange) ([]AppTransfer, error) { req, err := c.NewRequest("GET", "/account/app-transfers", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var appTransfersRes []AppTransfer return appTransfersRes, c.DoReq(req, &appTransfersRes) }
[ "func", "(", "c", "*", "Client", ")", "AppTransferList", "(", "lr", "*", "ListRange", ")", "(", "[", "]", "AppTransfer", ",", "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", "appTransfersRes", "[", "]", "AppTransfer", "\n", "return", "appTransfersRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "appTransfersRes", ")", "\n", "}" ]
// List existing apps transfers. // // lr is an optional ListRange that sets the Range options for the paginated // list of results.
[ "List", "existing", "apps", "transfers", ".", "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/app_transfer.go#L80-L92
train
remind101/empire
pkg/heroku/app_transfer.go
AppTransferUpdate
func (c *Client) AppTransferUpdate(appTransferIdentity string, state string) (*AppTransfer, error) { params := struct { State string `json:"state"` }{ State: state, } var appTransferRes AppTransfer return &appTransferRes, c.Patch(&appTransferRes, "/account/app-transfers/"+appTransferIdentity, params) }
go
func (c *Client) AppTransferUpdate(appTransferIdentity string, state string) (*AppTransfer, error) { params := struct { State string `json:"state"` }{ State: state, } var appTransferRes AppTransfer return &appTransferRes, c.Patch(&appTransferRes, "/account/app-transfers/"+appTransferIdentity, params) }
[ "func", "(", "c", "*", "Client", ")", "AppTransferUpdate", "(", "appTransferIdentity", "string", ",", "state", "string", ")", "(", "*", "AppTransfer", ",", "error", ")", "{", "params", ":=", "struct", "{", "State", "string", "`json:\"state\"`", "\n", "}", "{", "State", ":", "state", ",", "}", "\n", "var", "appTransferRes", "AppTransfer", "\n", "return", "&", "appTransferRes", ",", "c", ".", "Patch", "(", "&", "appTransferRes", ",", "\"", "\"", "+", "appTransferIdentity", ",", "params", ")", "\n", "}" ]
// Update an existing app transfer. // // appTransferIdentity is the unique identifier of the AppTransfer. state is the // the current state of an app transfer.
[ "Update", "an", "existing", "app", "transfer", ".", "appTransferIdentity", "is", "the", "unique", "identifier", "of", "the", "AppTransfer", ".", "state", "is", "the", "the", "current", "state", "of", "an", "app", "transfer", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app_transfer.go#L98-L106
train
remind101/empire
registry/registry.go
DockerDaemon
func DockerDaemon(c *dockerutil.Client) *DockerDaemonRegistry { e := multiExtractor( newFileExtractor(c), newCMDExtractor(c), ) return &DockerDaemonRegistry{ docker: c, extractor: e, } }
go
func DockerDaemon(c *dockerutil.Client) *DockerDaemonRegistry { e := multiExtractor( newFileExtractor(c), newCMDExtractor(c), ) return &DockerDaemonRegistry{ docker: c, extractor: e, } }
[ "func", "DockerDaemon", "(", "c", "*", "dockerutil", ".", "Client", ")", "*", "DockerDaemonRegistry", "{", "e", ":=", "multiExtractor", "(", "newFileExtractor", "(", "c", ")", ",", "newCMDExtractor", "(", "c", ")", ",", ")", "\n", "return", "&", "DockerDaemonRegistry", "{", "docker", ":", "c", ",", "extractor", ":", "e", ",", "}", "\n", "}" ]
// DockerDaemon returns an empire.ImageRegistry that uses a local Docker Daemon // to extract procfiles and resolve images.
[ "DockerDaemon", "returns", "an", "empire", ".", "ImageRegistry", "that", "uses", "a", "local", "Docker", "Daemon", "to", "extract", "procfiles", "and", "resolve", "images", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L66-L75
train
remind101/empire
registry/registry.go
multiExtractor
func multiExtractor(extractors ...empire.ProcfileExtractor) empire.ProcfileExtractor { return empire.ProcfileExtractorFunc(func(ctx context.Context, image image.Image, w *jsonmessage.Stream) ([]byte, error) { for _, extractor := range extractors { p, err := extractor.ExtractProcfile(ctx, image, w) // Yay! if err == nil { return p, nil } // Try the next one if _, ok := err.(*empire.ProcfileError); ok { continue } // Bubble up the error return p, err } return nil, &empire.ProcfileError{ Err: errors.New("no suitable Procfile extractor found"), } }) }
go
func multiExtractor(extractors ...empire.ProcfileExtractor) empire.ProcfileExtractor { return empire.ProcfileExtractorFunc(func(ctx context.Context, image image.Image, w *jsonmessage.Stream) ([]byte, error) { for _, extractor := range extractors { p, err := extractor.ExtractProcfile(ctx, image, w) // Yay! if err == nil { return p, nil } // Try the next one if _, ok := err.(*empire.ProcfileError); ok { continue } // Bubble up the error return p, err } return nil, &empire.ProcfileError{ Err: errors.New("no suitable Procfile extractor found"), } }) }
[ "func", "multiExtractor", "(", "extractors", "...", "empire", ".", "ProcfileExtractor", ")", "empire", ".", "ProcfileExtractor", "{", "return", "empire", ".", "ProcfileExtractorFunc", "(", "func", "(", "ctx", "context", ".", "Context", ",", "image", "image", ".", "Image", ",", "w", "*", "jsonmessage", ".", "Stream", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "for", "_", ",", "extractor", ":=", "range", "extractors", "{", "p", ",", "err", ":=", "extractor", ".", "ExtractProcfile", "(", "ctx", ",", "image", ",", "w", ")", "\n\n", "// Yay!", "if", "err", "==", "nil", "{", "return", "p", ",", "nil", "\n", "}", "\n\n", "// Try the next one", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "empire", ".", "ProcfileError", ")", ";", "ok", "{", "continue", "\n", "}", "\n\n", "// Bubble up the error", "return", "p", ",", "err", "\n", "}", "\n\n", "return", "nil", ",", "&", "empire", ".", "ProcfileError", "{", "Err", ":", "errors", ".", "New", "(", "\"", "\"", ")", ",", "}", "\n", "}", ")", "\n", "}" ]
// multiExtractor is an Extractor implementation that tries multiple Extractors // in succession until one succeeds.
[ "multiExtractor", "is", "an", "Extractor", "implementation", "that", "tries", "multiple", "Extractors", "in", "succession", "until", "one", "succeeds", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L166-L189
train
remind101/empire
registry/registry.go
ExtractProcfile
func (e *fileExtractor) ExtractProcfile(ctx context.Context, img image.Image, w *jsonmessage.Stream) ([]byte, error) { c, err := e.createContainer(ctx, img) if err != nil { return nil, err } defer e.removeContainer(ctx, c.ID) pfile, err := e.procfile(ctx, c.ID) if err != nil { return nil, err } b, err := e.copyFile(ctx, c.ID, pfile) if err != nil { return nil, &empire.ProcfileError{Err: err} } w.Encode(jsonmessage.JSONMessage{ Status: fmt.Sprintf("Status: Extracted Procfile from %q", pfile), }) return b, nil }
go
func (e *fileExtractor) ExtractProcfile(ctx context.Context, img image.Image, w *jsonmessage.Stream) ([]byte, error) { c, err := e.createContainer(ctx, img) if err != nil { return nil, err } defer e.removeContainer(ctx, c.ID) pfile, err := e.procfile(ctx, c.ID) if err != nil { return nil, err } b, err := e.copyFile(ctx, c.ID, pfile) if err != nil { return nil, &empire.ProcfileError{Err: err} } w.Encode(jsonmessage.JSONMessage{ Status: fmt.Sprintf("Status: Extracted Procfile from %q", pfile), }) return b, nil }
[ "func", "(", "e", "*", "fileExtractor", ")", "ExtractProcfile", "(", "ctx", "context", ".", "Context", ",", "img", "image", ".", "Image", ",", "w", "*", "jsonmessage", ".", "Stream", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "c", ",", "err", ":=", "e", ".", "createContainer", "(", "ctx", ",", "img", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "defer", "e", ".", "removeContainer", "(", "ctx", ",", "c", ".", "ID", ")", "\n\n", "pfile", ",", "err", ":=", "e", ".", "procfile", "(", "ctx", ",", "c", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "b", ",", "err", ":=", "e", ".", "copyFile", "(", "ctx", ",", "c", ".", "ID", ",", "pfile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "&", "empire", ".", "ProcfileError", "{", "Err", ":", "err", "}", "\n", "}", "\n\n", "w", ".", "Encode", "(", "jsonmessage", ".", "JSONMessage", "{", "Status", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pfile", ")", ",", "}", ")", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// Extract implements Extractor Extract.
[ "Extract", "implements", "Extractor", "Extract", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L203-L226
train
remind101/empire
registry/registry.go
procfile
func (e *fileExtractor) procfile(ctx context.Context, id string) (string, error) { p := "" c, err := e.client.InspectContainer(id) if err != nil { return "", err } if c.Config != nil { p = c.Config.WorkingDir } return path.Join(p, empire.Procfile), nil }
go
func (e *fileExtractor) procfile(ctx context.Context, id string) (string, error) { p := "" c, err := e.client.InspectContainer(id) if err != nil { return "", err } if c.Config != nil { p = c.Config.WorkingDir } return path.Join(p, empire.Procfile), nil }
[ "func", "(", "e", "*", "fileExtractor", ")", "procfile", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "string", ",", "error", ")", "{", "p", ":=", "\"", "\"", "\n\n", "c", ",", "err", ":=", "e", ".", "client", ".", "InspectContainer", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "c", ".", "Config", "!=", "nil", "{", "p", "=", "c", ".", "Config", ".", "WorkingDir", "\n", "}", "\n\n", "return", "path", ".", "Join", "(", "p", ",", "empire", ".", "Procfile", ")", ",", "nil", "\n", "}" ]
// procfile returns the path to the Procfile. If the container has a WORKDIR // set, then this will return a path to the Procfile within that directory.
[ "procfile", "returns", "the", "path", "to", "the", "Procfile", ".", "If", "the", "container", "has", "a", "WORKDIR", "set", "then", "this", "will", "return", "a", "path", "to", "the", "Procfile", "within", "that", "directory", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L230-L243
train
remind101/empire
registry/registry.go
createContainer
func (e *fileExtractor) createContainer(ctx context.Context, img image.Image) (*docker.Container, error) { return e.client.CreateContainer(ctx, docker.CreateContainerOptions{ Config: &docker.Config{ Image: img.String(), }, }) }
go
func (e *fileExtractor) createContainer(ctx context.Context, img image.Image) (*docker.Container, error) { return e.client.CreateContainer(ctx, docker.CreateContainerOptions{ Config: &docker.Config{ Image: img.String(), }, }) }
[ "func", "(", "e", "*", "fileExtractor", ")", "createContainer", "(", "ctx", "context", ".", "Context", ",", "img", "image", ".", "Image", ")", "(", "*", "docker", ".", "Container", ",", "error", ")", "{", "return", "e", ".", "client", ".", "CreateContainer", "(", "ctx", ",", "docker", ".", "CreateContainerOptions", "{", "Config", ":", "&", "docker", ".", "Config", "{", "Image", ":", "img", ".", "String", "(", ")", ",", "}", ",", "}", ")", "\n", "}" ]
// createContainer creates a new docker container for the given docker image.
[ "createContainer", "creates", "a", "new", "docker", "container", "for", "the", "given", "docker", "image", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L246-L252
train
remind101/empire
registry/registry.go
removeContainer
func (e *fileExtractor) removeContainer(ctx context.Context, containerID string) error { return e.client.RemoveContainer(ctx, docker.RemoveContainerOptions{ ID: containerID, }) }
go
func (e *fileExtractor) removeContainer(ctx context.Context, containerID string) error { return e.client.RemoveContainer(ctx, docker.RemoveContainerOptions{ ID: containerID, }) }
[ "func", "(", "e", "*", "fileExtractor", ")", "removeContainer", "(", "ctx", "context", ".", "Context", ",", "containerID", "string", ")", "error", "{", "return", "e", ".", "client", ".", "RemoveContainer", "(", "ctx", ",", "docker", ".", "RemoveContainerOptions", "{", "ID", ":", "containerID", ",", "}", ")", "\n", "}" ]
// removeContainer removes a container by its ID.
[ "removeContainer", "removes", "a", "container", "by", "its", "ID", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L255-L259
train
remind101/empire
registry/registry.go
copyFile
func (e *fileExtractor) copyFile(ctx context.Context, containerID, path string) ([]byte, error) { var buf bytes.Buffer if err := e.client.CopyFromContainer(ctx, docker.CopyFromContainerOptions{ Container: containerID, Resource: path, OutputStream: &buf, }); err != nil { return nil, err } // Open the tar archive for reading. r := bytes.NewReader(buf.Bytes()) return firstFile(tar.NewReader(r)) }
go
func (e *fileExtractor) copyFile(ctx context.Context, containerID, path string) ([]byte, error) { var buf bytes.Buffer if err := e.client.CopyFromContainer(ctx, docker.CopyFromContainerOptions{ Container: containerID, Resource: path, OutputStream: &buf, }); err != nil { return nil, err } // Open the tar archive for reading. r := bytes.NewReader(buf.Bytes()) return firstFile(tar.NewReader(r)) }
[ "func", "(", "e", "*", "fileExtractor", ")", "copyFile", "(", "ctx", "context", ".", "Context", ",", "containerID", ",", "path", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "buf", "bytes", ".", "Buffer", "\n", "if", "err", ":=", "e", ".", "client", ".", "CopyFromContainer", "(", "ctx", ",", "docker", ".", "CopyFromContainerOptions", "{", "Container", ":", "containerID", ",", "Resource", ":", "path", ",", "OutputStream", ":", "&", "buf", ",", "}", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "// Open the tar archive for reading.", "r", ":=", "bytes", ".", "NewReader", "(", "buf", ".", "Bytes", "(", ")", ")", "\n\n", "return", "firstFile", "(", "tar", ".", "NewReader", "(", "r", ")", ")", "\n", "}" ]
// copyFile copies a file from a container.
[ "copyFile", "copies", "a", "file", "from", "a", "container", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L262-L276
train
remind101/empire
registry/registry.go
firstFile
func firstFile(tr *tar.Reader) ([]byte, error) { if _, err := tr.Next(); err != nil { return nil, err } var buf bytes.Buffer if _, err := io.Copy(&buf, tr); err != nil { return nil, err } return buf.Bytes(), nil }
go
func firstFile(tr *tar.Reader) ([]byte, error) { if _, err := tr.Next(); err != nil { return nil, err } var buf bytes.Buffer if _, err := io.Copy(&buf, tr); err != nil { return nil, err } return buf.Bytes(), nil }
[ "func", "firstFile", "(", "tr", "*", "tar", ".", "Reader", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "_", ",", "err", ":=", "tr", ".", "Next", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "var", "buf", "bytes", ".", "Buffer", "\n", "if", "_", ",", "err", ":=", "io", ".", "Copy", "(", "&", "buf", ",", "tr", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// firstFile extracts the first file from a tar archive.
[ "firstFile", "extracts", "the", "first", "file", "from", "a", "tar", "archive", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/registry/registry.go#L279-L290
train
remind101/empire
pkg/heroku/release.go
ReleaseInfo
func (c *Client) ReleaseInfo(appIdentity string, releaseIdentity string) (*Release, error) { var release Release return &release, c.Get(&release, "/apps/"+appIdentity+"/releases/"+releaseIdentity) }
go
func (c *Client) ReleaseInfo(appIdentity string, releaseIdentity string) (*Release, error) { var release Release return &release, c.Get(&release, "/apps/"+appIdentity+"/releases/"+releaseIdentity) }
[ "func", "(", "c", "*", "Client", ")", "ReleaseInfo", "(", "appIdentity", "string", ",", "releaseIdentity", "string", ")", "(", "*", "Release", ",", "error", ")", "{", "var", "release", "Release", "\n", "return", "&", "release", ",", "c", ".", "Get", "(", "&", "release", ",", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", "+", "releaseIdentity", ")", "\n", "}" ]
// Info for existing release. // // appIdentity is the unique identifier of the Release's App. releaseIdentity is // the unique identifier of the Release.
[ "Info", "for", "existing", "release", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "Release", "s", "App", ".", "releaseIdentity", "is", "the", "unique", "identifier", "of", "the", "Release", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/release.go#L45-L48
train
remind101/empire
pkg/heroku/release.go
ReleaseList
func (c *Client) ReleaseList(appIdentity string, lr *ListRange) ([]Release, error) { req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/releases", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var releasesRes []Release return releasesRes, c.DoReq(req, &releasesRes) }
go
func (c *Client) ReleaseList(appIdentity string, lr *ListRange) ([]Release, error) { req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/releases", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var releasesRes []Release return releasesRes, c.DoReq(req, &releasesRes) }
[ "func", "(", "c", "*", "Client", ")", "ReleaseList", "(", "appIdentity", "string", ",", "lr", "*", "ListRange", ")", "(", "[", "]", "Release", ",", "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", "releasesRes", "[", "]", "Release", "\n", "return", "releasesRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "releasesRes", ")", "\n", "}" ]
// List existing releases. // // appIdentity is the unique identifier of the Release's App. lr is an optional // ListRange that sets the Range options for the paginated list of results.
[ "List", "existing", "releases", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "Release", "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/release.go#L54-L66
train
remind101/empire
pkg/heroku/release.go
ReleaseCreate
func (c *Client) ReleaseCreate(appIdentity string, slug string, options *ReleaseCreateOpts) (*Release, error) { params := struct { Slug string `json:"slug"` Description *string `json:"description,omitempty"` }{ Slug: slug, } if options != nil { params.Description = options.Description } var releaseRes Release return &releaseRes, c.Post(&releaseRes, "/apps/"+appIdentity+"/releases", params) }
go
func (c *Client) ReleaseCreate(appIdentity string, slug string, options *ReleaseCreateOpts) (*Release, error) { params := struct { Slug string `json:"slug"` Description *string `json:"description,omitempty"` }{ Slug: slug, } if options != nil { params.Description = options.Description } var releaseRes Release return &releaseRes, c.Post(&releaseRes, "/apps/"+appIdentity+"/releases", params) }
[ "func", "(", "c", "*", "Client", ")", "ReleaseCreate", "(", "appIdentity", "string", ",", "slug", "string", ",", "options", "*", "ReleaseCreateOpts", ")", "(", "*", "Release", ",", "error", ")", "{", "params", ":=", "struct", "{", "Slug", "string", "`json:\"slug\"`", "\n", "Description", "*", "string", "`json:\"description,omitempty\"`", "\n", "}", "{", "Slug", ":", "slug", ",", "}", "\n", "if", "options", "!=", "nil", "{", "params", ".", "Description", "=", "options", ".", "Description", "\n", "}", "\n", "var", "releaseRes", "Release", "\n", "return", "&", "releaseRes", ",", "c", ".", "Post", "(", "&", "releaseRes", ",", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", ",", "params", ")", "\n", "}" ]
// Create new release. The API cannot be used to create releases on Bamboo apps. // // appIdentity is the unique identifier of the Release's App. slug is the unique // identifier of slug. options is the struct of optional parameters for this // action.
[ "Create", "new", "release", ".", "The", "API", "cannot", "be", "used", "to", "create", "releases", "on", "Bamboo", "apps", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "Release", "s", "App", ".", "slug", "is", "the", "unique", "identifier", "of", "slug", ".", "options", "is", "the", "struct", "of", "optional", "parameters", "for", "this", "action", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/release.go#L73-L85
train
remind101/empire
pkg/heroku/release.go
ReleaseRollback
func (c *Client) ReleaseRollback(appIdentity, release, message string) (*Release, error) { params := struct { Release string `json:"release"` }{ Release: release, } rh := RequestHeaders{CommitMessage: message} var releaseRes Release return &releaseRes, c.PostWithHeaders(&releaseRes, "/apps/"+appIdentity+"/releases", params, rh.Headers()) }
go
func (c *Client) ReleaseRollback(appIdentity, release, message string) (*Release, error) { params := struct { Release string `json:"release"` }{ Release: release, } rh := RequestHeaders{CommitMessage: message} var releaseRes Release return &releaseRes, c.PostWithHeaders(&releaseRes, "/apps/"+appIdentity+"/releases", params, rh.Headers()) }
[ "func", "(", "c", "*", "Client", ")", "ReleaseRollback", "(", "appIdentity", ",", "release", ",", "message", "string", ")", "(", "*", "Release", ",", "error", ")", "{", "params", ":=", "struct", "{", "Release", "string", "`json:\"release\"`", "\n", "}", "{", "Release", ":", "release", ",", "}", "\n", "rh", ":=", "RequestHeaders", "{", "CommitMessage", ":", "message", "}", "\n", "var", "releaseRes", "Release", "\n", "return", "&", "releaseRes", ",", "c", ".", "PostWithHeaders", "(", "&", "releaseRes", ",", "\"", "\"", "+", "appIdentity", "+", "\"", "\"", ",", "params", ",", "rh", ".", "Headers", "(", ")", ")", "\n", "}" ]
// Rollback to an existing release. // // appIdentity is the unique identifier of the Release's App. release is the // unique identifier of release.
[ "Rollback", "to", "an", "existing", "release", ".", "appIdentity", "is", "the", "unique", "identifier", "of", "the", "Release", "s", "App", ".", "release", "is", "the", "unique", "identifier", "of", "release", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/release.go#L97-L106
train
remind101/empire
pkg/jsonmessage/jsonmessage.go
NewStream
func NewStream(w io.Writer) *Stream { return &Stream{ Writer: w, enc: json.NewEncoder(w), } }
go
func NewStream(w io.Writer) *Stream { return &Stream{ Writer: w, enc: json.NewEncoder(w), } }
[ "func", "NewStream", "(", "w", "io", ".", "Writer", ")", "*", "Stream", "{", "return", "&", "Stream", "{", "Writer", ":", "w", ",", "enc", ":", "json", ".", "NewEncoder", "(", "w", ")", ",", "}", "\n", "}" ]
// NewStream returns a new Stream backed by w.
[ "NewStream", "returns", "a", "new", "Stream", "backed", "by", "w", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/jsonmessage/jsonmessage.go#L18-L23
train
remind101/empire
pkg/jsonmessage/jsonmessage.go
Encode
func (w *Stream) Encode(m JSONMessage) error { return w.enc.Encode(m) }
go
func (w *Stream) Encode(m JSONMessage) error { return w.enc.Encode(m) }
[ "func", "(", "w", "*", "Stream", ")", "Encode", "(", "m", "JSONMessage", ")", "error", "{", "return", "w", ".", "enc", ".", "Encode", "(", "m", ")", "\n", "}" ]
// Encode encodes m into the stream and implements the jsonmessage.Writer // interface.
[ "Encode", "encodes", "m", "into", "the", "stream", "and", "implements", "the", "jsonmessage", ".", "Writer", "interface", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/jsonmessage/jsonmessage.go#L27-L29
train
remind101/empire
server/heroku/errors.go
Unauthorized
func Unauthorized(reason error) *ErrorResource { if reason == nil { return ErrUnauthorized } return &ErrorResource{ Status: http.StatusUnauthorized, ID: "unauthorized", Message: reason.Error(), } }
go
func Unauthorized(reason error) *ErrorResource { if reason == nil { return ErrUnauthorized } return &ErrorResource{ Status: http.StatusUnauthorized, ID: "unauthorized", Message: reason.Error(), } }
[ "func", "Unauthorized", "(", "reason", "error", ")", "*", "ErrorResource", "{", "if", "reason", "==", "nil", "{", "return", "ErrUnauthorized", "\n", "}", "\n\n", "return", "&", "ErrorResource", "{", "Status", ":", "http", ".", "StatusUnauthorized", ",", "ID", ":", "\"", "\"", ",", "Message", ":", "reason", ".", "Error", "(", ")", ",", "}", "\n", "}" ]
// Returns an appropriate ErrorResource when a request is unauthorized.
[ "Returns", "an", "appropriate", "ErrorResource", "when", "a", "request", "is", "unauthorized", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/errors.go#L95-L105
train
remind101/empire
server/heroku/errors.go
SAMLUnauthorized
func SAMLUnauthorized(loginURL string) func(error) *ErrorResource { return func(reason error) *ErrorResource { if reason == nil { reason = errors.New("Request not authenticated, API token is missing, invalid or expired") } return &ErrorResource{ Status: http.StatusUnauthorized, ID: "saml_unauthorized", Message: fmt.Sprintf("%s. Login at %s", reason, loginURL), } } }
go
func SAMLUnauthorized(loginURL string) func(error) *ErrorResource { return func(reason error) *ErrorResource { if reason == nil { reason = errors.New("Request not authenticated, API token is missing, invalid or expired") } return &ErrorResource{ Status: http.StatusUnauthorized, ID: "saml_unauthorized", Message: fmt.Sprintf("%s. Login at %s", reason, loginURL), } } }
[ "func", "SAMLUnauthorized", "(", "loginURL", "string", ")", "func", "(", "error", ")", "*", "ErrorResource", "{", "return", "func", "(", "reason", "error", ")", "*", "ErrorResource", "{", "if", "reason", "==", "nil", "{", "reason", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "&", "ErrorResource", "{", "Status", ":", "http", ".", "StatusUnauthorized", ",", "ID", ":", "\"", "\"", ",", "Message", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "reason", ",", "loginURL", ")", ",", "}", "\n", "}", "\n", "}" ]
// SAMLUnauthorized can be used in place of Unauthorized to return a link to // login via SAML.
[ "SAMLUnauthorized", "can", "be", "used", "in", "place", "of", "Unauthorized", "to", "return", "a", "link", "to", "login", "via", "SAML", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/errors.go#L109-L121
train
remind101/empire
server/heroku/errors.go
errHandler
func errHandler(err error) handlerFunc { return func(w http.ResponseWriter, r *http.Request) error { return err } }
go
func errHandler(err error) handlerFunc { return func(w http.ResponseWriter, r *http.Request) error { return err } }
[ "func", "errHandler", "(", "err", "error", ")", "handlerFunc", "{", "return", "func", "(", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ")", "error", "{", "return", "err", "\n", "}", "\n", "}" ]
// errHandler returns a handler that responds with the given error.
[ "errHandler", "returns", "a", "handler", "that", "responds", "with", "the", "given", "error", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/errors.go#L124-L128
train
remind101/empire
pkg/heroku/key.go
KeyCreate
func (c *Client) KeyCreate(publicKey string) (*Key, error) { params := struct { PublicKey string `json:"public_key"` }{ PublicKey: publicKey, } var keyRes Key return &keyRes, c.Post(&keyRes, "/account/keys", params) }
go
func (c *Client) KeyCreate(publicKey string) (*Key, error) { params := struct { PublicKey string `json:"public_key"` }{ PublicKey: publicKey, } var keyRes Key return &keyRes, c.Post(&keyRes, "/account/keys", params) }
[ "func", "(", "c", "*", "Client", ")", "KeyCreate", "(", "publicKey", "string", ")", "(", "*", "Key", ",", "error", ")", "{", "params", ":=", "struct", "{", "PublicKey", "string", "`json:\"public_key\"`", "\n", "}", "{", "PublicKey", ":", "publicKey", ",", "}", "\n", "var", "keyRes", "Key", "\n", "return", "&", "keyRes", ",", "c", ".", "Post", "(", "&", "keyRes", ",", "\"", "\"", ",", "params", ")", "\n", "}" ]
// Create a new key. // // publicKey is the full public_key as uploaded.
[ "Create", "a", "new", "key", ".", "publicKey", "is", "the", "full", "public_key", "as", "uploaded", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/key.go#L39-L47
train
remind101/empire
pkg/heroku/key.go
KeyInfo
func (c *Client) KeyInfo(keyIdentity string) (*Key, error) { var key Key return &key, c.Get(&key, "/account/keys/"+keyIdentity) }
go
func (c *Client) KeyInfo(keyIdentity string) (*Key, error) { var key Key return &key, c.Get(&key, "/account/keys/"+keyIdentity) }
[ "func", "(", "c", "*", "Client", ")", "KeyInfo", "(", "keyIdentity", "string", ")", "(", "*", "Key", ",", "error", ")", "{", "var", "key", "Key", "\n", "return", "&", "key", ",", "c", ".", "Get", "(", "&", "key", ",", "\"", "\"", "+", "keyIdentity", ")", "\n", "}" ]
// Info for existing key. // // keyIdentity is the unique identifier of the Key.
[ "Info", "for", "existing", "key", ".", "keyIdentity", "is", "the", "unique", "identifier", "of", "the", "Key", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/key.go#L59-L62
train
remind101/empire
pkg/heroku/key.go
KeyList
func (c *Client) KeyList(lr *ListRange) ([]Key, error) { req, err := c.NewRequest("GET", "/account/keys", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var keysRes []Key return keysRes, c.DoReq(req, &keysRes) }
go
func (c *Client) KeyList(lr *ListRange) ([]Key, error) { req, err := c.NewRequest("GET", "/account/keys", nil, nil) if err != nil { return nil, err } if lr != nil { lr.SetHeader(req) } var keysRes []Key return keysRes, c.DoReq(req, &keysRes) }
[ "func", "(", "c", "*", "Client", ")", "KeyList", "(", "lr", "*", "ListRange", ")", "(", "[", "]", "Key", ",", "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", "keysRes", "[", "]", "Key", "\n", "return", "keysRes", ",", "c", ".", "DoReq", "(", "req", ",", "&", "keysRes", ")", "\n", "}" ]
// List existing keys. // // lr is an optional ListRange that sets the Range options for the paginated // list of results.
[ "List", "existing", "keys", ".", "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/key.go#L68-L80
train
remind101/empire
server/auth/auth.go
PrependAuthenticator
func (a *Auth) PrependAuthenticator(name string, authenticator Authenticator) *Auth { c := a.copy() strategy := &Strategy{ Name: name, Authenticator: authenticator, } c.Strategies = append([]*Strategy{strategy}, c.Strategies...) return c }
go
func (a *Auth) PrependAuthenticator(name string, authenticator Authenticator) *Auth { c := a.copy() strategy := &Strategy{ Name: name, Authenticator: authenticator, } c.Strategies = append([]*Strategy{strategy}, c.Strategies...) return c }
[ "func", "(", "a", "*", "Auth", ")", "PrependAuthenticator", "(", "name", "string", ",", "authenticator", "Authenticator", ")", "*", "Auth", "{", "c", ":=", "a", ".", "copy", "(", ")", "\n", "strategy", ":=", "&", "Strategy", "{", "Name", ":", "name", ",", "Authenticator", ":", "authenticator", ",", "}", "\n", "c", ".", "Strategies", "=", "append", "(", "[", "]", "*", "Strategy", "{", "strategy", "}", ",", "c", ".", "Strategies", "...", ")", "\n", "return", "c", "\n", "}" ]
// AddAuthenticator returns a shallow copy of the Auth object with the given // authentication method added.
[ "AddAuthenticator", "returns", "a", "shallow", "copy", "of", "the", "Auth", "object", "with", "the", "given", "authentication", "method", "added", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L106-L114
train
remind101/empire
server/auth/auth.go
Authenticate
func (a *Auth) Authenticate(ctx context.Context, username, password, otp string, strategies ...string) (context.Context, error) { // Default to using all strategies to authenticate. authenticator := a.Strategies.AuthenticatorFor(strategies...) return a.authenticate(ctx, authenticator, username, password, otp) }
go
func (a *Auth) Authenticate(ctx context.Context, username, password, otp string, strategies ...string) (context.Context, error) { // Default to using all strategies to authenticate. authenticator := a.Strategies.AuthenticatorFor(strategies...) return a.authenticate(ctx, authenticator, username, password, otp) }
[ "func", "(", "a", "*", "Auth", ")", "Authenticate", "(", "ctx", "context", ".", "Context", ",", "username", ",", "password", ",", "otp", "string", ",", "strategies", "...", "string", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "// Default to using all strategies to authenticate.", "authenticator", ":=", "a", ".", "Strategies", ".", "AuthenticatorFor", "(", "strategies", "...", ")", "\n", "return", "a", ".", "authenticate", "(", "ctx", ",", "authenticator", ",", "username", ",", "password", ",", "otp", ")", "\n", "}" ]
// Authenticate authenticates the request using the named strategy, and returns // a new context.Context with the user embedded. The user can be retrieved with // UserFromContext.
[ "Authenticate", "authenticates", "the", "request", "using", "the", "named", "strategy", "and", "returns", "a", "new", "context", ".", "Context", "with", "the", "user", "embedded", ".", "The", "user", "can", "be", "retrieved", "with", "UserFromContext", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L119-L123
train
remind101/empire
server/auth/auth.go
Authenticate
func (fn AuthenticatorFunc) Authenticate(username, password, otp string) (*Session, error) { return fn(username, password, otp) }
go
func (fn AuthenticatorFunc) Authenticate(username, password, otp string) (*Session, error) { return fn(username, password, otp) }
[ "func", "(", "fn", "AuthenticatorFunc", ")", "Authenticate", "(", "username", ",", "password", ",", "otp", "string", ")", "(", "*", "Session", ",", "error", ")", "{", "return", "fn", "(", "username", ",", "password", ",", "otp", ")", "\n", "}" ]
// Authenticate calls the AuthenticatorFunc.
[ "Authenticate", "calls", "the", "AuthenticatorFunc", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L168-L170
train
remind101/empire
server/auth/auth.go
StaticAuthenticator
func StaticAuthenticator(username, password, otp string, user *empire.User) Authenticator { return AuthenticatorFunc(func(givenUsername, givenPassword, givenOtp string) (*Session, error) { if givenUsername != username { return nil, ErrForbidden } if givenPassword != password { return nil, ErrForbidden } if givenOtp != otp { return nil, ErrTwoFactor } return NewSession(user), nil }) }
go
func StaticAuthenticator(username, password, otp string, user *empire.User) Authenticator { return AuthenticatorFunc(func(givenUsername, givenPassword, givenOtp string) (*Session, error) { if givenUsername != username { return nil, ErrForbidden } if givenPassword != password { return nil, ErrForbidden } if givenOtp != otp { return nil, ErrTwoFactor } return NewSession(user), nil }) }
[ "func", "StaticAuthenticator", "(", "username", ",", "password", ",", "otp", "string", ",", "user", "*", "empire", ".", "User", ")", "Authenticator", "{", "return", "AuthenticatorFunc", "(", "func", "(", "givenUsername", ",", "givenPassword", ",", "givenOtp", "string", ")", "(", "*", "Session", ",", "error", ")", "{", "if", "givenUsername", "!=", "username", "{", "return", "nil", ",", "ErrForbidden", "\n", "}", "\n\n", "if", "givenPassword", "!=", "password", "{", "return", "nil", ",", "ErrForbidden", "\n", "}", "\n\n", "if", "givenOtp", "!=", "otp", "{", "return", "nil", ",", "ErrTwoFactor", "\n", "}", "\n\n", "return", "NewSession", "(", "user", ")", ",", "nil", "\n", "}", ")", "\n", "}" ]
// StaticAuthenticator returns an Authenticator that returns the provided user // when the given credentials are provided.
[ "StaticAuthenticator", "returns", "an", "Authenticator", "that", "returns", "the", "provided", "user", "when", "the", "given", "credentials", "are", "provided", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L187-L203
train
remind101/empire
server/auth/auth.go
Anyone
func Anyone(user *empire.User) Authenticator { return AuthenticatorFunc(func(username, password, otp string) (*Session, error) { return NewSession(user), nil }) }
go
func Anyone(user *empire.User) Authenticator { return AuthenticatorFunc(func(username, password, otp string) (*Session, error) { return NewSession(user), nil }) }
[ "func", "Anyone", "(", "user", "*", "empire", ".", "User", ")", "Authenticator", "{", "return", "AuthenticatorFunc", "(", "func", "(", "username", ",", "password", ",", "otp", "string", ")", "(", "*", "Session", ",", "error", ")", "{", "return", "NewSession", "(", "user", ")", ",", "nil", "\n", "}", ")", "\n", "}" ]
// Anyone returns an Authenticator that let's anyone in and sets them as the // given user.
[ "Anyone", "returns", "an", "Authenticator", "that", "let", "s", "anyone", "in", "and", "sets", "them", "as", "the", "given", "user", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L207-L211
train
remind101/empire
server/auth/auth.go
WithMaxSessionDuration
func WithMaxSessionDuration(auth Authenticator, exp func() time.Time) Authenticator { return AuthenticatorFunc(func(username, password, otp string) (*Session, error) { session, err := auth.Authenticate(username, password, otp) if err != nil { return session, err } t := exp() if exp := session.ExpiresAt; exp != nil { if exp.Before(t) { // Re-setting ExpiresAt to t would increase the // expiration of this session, instead we want // to keep it in tact. return session, err } } session.ExpiresAt = &t return session, err }) }
go
func WithMaxSessionDuration(auth Authenticator, exp func() time.Time) Authenticator { return AuthenticatorFunc(func(username, password, otp string) (*Session, error) { session, err := auth.Authenticate(username, password, otp) if err != nil { return session, err } t := exp() if exp := session.ExpiresAt; exp != nil { if exp.Before(t) { // Re-setting ExpiresAt to t would increase the // expiration of this session, instead we want // to keep it in tact. return session, err } } session.ExpiresAt = &t return session, err }) }
[ "func", "WithMaxSessionDuration", "(", "auth", "Authenticator", ",", "exp", "func", "(", ")", "time", ".", "Time", ")", "Authenticator", "{", "return", "AuthenticatorFunc", "(", "func", "(", "username", ",", "password", ",", "otp", "string", ")", "(", "*", "Session", ",", "error", ")", "{", "session", ",", "err", ":=", "auth", ".", "Authenticate", "(", "username", ",", "password", ",", "otp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "session", ",", "err", "\n", "}", "\n\n", "t", ":=", "exp", "(", ")", "\n", "if", "exp", ":=", "session", ".", "ExpiresAt", ";", "exp", "!=", "nil", "{", "if", "exp", ".", "Before", "(", "t", ")", "{", "// Re-setting ExpiresAt to t would increase the", "// expiration of this session, instead we want", "// to keep it in tact.", "return", "session", ",", "err", "\n", "}", "\n", "}", "\n", "session", ".", "ExpiresAt", "=", "&", "t", "\n", "return", "session", ",", "err", "\n", "}", ")", "\n", "}" ]
// WithMaxSessionDuration wraps an Authenticator to ensure that sessions always // have a maximum lifetime. If the Session already has an expiration that will // expire before d, the existing expiration is left in tact.
[ "WithMaxSessionDuration", "wraps", "an", "Authenticator", "to", "ensure", "that", "sessions", "always", "have", "a", "maximum", "lifetime", ".", "If", "the", "Session", "already", "has", "an", "expiration", "that", "will", "expire", "before", "d", "the", "existing", "expiration", "is", "left", "in", "tact", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L245-L264
train
remind101/empire
server/auth/auth.go
WithSession
func WithSession(ctx context.Context, session *Session) context.Context { return context.WithValue(ctx, sessionKey, session) }
go
func WithSession(ctx context.Context, session *Session) context.Context { return context.WithValue(ctx, sessionKey, session) }
[ "func", "WithSession", "(", "ctx", "context", ".", "Context", ",", "session", "*", "Session", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "sessionKey", ",", "session", ")", "\n", "}" ]
// WithSession embeds the authentication Session in the context.Context.
[ "WithSession", "embeds", "the", "authentication", "Session", "in", "the", "context", ".", "Context", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L274-L276
train
remind101/empire
server/auth/auth.go
UserFromContext
func UserFromContext(ctx context.Context) *empire.User { session := SessionFromContext(ctx) return session.User }
go
func UserFromContext(ctx context.Context) *empire.User { session := SessionFromContext(ctx) return session.User }
[ "func", "UserFromContext", "(", "ctx", "context", ".", "Context", ")", "*", "empire", ".", "User", "{", "session", ":=", "SessionFromContext", "(", "ctx", ")", "\n", "return", "session", ".", "User", "\n", "}" ]
// UserFromContext returns a user from a context.Context if one is present.
[ "UserFromContext", "returns", "a", "user", "from", "a", "context", ".", "Context", "if", "one", "is", "present", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L279-L282
train
remind101/empire
server/auth/auth.go
SessionFromContext
func SessionFromContext(ctx context.Context) *Session { session, ok := ctx.Value(sessionKey).(*Session) if !ok { panic("expected user to be authenticated") } return session }
go
func SessionFromContext(ctx context.Context) *Session { session, ok := ctx.Value(sessionKey).(*Session) if !ok { panic("expected user to be authenticated") } return session }
[ "func", "SessionFromContext", "(", "ctx", "context", ".", "Context", ")", "*", "Session", "{", "session", ",", "ok", ":=", "ctx", ".", "Value", "(", "sessionKey", ")", ".", "(", "*", "Session", ")", "\n", "if", "!", "ok", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "session", "\n", "}" ]
// SessionFromContext returns the embedded Session in the context.Context.
[ "SessionFromContext", "returns", "the", "embedded", "Session", "in", "the", "context", ".", "Context", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/auth.go#L285-L291
train
remind101/empire
server/github/builder.go
ImageFromTemplate
func ImageFromTemplate(t *template.Template) ImageBuilder { return ImageBuilderFunc(func(ctx context.Context, _ io.Writer, event events.Deployment) (image.Image, error) { buf := new(bytes.Buffer) if err := t.Execute(buf, event); err != nil { return image.Image{}, err } return image.Decode(buf.String()) }) }
go
func ImageFromTemplate(t *template.Template) ImageBuilder { return ImageBuilderFunc(func(ctx context.Context, _ io.Writer, event events.Deployment) (image.Image, error) { buf := new(bytes.Buffer) if err := t.Execute(buf, event); err != nil { return image.Image{}, err } return image.Decode(buf.String()) }) }
[ "func", "ImageFromTemplate", "(", "t", "*", "template", ".", "Template", ")", "ImageBuilder", "{", "return", "ImageBuilderFunc", "(", "func", "(", "ctx", "context", ".", "Context", ",", "_", "io", ".", "Writer", ",", "event", "events", ".", "Deployment", ")", "(", "image", ".", "Image", ",", "error", ")", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", ":=", "t", ".", "Execute", "(", "buf", ",", "event", ")", ";", "err", "!=", "nil", "{", "return", "image", ".", "Image", "{", "}", ",", "err", "\n", "}", "\n\n", "return", "image", ".", "Decode", "(", "buf", ".", "String", "(", ")", ")", "\n", "}", ")", "\n", "}" ]
// ImageFromTemplate returns an ImageBuilder that will execute a template to // determine what docker image should be deployed. Note that this doesn't not // actually perform any "build".
[ "ImageFromTemplate", "returns", "an", "ImageBuilder", "that", "will", "execute", "a", "template", "to", "determine", "what", "docker", "image", "should", "be", "deployed", ".", "Note", "that", "this", "doesn", "t", "not", "actually", "perform", "any", "build", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/github/builder.go#L31-L40
train
remind101/empire
internal/migrate/migrate.go
newPostgresLocker
func newPostgresLocker(db *sql.DB) sync.Locker { key := crc32.ChecksumIEEE([]byte("migrations")) return &postgresLocker{ key: key, db: db, } }
go
func newPostgresLocker(db *sql.DB) sync.Locker { key := crc32.ChecksumIEEE([]byte("migrations")) return &postgresLocker{ key: key, db: db, } }
[ "func", "newPostgresLocker", "(", "db", "*", "sql", ".", "DB", ")", "sync", ".", "Locker", "{", "key", ":=", "crc32", ".", "ChecksumIEEE", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "return", "&", "postgresLocker", "{", "key", ":", "key", ",", "db", ":", "db", ",", "}", "\n", "}" ]
// NewPostgresLocker returns a new sync.Locker that obtains locks with // pg_advisory_lock.
[ "NewPostgresLocker", "returns", "a", "new", "sync", ".", "Locker", "that", "obtains", "locks", "with", "pg_advisory_lock", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L95-L101
train
remind101/empire
internal/migrate/migrate.go
NewMigrator
func NewMigrator(db *sql.DB) *Migrator { return &Migrator{ db: db, Locker: new(sync.Mutex), } }
go
func NewMigrator(db *sql.DB) *Migrator { return &Migrator{ db: db, Locker: new(sync.Mutex), } }
[ "func", "NewMigrator", "(", "db", "*", "sql", ".", "DB", ")", "*", "Migrator", "{", "return", "&", "Migrator", "{", "db", ":", "db", ",", "Locker", ":", "new", "(", "sync", ".", "Mutex", ")", ",", "}", "\n", "}" ]
// NewMigrator returns a new Migrator instance that will use the sql.DB to // perform the migrations.
[ "NewMigrator", "returns", "a", "new", "Migrator", "instance", "that", "will", "use", "the", "sql", ".", "DB", "to", "perform", "the", "migrations", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L122-L127
train
remind101/empire
internal/migrate/migrate.go
NewPostgresMigrator
func NewPostgresMigrator(db *sql.DB) *Migrator { m := NewMigrator(db) m.Locker = newPostgresLocker(db) return m }
go
func NewPostgresMigrator(db *sql.DB) *Migrator { m := NewMigrator(db) m.Locker = newPostgresLocker(db) return m }
[ "func", "NewPostgresMigrator", "(", "db", "*", "sql", ".", "DB", ")", "*", "Migrator", "{", "m", ":=", "NewMigrator", "(", "db", ")", "\n", "m", ".", "Locker", "=", "newPostgresLocker", "(", "db", ")", "\n", "return", "m", "\n", "}" ]
// NewPostgresMigrator returns a new Migrator instance that uses the underlying // sql.DB connection to a postgres database to perform migrations. It will use // Postgres's advisory locks to ensure that only 1 migration is run at a time.
[ "NewPostgresMigrator", "returns", "a", "new", "Migrator", "instance", "that", "uses", "the", "underlying", "sql", ".", "DB", "connection", "to", "a", "postgres", "database", "to", "perform", "migrations", ".", "It", "will", "use", "Postgres", "s", "advisory", "locks", "to", "ensure", "that", "only", "1", "migration", "is", "run", "at", "a", "time", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L132-L136
train
remind101/empire
internal/migrate/migrate.go
Exec
func (m *Migrator) Exec(dir MigrationDirection, migrations ...Migration) error { m.Lock() defer m.Unlock() _, err := m.db.Exec(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (version integer primary key not null)", m.table())) if err != nil { return err } var tx *sql.Tx if m.TransactionMode == SingleTransaction { tx, err = m.db.Begin() if err != nil { return err } } for _, migration := range sortMigrations(dir, migrations) { if m.TransactionMode == IndividualTransactions { tx, err = m.db.Begin() if err != nil { return err } } if err := m.runMigration(tx, dir, migration); err != nil { tx.Rollback() return err } if m.TransactionMode == IndividualTransactions { if err := tx.Commit(); err != nil { return err } } } if m.TransactionMode == SingleTransaction { if err := tx.Commit(); err != nil { return err } } return nil }
go
func (m *Migrator) Exec(dir MigrationDirection, migrations ...Migration) error { m.Lock() defer m.Unlock() _, err := m.db.Exec(fmt.Sprintf("CREATE TABLE IF NOT EXISTS %s (version integer primary key not null)", m.table())) if err != nil { return err } var tx *sql.Tx if m.TransactionMode == SingleTransaction { tx, err = m.db.Begin() if err != nil { return err } } for _, migration := range sortMigrations(dir, migrations) { if m.TransactionMode == IndividualTransactions { tx, err = m.db.Begin() if err != nil { return err } } if err := m.runMigration(tx, dir, migration); err != nil { tx.Rollback() return err } if m.TransactionMode == IndividualTransactions { if err := tx.Commit(); err != nil { return err } } } if m.TransactionMode == SingleTransaction { if err := tx.Commit(); err != nil { return err } } return nil }
[ "func", "(", "m", "*", "Migrator", ")", "Exec", "(", "dir", "MigrationDirection", ",", "migrations", "...", "Migration", ")", "error", "{", "m", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "Unlock", "(", ")", "\n\n", "_", ",", "err", ":=", "m", ".", "db", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "table", "(", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "tx", "*", "sql", ".", "Tx", "\n", "if", "m", ".", "TransactionMode", "==", "SingleTransaction", "{", "tx", ",", "err", "=", "m", ".", "db", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "migration", ":=", "range", "sortMigrations", "(", "dir", ",", "migrations", ")", "{", "if", "m", ".", "TransactionMode", "==", "IndividualTransactions", "{", "tx", ",", "err", "=", "m", ".", "db", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "m", ".", "runMigration", "(", "tx", ",", "dir", ",", "migration", ")", ";", "err", "!=", "nil", "{", "tx", ".", "Rollback", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "m", ".", "TransactionMode", "==", "IndividualTransactions", "{", "if", "err", ":=", "tx", ".", "Commit", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "m", ".", "TransactionMode", "==", "SingleTransaction", "{", "if", "err", ":=", "tx", ".", "Commit", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Exec runs the migrations in the given direction.
[ "Exec", "runs", "the", "migrations", "in", "the", "given", "direction", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L139-L183
train
remind101/empire
internal/migrate/migrate.go
runMigration
func (m *Migrator) runMigration(tx *sql.Tx, dir MigrationDirection, migration Migration) error { shouldMigrate, err := m.shouldMigrate(tx, migration.ID, dir) if err != nil { return err } if !shouldMigrate { return nil } var migrate func(tx *sql.Tx) error switch dir { case Up: migrate = migration.Up default: migrate = migration.Down } if err := migrate(tx); err != nil { return &MigrationError{Migration: migration, Err: err} } var query string switch dir { case Up: // Yes. This is a sql injection vulnerability. This gets around // the different bindings for sqlite3/postgres. // // If you're running migrations from user input, you're doing // something wrong. query = fmt.Sprintf("INSERT INTO %s (version) VALUES (%d)", m.table(), migration.ID) default: query = fmt.Sprintf("DELETE FROM %s WHERE version = %d", m.table(), migration.ID) } _, err = tx.Exec(query) return err }
go
func (m *Migrator) runMigration(tx *sql.Tx, dir MigrationDirection, migration Migration) error { shouldMigrate, err := m.shouldMigrate(tx, migration.ID, dir) if err != nil { return err } if !shouldMigrate { return nil } var migrate func(tx *sql.Tx) error switch dir { case Up: migrate = migration.Up default: migrate = migration.Down } if err := migrate(tx); err != nil { return &MigrationError{Migration: migration, Err: err} } var query string switch dir { case Up: // Yes. This is a sql injection vulnerability. This gets around // the different bindings for sqlite3/postgres. // // If you're running migrations from user input, you're doing // something wrong. query = fmt.Sprintf("INSERT INTO %s (version) VALUES (%d)", m.table(), migration.ID) default: query = fmt.Sprintf("DELETE FROM %s WHERE version = %d", m.table(), migration.ID) } _, err = tx.Exec(query) return err }
[ "func", "(", "m", "*", "Migrator", ")", "runMigration", "(", "tx", "*", "sql", ".", "Tx", ",", "dir", "MigrationDirection", ",", "migration", "Migration", ")", "error", "{", "shouldMigrate", ",", "err", ":=", "m", ".", "shouldMigrate", "(", "tx", ",", "migration", ".", "ID", ",", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "!", "shouldMigrate", "{", "return", "nil", "\n", "}", "\n\n", "var", "migrate", "func", "(", "tx", "*", "sql", ".", "Tx", ")", "error", "\n", "switch", "dir", "{", "case", "Up", ":", "migrate", "=", "migration", ".", "Up", "\n", "default", ":", "migrate", "=", "migration", ".", "Down", "\n", "}", "\n\n", "if", "err", ":=", "migrate", "(", "tx", ")", ";", "err", "!=", "nil", "{", "return", "&", "MigrationError", "{", "Migration", ":", "migration", ",", "Err", ":", "err", "}", "\n", "}", "\n\n", "var", "query", "string", "\n", "switch", "dir", "{", "case", "Up", ":", "// Yes. This is a sql injection vulnerability. This gets around", "// the different bindings for sqlite3/postgres.", "//", "// If you're running migrations from user input, you're doing", "// something wrong.", "query", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "table", "(", ")", ",", "migration", ".", "ID", ")", "\n", "default", ":", "query", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "m", ".", "table", "(", ")", ",", "migration", ".", "ID", ")", "\n", "}", "\n\n", "_", ",", "err", "=", "tx", ".", "Exec", "(", "query", ")", "\n", "return", "err", "\n", "}" ]
// runMigration runs the given Migration in the given direction using the given // transaction. This function does not commit or rollback the transaction, // that's the responsibility of the consumer dependending on whether an error // gets returned.
[ "runMigration", "runs", "the", "given", "Migration", "in", "the", "given", "direction", "using", "the", "given", "transaction", ".", "This", "function", "does", "not", "commit", "or", "rollback", "the", "transaction", "that", "s", "the", "responsibility", "of", "the", "consumer", "dependending", "on", "whether", "an", "error", "gets", "returned", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L189-L226
train
remind101/empire
internal/migrate/migrate.go
Exec
func Exec(db *sql.DB, dir MigrationDirection, migrations ...Migration) error { return NewMigrator(db).Exec(dir, migrations...) }
go
func Exec(db *sql.DB, dir MigrationDirection, migrations ...Migration) error { return NewMigrator(db).Exec(dir, migrations...) }
[ "func", "Exec", "(", "db", "*", "sql", ".", "DB", ",", "dir", "MigrationDirection", ",", "migrations", "...", "Migration", ")", "error", "{", "return", "NewMigrator", "(", "db", ")", ".", "Exec", "(", "dir", ",", "migrations", "...", ")", "\n", "}" ]
// Exec is a convenience method that runs the migrations against the default // table.
[ "Exec", "is", "a", "convenience", "method", "that", "runs", "the", "migrations", "against", "the", "default", "table", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L257-L259
train
remind101/empire
internal/migrate/migrate.go
sortMigrations
func sortMigrations(dir MigrationDirection, migrations []Migration) []Migration { var m ByID for _, migration := range migrations { m = append(m, migration) } switch dir { case Up: sort.Sort(ByID(m)) default: sort.Sort(sort.Reverse(ByID(m))) } return m }
go
func sortMigrations(dir MigrationDirection, migrations []Migration) []Migration { var m ByID for _, migration := range migrations { m = append(m, migration) } switch dir { case Up: sort.Sort(ByID(m)) default: sort.Sort(sort.Reverse(ByID(m))) } return m }
[ "func", "sortMigrations", "(", "dir", "MigrationDirection", ",", "migrations", "[", "]", "Migration", ")", "[", "]", "Migration", "{", "var", "m", "ByID", "\n", "for", "_", ",", "migration", ":=", "range", "migrations", "{", "m", "=", "append", "(", "m", ",", "migration", ")", "\n", "}", "\n\n", "switch", "dir", "{", "case", "Up", ":", "sort", ".", "Sort", "(", "ByID", "(", "m", ")", ")", "\n", "default", ":", "sort", ".", "Sort", "(", "sort", ".", "Reverse", "(", "ByID", "(", "m", ")", ")", ")", "\n", "}", "\n\n", "return", "m", "\n", "}" ]
// sortMigrations sorts the migrations by id. // // When the direction is "Up", the migrations will be sorted by ID ascending. // When the direction is "Down", the migrations will be sorted by ID descending.
[ "sortMigrations", "sorts", "the", "migrations", "by", "id", ".", "When", "the", "direction", "is", "Up", "the", "migrations", "will", "be", "sorted", "by", "ID", "ascending", ".", "When", "the", "direction", "is", "Down", "the", "migrations", "will", "be", "sorted", "by", "ID", "descending", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/migrate/migrate.go#L279-L293
train
remind101/empire
server/cloudformation/cloudformation.go
NewCustomResourceProvisioner
func NewCustomResourceProvisioner(empire *empire.Empire, config client.ConfigProvider) *CustomResourceProvisioner { db := empire.DB.DB.DB() p := &CustomResourceProvisioner{ SQSDispatcher: newSQSDispatcher(config), Provisioners: make(map[string]customresources.Provisioner), sendResponse: customresources.SendResponse, } p.add("Custom::InstancePort", newInstancePortsProvisioner(&InstancePortsResource{ ports: newDBPortAllocator(db), })) ecs := newECSClient(config) p.add("Custom::ECSService", newECSServiceProvisioner(&ECSServiceResource{ ecs: ecs, })) store := &dbEnvironmentStore{db} p.add("Custom::ECSEnvironment", newECSEnvironmentProvisioner(&ECSEnvironmentResource{ environmentStore: store, })) p.add("Custom::ECSTaskDefinition", newECSTaskDefinitionProvisioner(&ECSTaskDefinitionResource{ ecs: ecs, environmentStore: store, })) p.add("Custom::EmpireApp", &EmpireAppResource{ empire: empire, }) p.add("Custom::EmpireAppEnvironment", &EmpireAppEnvironmentResource{ empire: empire, }) return p }
go
func NewCustomResourceProvisioner(empire *empire.Empire, config client.ConfigProvider) *CustomResourceProvisioner { db := empire.DB.DB.DB() p := &CustomResourceProvisioner{ SQSDispatcher: newSQSDispatcher(config), Provisioners: make(map[string]customresources.Provisioner), sendResponse: customresources.SendResponse, } p.add("Custom::InstancePort", newInstancePortsProvisioner(&InstancePortsResource{ ports: newDBPortAllocator(db), })) ecs := newECSClient(config) p.add("Custom::ECSService", newECSServiceProvisioner(&ECSServiceResource{ ecs: ecs, })) store := &dbEnvironmentStore{db} p.add("Custom::ECSEnvironment", newECSEnvironmentProvisioner(&ECSEnvironmentResource{ environmentStore: store, })) p.add("Custom::ECSTaskDefinition", newECSTaskDefinitionProvisioner(&ECSTaskDefinitionResource{ ecs: ecs, environmentStore: store, })) p.add("Custom::EmpireApp", &EmpireAppResource{ empire: empire, }) p.add("Custom::EmpireAppEnvironment", &EmpireAppEnvironmentResource{ empire: empire, }) return p }
[ "func", "NewCustomResourceProvisioner", "(", "empire", "*", "empire", ".", "Empire", ",", "config", "client", ".", "ConfigProvider", ")", "*", "CustomResourceProvisioner", "{", "db", ":=", "empire", ".", "DB", ".", "DB", ".", "DB", "(", ")", "\n", "p", ":=", "&", "CustomResourceProvisioner", "{", "SQSDispatcher", ":", "newSQSDispatcher", "(", "config", ")", ",", "Provisioners", ":", "make", "(", "map", "[", "string", "]", "customresources", ".", "Provisioner", ")", ",", "sendResponse", ":", "customresources", ".", "SendResponse", ",", "}", "\n\n", "p", ".", "add", "(", "\"", "\"", ",", "newInstancePortsProvisioner", "(", "&", "InstancePortsResource", "{", "ports", ":", "newDBPortAllocator", "(", "db", ")", ",", "}", ")", ")", "\n\n", "ecs", ":=", "newECSClient", "(", "config", ")", "\n", "p", ".", "add", "(", "\"", "\"", ",", "newECSServiceProvisioner", "(", "&", "ECSServiceResource", "{", "ecs", ":", "ecs", ",", "}", ")", ")", "\n\n", "store", ":=", "&", "dbEnvironmentStore", "{", "db", "}", "\n", "p", ".", "add", "(", "\"", "\"", ",", "newECSEnvironmentProvisioner", "(", "&", "ECSEnvironmentResource", "{", "environmentStore", ":", "store", ",", "}", ")", ")", "\n", "p", ".", "add", "(", "\"", "\"", ",", "newECSTaskDefinitionProvisioner", "(", "&", "ECSTaskDefinitionResource", "{", "ecs", ":", "ecs", ",", "environmentStore", ":", "store", ",", "}", ")", ")", "\n\n", "p", ".", "add", "(", "\"", "\"", ",", "&", "EmpireAppResource", "{", "empire", ":", "empire", ",", "}", ")", "\n", "p", ".", "add", "(", "\"", "\"", ",", "&", "EmpireAppEnvironmentResource", "{", "empire", ":", "empire", ",", "}", ")", "\n\n", "return", "p", "\n", "}" ]
// NewCustomResourceProvisioner returns a new CustomResourceProvisioner with an // sqs client configured from config.
[ "NewCustomResourceProvisioner", "returns", "a", "new", "CustomResourceProvisioner", "with", "an", "sqs", "client", "configured", "from", "config", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/cloudformation.go#L50-L84
train
remind101/empire
server/cloudformation/cloudformation.go
add
func (c *CustomResourceProvisioner) add(resourceName string, p customresources.Provisioner) { // Wrap the provisioner with timeouts. p = customresources.WithTimeout(p, ProvisioningTimeout, ProvisioningGraceTimeout) c.Provisioners[resourceName] = withMetrics(p) }
go
func (c *CustomResourceProvisioner) add(resourceName string, p customresources.Provisioner) { // Wrap the provisioner with timeouts. p = customresources.WithTimeout(p, ProvisioningTimeout, ProvisioningGraceTimeout) c.Provisioners[resourceName] = withMetrics(p) }
[ "func", "(", "c", "*", "CustomResourceProvisioner", ")", "add", "(", "resourceName", "string", ",", "p", "customresources", ".", "Provisioner", ")", "{", "// Wrap the provisioner with timeouts.", "p", "=", "customresources", ".", "WithTimeout", "(", "p", ",", "ProvisioningTimeout", ",", "ProvisioningGraceTimeout", ")", "\n", "c", ".", "Provisioners", "[", "resourceName", "]", "=", "withMetrics", "(", "p", ")", "\n", "}" ]
// add adds a custom resource provisioner.
[ "add", "adds", "a", "custom", "resource", "provisioner", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/cloudformation.go#L87-L91
train
remind101/empire
server/cloudformation/cloudformation.go
Handle
func (c *CustomResourceProvisioner) Handle(ctx context.Context, message *sqs.Message) error { var m Message err := json.Unmarshal([]byte(*message.Body), &m) if err != nil { return fmt.Errorf("error unmarshalling sqs message body: %v", err) } var req customresources.Request err = json.Unmarshal([]byte(m.Message), &req) if err != nil { return fmt.Errorf("error unmarshalling to cloudformation request: %v", err) } logger.Info(ctx, "cloudformation.provision.request", "request_id", req.RequestId, "stack_id", req.StackId, "request_type", req.RequestType, "resource_type", req.ResourceType, "logical_resource_id", req.LogicalResourceId, "physical_resource_id", req.PhysicalResourceId, ) resp := customresources.NewResponseFromRequest(req) // CloudFormation is weird. PhysicalResourceId is required when creating // a resource, but if the creation fails, how would we have a physical // resource id? In cases where a Create request fails, we set the // physical resource id to `failed/Create`. When a delete request comes // in to delete that resource, we just send back a SUCCESS response so // CloudFormation is happy. if req.RequestType == customresources.Delete && req.PhysicalResourceId == fmt.Sprintf("failed/%s", customresources.Create) { resp.PhysicalResourceId = req.PhysicalResourceId } else { resp.PhysicalResourceId, resp.Data, err = c.provision(ctx, m, req) } // Allow provisioners to just return "" to indicate that the physical // resource id did not change. if resp.PhysicalResourceId == "" && req.PhysicalResourceId != "" { resp.PhysicalResourceId = req.PhysicalResourceId } switch err { case nil: resp.Status = customresources.StatusSuccess logger.Info(ctx, "cloudformation.provision.success", "request_id", req.RequestId, "stack_id", req.StackId, "physical_resource_id", resp.PhysicalResourceId, ) default: // A physical resource id is required, so if a Create request // fails, and there's no physical resource id, CloudFormation // will only say `Invalid PhysicalResourceId` in the status // Reason instead of the actual error that caused the Create to // fail. if req.RequestType == customresources.Create && resp.PhysicalResourceId == "" { resp.PhysicalResourceId = fmt.Sprintf("failed/%s", req.RequestType) } resp.Status = customresources.StatusFailed resp.Reason = err.Error() logger.Error(ctx, "cloudformation.provision.error", "request_id", req.RequestId, "stack_id", req.StackId, "err", err.Error(), ) } return c.sendResponse(req, resp) }
go
func (c *CustomResourceProvisioner) Handle(ctx context.Context, message *sqs.Message) error { var m Message err := json.Unmarshal([]byte(*message.Body), &m) if err != nil { return fmt.Errorf("error unmarshalling sqs message body: %v", err) } var req customresources.Request err = json.Unmarshal([]byte(m.Message), &req) if err != nil { return fmt.Errorf("error unmarshalling to cloudformation request: %v", err) } logger.Info(ctx, "cloudformation.provision.request", "request_id", req.RequestId, "stack_id", req.StackId, "request_type", req.RequestType, "resource_type", req.ResourceType, "logical_resource_id", req.LogicalResourceId, "physical_resource_id", req.PhysicalResourceId, ) resp := customresources.NewResponseFromRequest(req) // CloudFormation is weird. PhysicalResourceId is required when creating // a resource, but if the creation fails, how would we have a physical // resource id? In cases where a Create request fails, we set the // physical resource id to `failed/Create`. When a delete request comes // in to delete that resource, we just send back a SUCCESS response so // CloudFormation is happy. if req.RequestType == customresources.Delete && req.PhysicalResourceId == fmt.Sprintf("failed/%s", customresources.Create) { resp.PhysicalResourceId = req.PhysicalResourceId } else { resp.PhysicalResourceId, resp.Data, err = c.provision(ctx, m, req) } // Allow provisioners to just return "" to indicate that the physical // resource id did not change. if resp.PhysicalResourceId == "" && req.PhysicalResourceId != "" { resp.PhysicalResourceId = req.PhysicalResourceId } switch err { case nil: resp.Status = customresources.StatusSuccess logger.Info(ctx, "cloudformation.provision.success", "request_id", req.RequestId, "stack_id", req.StackId, "physical_resource_id", resp.PhysicalResourceId, ) default: // A physical resource id is required, so if a Create request // fails, and there's no physical resource id, CloudFormation // will only say `Invalid PhysicalResourceId` in the status // Reason instead of the actual error that caused the Create to // fail. if req.RequestType == customresources.Create && resp.PhysicalResourceId == "" { resp.PhysicalResourceId = fmt.Sprintf("failed/%s", req.RequestType) } resp.Status = customresources.StatusFailed resp.Reason = err.Error() logger.Error(ctx, "cloudformation.provision.error", "request_id", req.RequestId, "stack_id", req.StackId, "err", err.Error(), ) } return c.sendResponse(req, resp) }
[ "func", "(", "c", "*", "CustomResourceProvisioner", ")", "Handle", "(", "ctx", "context", ".", "Context", ",", "message", "*", "sqs", ".", "Message", ")", "error", "{", "var", "m", "Message", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "*", "message", ".", "Body", ")", ",", "&", "m", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "var", "req", "customresources", ".", "Request", "\n", "err", "=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "m", ".", "Message", ")", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "logger", ".", "Info", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "req", ".", "RequestId", ",", "\"", "\"", ",", "req", ".", "StackId", ",", "\"", "\"", ",", "req", ".", "RequestType", ",", "\"", "\"", ",", "req", ".", "ResourceType", ",", "\"", "\"", ",", "req", ".", "LogicalResourceId", ",", "\"", "\"", ",", "req", ".", "PhysicalResourceId", ",", ")", "\n\n", "resp", ":=", "customresources", ".", "NewResponseFromRequest", "(", "req", ")", "\n\n", "// CloudFormation is weird. PhysicalResourceId is required when creating", "// a resource, but if the creation fails, how would we have a physical", "// resource id? In cases where a Create request fails, we set the", "// physical resource id to `failed/Create`. When a delete request comes", "// in to delete that resource, we just send back a SUCCESS response so", "// CloudFormation is happy.", "if", "req", ".", "RequestType", "==", "customresources", ".", "Delete", "&&", "req", ".", "PhysicalResourceId", "==", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "customresources", ".", "Create", ")", "{", "resp", ".", "PhysicalResourceId", "=", "req", ".", "PhysicalResourceId", "\n", "}", "else", "{", "resp", ".", "PhysicalResourceId", ",", "resp", ".", "Data", ",", "err", "=", "c", ".", "provision", "(", "ctx", ",", "m", ",", "req", ")", "\n", "}", "\n\n", "// Allow provisioners to just return \"\" to indicate that the physical", "// resource id did not change.", "if", "resp", ".", "PhysicalResourceId", "==", "\"", "\"", "&&", "req", ".", "PhysicalResourceId", "!=", "\"", "\"", "{", "resp", ".", "PhysicalResourceId", "=", "req", ".", "PhysicalResourceId", "\n", "}", "\n\n", "switch", "err", "{", "case", "nil", ":", "resp", ".", "Status", "=", "customresources", ".", "StatusSuccess", "\n", "logger", ".", "Info", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "req", ".", "RequestId", ",", "\"", "\"", ",", "req", ".", "StackId", ",", "\"", "\"", ",", "resp", ".", "PhysicalResourceId", ",", ")", "\n", "default", ":", "// A physical resource id is required, so if a Create request", "// fails, and there's no physical resource id, CloudFormation", "// will only say `Invalid PhysicalResourceId` in the status", "// Reason instead of the actual error that caused the Create to", "// fail.", "if", "req", ".", "RequestType", "==", "customresources", ".", "Create", "&&", "resp", ".", "PhysicalResourceId", "==", "\"", "\"", "{", "resp", ".", "PhysicalResourceId", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "req", ".", "RequestType", ")", "\n", "}", "\n\n", "resp", ".", "Status", "=", "customresources", ".", "StatusFailed", "\n", "resp", ".", "Reason", "=", "err", ".", "Error", "(", ")", "\n", "logger", ".", "Error", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "req", ".", "RequestId", ",", "\"", "\"", ",", "req", ".", "StackId", ",", "\"", "\"", ",", "err", ".", "Error", "(", ")", ",", ")", "\n", "}", "\n\n", "return", "c", ".", "sendResponse", "(", "req", ",", "resp", ")", "\n", "}" ]
// Handle handles a single sqs.Message to perform the provisioning.
[ "Handle", "handles", "a", "single", "sqs", ".", "Message", "to", "perform", "the", "provisioning", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/cloudformation.go#L98-L168
train
remind101/empire
server/cloudformation/cloudformation.go
requiresReplacement
func requiresReplacement(n, o properties) (bool, error) { a, err := n.ReplacementHash() if err != nil { return false, err } b, err := o.ReplacementHash() if err != nil { return false, err } return a != b, nil }
go
func requiresReplacement(n, o properties) (bool, error) { a, err := n.ReplacementHash() if err != nil { return false, err } b, err := o.ReplacementHash() if err != nil { return false, err } return a != b, nil }
[ "func", "requiresReplacement", "(", "n", ",", "o", "properties", ")", "(", "bool", ",", "error", ")", "{", "a", ",", "err", ":=", "n", ".", "ReplacementHash", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "b", ",", "err", ":=", "o", ".", "ReplacementHash", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "a", "!=", "b", ",", "nil", "\n", "}" ]
// requiresReplacement returns true if the new properties require a replacement // of the old properties.
[ "requiresReplacement", "returns", "true", "if", "the", "new", "properties", "require", "a", "replacement", "of", "the", "old", "properties", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/cloudformation.go#L244-L256
train
remind101/empire
tasks.go
taskFromInstance
func taskFromInstance(i *twelvefactor.Task) *Task { version := i.Process.Env["EMPIRE_RELEASE"] if version == "" { version = "v0" } return &Task{ Name: fmt.Sprintf("%s.%s.%s", version, i.Process.Type, i.ID), Type: string(i.Process.Type), Host: Host{ID: i.Host.ID}, Command: Command(i.Process.Command), Constraints: Constraints{ CPUShare: constraints.CPUShare(i.Process.CPUShares), Memory: constraints.Memory(i.Process.Memory), Nproc: constraints.Nproc(i.Process.Nproc), }, State: i.State, UpdatedAt: i.UpdatedAt, } }
go
func taskFromInstance(i *twelvefactor.Task) *Task { version := i.Process.Env["EMPIRE_RELEASE"] if version == "" { version = "v0" } return &Task{ Name: fmt.Sprintf("%s.%s.%s", version, i.Process.Type, i.ID), Type: string(i.Process.Type), Host: Host{ID: i.Host.ID}, Command: Command(i.Process.Command), Constraints: Constraints{ CPUShare: constraints.CPUShare(i.Process.CPUShares), Memory: constraints.Memory(i.Process.Memory), Nproc: constraints.Nproc(i.Process.Nproc), }, State: i.State, UpdatedAt: i.UpdatedAt, } }
[ "func", "taskFromInstance", "(", "i", "*", "twelvefactor", ".", "Task", ")", "*", "Task", "{", "version", ":=", "i", ".", "Process", ".", "Env", "[", "\"", "\"", "]", "\n", "if", "version", "==", "\"", "\"", "{", "version", "=", "\"", "\"", "\n", "}", "\n\n", "return", "&", "Task", "{", "Name", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "version", ",", "i", ".", "Process", ".", "Type", ",", "i", ".", "ID", ")", ",", "Type", ":", "string", "(", "i", ".", "Process", ".", "Type", ")", ",", "Host", ":", "Host", "{", "ID", ":", "i", ".", "Host", ".", "ID", "}", ",", "Command", ":", "Command", "(", "i", ".", "Process", ".", "Command", ")", ",", "Constraints", ":", "Constraints", "{", "CPUShare", ":", "constraints", ".", "CPUShare", "(", "i", ".", "Process", ".", "CPUShares", ")", ",", "Memory", ":", "constraints", ".", "Memory", "(", "i", ".", "Process", ".", "Memory", ")", ",", "Nproc", ":", "constraints", ".", "Nproc", "(", "i", ".", "Process", ".", "Nproc", ")", ",", "}", ",", "State", ":", "i", ".", "State", ",", "UpdatedAt", ":", "i", ".", "UpdatedAt", ",", "}", "\n", "}" ]
// taskFromInstance converts a scheduler.Instance into a Task. // It pulls some of its data from empire specific environment variables if they have been set. // Once ECS supports this data natively, we can stop doing this.
[ "taskFromInstance", "converts", "a", "scheduler", ".", "Instance", "into", "a", "Task", ".", "It", "pulls", "some", "of", "its", "data", "from", "empire", "specific", "environment", "variables", "if", "they", "have", "been", "set", ".", "Once", "ECS", "supports", "this", "data", "natively", "we", "can", "stop", "doing", "this", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/tasks.go#L67-L86
train
remind101/empire
logs/logs.go
RecordToCloudWatch
func RecordToCloudWatch(group string, config client.ConfigProvider) empire.RunRecorder { c := cloudwatchlogs.New(config) g := cloudwatch.NewGroup(group, c) return func() (io.Writer, error) { stream := uuid.New() w, err := g.Create(stream) if err != nil { return nil, err } url := fmt.Sprintf("https://console.aws.amazon.com/cloudwatch/home?region=%s#logEvent:group=%s;stream=%s", *c.Config.Region, group, stream) return &writerWithURL{w, url}, nil } }
go
func RecordToCloudWatch(group string, config client.ConfigProvider) empire.RunRecorder { c := cloudwatchlogs.New(config) g := cloudwatch.NewGroup(group, c) return func() (io.Writer, error) { stream := uuid.New() w, err := g.Create(stream) if err != nil { return nil, err } url := fmt.Sprintf("https://console.aws.amazon.com/cloudwatch/home?region=%s#logEvent:group=%s;stream=%s", *c.Config.Region, group, stream) return &writerWithURL{w, url}, nil } }
[ "func", "RecordToCloudWatch", "(", "group", "string", ",", "config", "client", ".", "ConfigProvider", ")", "empire", ".", "RunRecorder", "{", "c", ":=", "cloudwatchlogs", ".", "New", "(", "config", ")", "\n", "g", ":=", "cloudwatch", ".", "NewGroup", "(", "group", ",", "c", ")", "\n", "return", "func", "(", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "stream", ":=", "uuid", ".", "New", "(", ")", "\n", "w", ",", "err", ":=", "g", ".", "Create", "(", "stream", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "*", "c", ".", "Config", ".", "Region", ",", "group", ",", "stream", ")", "\n", "return", "&", "writerWithURL", "{", "w", ",", "url", "}", ",", "nil", "\n", "}", "\n", "}" ]
// RecordToCloudWatch returns a RunRecorder that writes the log record to // CloudWatch Logs.
[ "RecordToCloudWatch", "returns", "a", "RunRecorder", "that", "writes", "the", "log", "record", "to", "CloudWatch", "Logs", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/logs/logs.go#L45-L58
train
remind101/empire
logs/logs.go
RecordTo
func RecordTo(w io.Writer) empire.RunRecorder { return func() (io.Writer, error) { return w, nil } }
go
func RecordTo(w io.Writer) empire.RunRecorder { return func() (io.Writer, error) { return w, nil } }
[ "func", "RecordTo", "(", "w", "io", ".", "Writer", ")", "empire", ".", "RunRecorder", "{", "return", "func", "(", ")", "(", "io", ".", "Writer", ",", "error", ")", "{", "return", "w", ",", "nil", "\n", "}", "\n", "}" ]
// RecordTo returns a RunRecorder that writes the log record to the io.Writer
[ "RecordTo", "returns", "a", "RunRecorder", "that", "writes", "the", "log", "record", "to", "the", "io", ".", "Writer" ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/logs/logs.go#L72-L76
train
remind101/empire
pkg/pg/lock/lock.go
NewAdvisoryLock
func NewAdvisoryLock(db *sql.DB, key uint32) (*AdvisoryLock, error) { tx, err := db.Begin() if err != nil { return nil, err } return &AdvisoryLock{ tx: tx, key: key, }, nil }
go
func NewAdvisoryLock(db *sql.DB, key uint32) (*AdvisoryLock, error) { tx, err := db.Begin() if err != nil { return nil, err } return &AdvisoryLock{ tx: tx, key: key, }, nil }
[ "func", "NewAdvisoryLock", "(", "db", "*", "sql", ".", "DB", ",", "key", "uint32", ")", "(", "*", "AdvisoryLock", ",", "error", ")", "{", "tx", ",", "err", ":=", "db", ".", "Begin", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "AdvisoryLock", "{", "tx", ":", "tx", ",", "key", ":", "key", ",", "}", ",", "nil", "\n", "}" ]
// NewAdvisoryLock opens a new transaction and returns the AdvisoryLock.
[ "NewAdvisoryLock", "opens", "a", "new", "transaction", "and", "returns", "the", "AdvisoryLock", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/pg/lock/lock.go#L43-L53
train
remind101/empire
pkg/pg/lock/lock.go
Lock
func (l *AdvisoryLock) Lock() error { l.mu.Lock() defer l.mu.Unlock() if l.commited { panic("lock called on commited lock") } if l.LockTimeout != 0 { _, err := l.tx.Exec(fmt.Sprintf("SET LOCAL lock_timeout = %d", int(l.LockTimeout.Seconds()*1000))) if err != nil { return fmt.Errorf("error setting lock timeout: %v", err) } } _, err := l.tx.Exec(fmt.Sprintf("SELECT pg_advisory_lock($1) /* %s */", l.Context), l.key) if err != nil { // If there's an error trying to obtain the lock, probably the // safest thing to do is commit the transaction and make this // lock invalid. l.commit() if err, ok := err.(*pq.Error); ok { switch err.Code.Name() { case "query_canceled": return Canceled case "lock_not_available": return ErrLockTimeout } } return fmt.Errorf("error obtaining lock: %v", err) } l.c += 1 return nil }
go
func (l *AdvisoryLock) Lock() error { l.mu.Lock() defer l.mu.Unlock() if l.commited { panic("lock called on commited lock") } if l.LockTimeout != 0 { _, err := l.tx.Exec(fmt.Sprintf("SET LOCAL lock_timeout = %d", int(l.LockTimeout.Seconds()*1000))) if err != nil { return fmt.Errorf("error setting lock timeout: %v", err) } } _, err := l.tx.Exec(fmt.Sprintf("SELECT pg_advisory_lock($1) /* %s */", l.Context), l.key) if err != nil { // If there's an error trying to obtain the lock, probably the // safest thing to do is commit the transaction and make this // lock invalid. l.commit() if err, ok := err.(*pq.Error); ok { switch err.Code.Name() { case "query_canceled": return Canceled case "lock_not_available": return ErrLockTimeout } } return fmt.Errorf("error obtaining lock: %v", err) } l.c += 1 return nil }
[ "func", "(", "l", "*", "AdvisoryLock", ")", "Lock", "(", ")", "error", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "l", ".", "commited", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "l", ".", "LockTimeout", "!=", "0", "{", "_", ",", "err", ":=", "l", ".", "tx", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "int", "(", "l", ".", "LockTimeout", ".", "Seconds", "(", ")", "*", "1000", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "_", ",", "err", ":=", "l", ".", "tx", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "Context", ")", ",", "l", ".", "key", ")", "\n", "if", "err", "!=", "nil", "{", "// If there's an error trying to obtain the lock, probably the", "// safest thing to do is commit the transaction and make this", "// lock invalid.", "l", ".", "commit", "(", ")", "\n\n", "if", "err", ",", "ok", ":=", "err", ".", "(", "*", "pq", ".", "Error", ")", ";", "ok", "{", "switch", "err", ".", "Code", ".", "Name", "(", ")", "{", "case", "\"", "\"", ":", "return", "Canceled", "\n", "case", "\"", "\"", ":", "return", "ErrLockTimeout", "\n", "}", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "l", ".", "c", "+=", "1", "\n\n", "return", "nil", "\n", "}" ]
// Lock obtains the advisory lock.
[ "Lock", "obtains", "the", "advisory", "lock", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/pg/lock/lock.go#L74-L111
train
remind101/empire
pkg/pg/lock/lock.go
Unlock
func (l *AdvisoryLock) Unlock() error { l.mu.Lock() defer l.mu.Unlock() if l.commited { panic("unlock called on commited lock") } if l.c == 0 { panic("unlock of unlocked advisory lock") } _, err := l.tx.Exec(fmt.Sprintf("SELECT pg_advisory_unlock($1) /* %s */", l.Context), l.key) if err != nil { return err } l.c -= 1 if l.c == 0 { if err := l.commit(); err != nil { return err } } return err }
go
func (l *AdvisoryLock) Unlock() error { l.mu.Lock() defer l.mu.Unlock() if l.commited { panic("unlock called on commited lock") } if l.c == 0 { panic("unlock of unlocked advisory lock") } _, err := l.tx.Exec(fmt.Sprintf("SELECT pg_advisory_unlock($1) /* %s */", l.Context), l.key) if err != nil { return err } l.c -= 1 if l.c == 0 { if err := l.commit(); err != nil { return err } } return err }
[ "func", "(", "l", "*", "AdvisoryLock", ")", "Unlock", "(", ")", "error", "{", "l", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "l", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "l", ".", "commited", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "l", ".", "c", "==", "0", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "_", ",", "err", ":=", "l", ".", "tx", ".", "Exec", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "l", ".", "Context", ")", ",", "l", ".", "key", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "l", ".", "c", "-=", "1", "\n\n", "if", "l", ".", "c", "==", "0", "{", "if", "err", ":=", "l", ".", "commit", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Unlock releases the advisory lock.
[ "Unlock", "releases", "the", "advisory", "lock", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/pg/lock/lock.go#L114-L140
train
remind101/empire
cmd/emp/suggest.go
suggest
func suggest(s string) (a []string) { var g Suggestions for _, c := range commands { if d := editDistance(s, c.Name()); d < 4 { if c.Runnable() { g = append(g, Suggestion{c.Name(), d}) } else { g = append(g, Suggestion{strconv.Quote("help " + c.Name()), d}) } } } sort.Sort(g) for i, s := range g { a = append(a, s.s) if i >= 4 { break } } return a }
go
func suggest(s string) (a []string) { var g Suggestions for _, c := range commands { if d := editDistance(s, c.Name()); d < 4 { if c.Runnable() { g = append(g, Suggestion{c.Name(), d}) } else { g = append(g, Suggestion{strconv.Quote("help " + c.Name()), d}) } } } sort.Sort(g) for i, s := range g { a = append(a, s.s) if i >= 4 { break } } return a }
[ "func", "suggest", "(", "s", "string", ")", "(", "a", "[", "]", "string", ")", "{", "var", "g", "Suggestions", "\n", "for", "_", ",", "c", ":=", "range", "commands", "{", "if", "d", ":=", "editDistance", "(", "s", ",", "c", ".", "Name", "(", ")", ")", ";", "d", "<", "4", "{", "if", "c", ".", "Runnable", "(", ")", "{", "g", "=", "append", "(", "g", ",", "Suggestion", "{", "c", ".", "Name", "(", ")", ",", "d", "}", ")", "\n", "}", "else", "{", "g", "=", "append", "(", "g", ",", "Suggestion", "{", "strconv", ".", "Quote", "(", "\"", "\"", "+", "c", ".", "Name", "(", ")", ")", ",", "d", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "sort", ".", "Sort", "(", "g", ")", "\n", "for", "i", ",", "s", ":=", "range", "g", "{", "a", "=", "append", "(", "a", ",", "s", ".", "s", ")", "\n", "if", "i", ">=", "4", "{", "break", "\n", "}", "\n", "}", "\n", "return", "a", "\n", "}" ]
// suggest returns command names that are similar to s.
[ "suggest", "returns", "command", "names", "that", "are", "similar", "to", "s", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/cmd/emp/suggest.go#L20-L39
train
remind101/empire
server/auth/saml/saml.go
SessionFromAssertion
func SessionFromAssertion(assertion *saml.Assertion) *auth.Session { login := assertion.Subject.NameID.Value user := &empire.User{ Name: login, } session := auth.NewSession(user) session.ExpiresAt = &assertion.AuthnStatement.SessionNotOnOrAfter return session }
go
func SessionFromAssertion(assertion *saml.Assertion) *auth.Session { login := assertion.Subject.NameID.Value user := &empire.User{ Name: login, } session := auth.NewSession(user) session.ExpiresAt = &assertion.AuthnStatement.SessionNotOnOrAfter return session }
[ "func", "SessionFromAssertion", "(", "assertion", "*", "saml", ".", "Assertion", ")", "*", "auth", ".", "Session", "{", "login", ":=", "assertion", ".", "Subject", ".", "NameID", ".", "Value", "\n", "user", ":=", "&", "empire", ".", "User", "{", "Name", ":", "login", ",", "}", "\n\n", "session", ":=", "auth", ".", "NewSession", "(", "user", ")", "\n", "session", ".", "ExpiresAt", "=", "&", "assertion", ".", "AuthnStatement", ".", "SessionNotOnOrAfter", "\n", "return", "session", "\n", "}" ]
// SessionFromAssertion returns a new auth.Session generated from the SAML // assertion.
[ "SessionFromAssertion", "returns", "a", "new", "auth", ".", "Session", "generated", "from", "the", "SAML", "assertion", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/saml/saml.go#L11-L20
train
remind101/empire
processes.go
MustParseCommand
func MustParseCommand(command string) Command { c, err := ParseCommand(command) if err != nil { panic(err) } return c }
go
func MustParseCommand(command string) Command { c, err := ParseCommand(command) if err != nil { panic(err) } return c }
[ "func", "MustParseCommand", "(", "command", "string", ")", "Command", "{", "c", ",", "err", ":=", "ParseCommand", "(", "command", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "c", "\n", "}" ]
// MustParseCommand parses the string into a Command, panicing if there's an // error. This method should only be used in tests for convenience.
[ "MustParseCommand", "parses", "the", "string", "into", "a", "Command", "panicing", "if", "there", "s", "an", "error", ".", "This", "method", "should", "only", "be", "used", "in", "tests", "for", "convenience", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/processes.go#L32-L38
train
remind101/empire
processes.go
IsValid
func (p *Process) IsValid() error { // Ensure that processes marked as NoService can't be scaled up. if p.NoService { if p.Quantity != 0 { return errors.New("non-service processes cannot be scaled up") } } return nil }
go
func (p *Process) IsValid() error { // Ensure that processes marked as NoService can't be scaled up. if p.NoService { if p.Quantity != 0 { return errors.New("non-service processes cannot be scaled up") } } return nil }
[ "func", "(", "p", "*", "Process", ")", "IsValid", "(", ")", "error", "{", "// Ensure that processes marked as NoService can't be scaled up.", "if", "p", ".", "NoService", "{", "if", "p", ".", "Quantity", "!=", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// IsValid returns nil if the Process is valid.
[ "IsValid", "returns", "nil", "if", "the", "Process", "is", "valid", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/processes.go#L112-L121
train
remind101/empire
processes.go
Constraints
func (p *Process) Constraints() Constraints { return Constraints{ Memory: p.Memory, CPUShare: p.CPUShare, Nproc: p.Nproc, } }
go
func (p *Process) Constraints() Constraints { return Constraints{ Memory: p.Memory, CPUShare: p.CPUShare, Nproc: p.Nproc, } }
[ "func", "(", "p", "*", "Process", ")", "Constraints", "(", ")", "Constraints", "{", "return", "Constraints", "{", "Memory", ":", "p", ".", "Memory", ",", "CPUShare", ":", "p", ".", "CPUShare", ",", "Nproc", ":", "p", ".", "Nproc", ",", "}", "\n", "}" ]
// Constraints returns a constraints.Constraints from this Process definition.
[ "Constraints", "returns", "a", "constraints", ".", "Constraints", "from", "this", "Process", "definition", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/processes.go#L124-L130
train
remind101/empire
processes.go
IsValid
func (f Formation) IsValid() error { for n, p := range f { if err := p.IsValid(); err != nil { return fmt.Errorf("process %s is not valid: %v", n, err) } } return nil }
go
func (f Formation) IsValid() error { for n, p := range f { if err := p.IsValid(); err != nil { return fmt.Errorf("process %s is not valid: %v", n, err) } } return nil }
[ "func", "(", "f", "Formation", ")", "IsValid", "(", ")", "error", "{", "for", "n", ",", "p", ":=", "range", "f", "{", "if", "err", ":=", "p", ".", "IsValid", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "n", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// IsValid returns nil if all of the Processes are valid.
[ "IsValid", "returns", "nil", "if", "all", "of", "the", "Processes", "are", "valid", "." ]
3daba389f6b07b5d219246bfc7d901fcec664161
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/processes.go#L144-L152
train