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",
"(",
"\"",
"\"",
",",
"\"",
"\"",
... | // 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",
... | 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\"`",
... | // 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",
... | 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",
",",
"\"",
"\"",
"+... | // 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",
")... | // 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... | // 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",
")",
"{",
"... | // 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.Extra... | 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.Extra... | [
"func",
"slugsCreateByImage",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"r",
"ImageRegistry",
",",
"img",
"image",
".",
"Image",
",",
"w",
"*",
"DeploymentStream",
")",
"(",
"*",
"Slug",
",",
"error",
")",
"{",
"v... | // 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",
"... | 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",
"int... | // 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",
... | // 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"... | 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"... | [
"func",
"New",
"(",
"e",
"*",
"empire",
".",
"Empire",
")",
"*",
"Server",
"{",
"r",
":=",
"&",
"Server",
"{",
"Empire",
":",
"e",
",",
"mux",
":",
"mux",
".",
"NewRouter",
"(",
")",
",",
"}",
"\n\n",
"// Apps",
"r",
".",
"handle",
"(",
"\"",
... | // 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 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",
"}... | // 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",
"}",
... | // 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",
")",
... | // 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",
",... | // 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... | // 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",
"."... | // 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",
")",
"\... | // 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... | 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... | [
"func",
"(",
"s",
"*",
"Server",
")",
"SAMLACS",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"s",
".",
"ServiceProvider",
"==",
"nil",
"{",
"http",
".",
"NotFound",
"(",
"w",
",",
"r",
")",
"\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",
... | // 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",
",",
"... | // 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.DoRe... | 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.DoRe... | [
"func",
"(",
"c",
"*",
"Client",
")",
"SSLEndpointList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"SSLEndpoint",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\... | // 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",
"li... | 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",
"SSLEndpoi... | // 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",
"... | 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, &For... | 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, &For... | [
"func",
"(",
"h",
"*",
"Server",
")",
"GetFormation",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n\n",
"app",
",",
"err",
":=",
"h",
".",
"findA... | // 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",
"{",
"... | // 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",
"(",
"&",... | // 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, &plansRe... | 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, &plansRe... | [
"func",
"(",
"c",
"*",
"Client",
")",
"PlanList",
"(",
"addonServiceIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Plan",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
... | // 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... | 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... | // 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",
","... | // 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",... | // 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
}
de... | 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
}
de... | [
"func",
"(",
"c",
"*",
"ResponseClient",
")",
"SendResponse",
"(",
"req",
"Request",
",",
"response",
"Response",
")",
"error",
"{",
"raw",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // 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",
",",
... | // 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",
"}... | // 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",
... | // 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",
"."... | // 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(... | 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(... | [
"func",
"(",
"r",
"*",
"runtimeSample",
")",
"drain",
"(",
"stats",
"Stats",
")",
"{",
"stats",
".",
"Gauge",
"(",
"\"",
"\"",
",",
"float32",
"(",
"r",
".",
"NumGoroutine",
")",
",",
"1.0",
",",
"nil",
")",
"\n",
"stats",
".",
"Gauge",
"(",
"\""... | // 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/a... | 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/a... | [
"func",
"(",
"c",
"*",
"Client",
")",
"AppTransferCreate",
"(",
"app",
"string",
",",
"recipient",
"string",
")",
"(",
"*",
"AppTransfer",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"App",
"string",
"`json:\"app\"`",
"\n",
"Recipient",
"string"... | // 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",
... | 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",
"(",
"&",
... | // 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",
",",
... | // 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",
"}",
... | // 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",
"&",
"DockerDae... | // 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!
... | 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!
... | [
"func",
"multiExtractor",
"(",
"extractors",
"...",
"empire",
".",
"ProcfileExtractor",
")",
"empire",
".",
"ProcfileExtractor",
"{",
"return",
"empire",
".",
"ProcfileExtractorFunc",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"image",
"image",
"."... | // 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 :=... | 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 :=... | [
"func",
"(",
"e",
"*",
"fileExtractor",
")",
"ExtractProcfile",
"(",
"ctx",
"context",
".",
"Context",
",",
"img",
"image",
".",
"Image",
",",
"w",
"*",
"jsonmessage",
".",
"Stream",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"c",
",",
"er... | // 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",
".",
"Inspe... | // 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",
".",
"CreateConta... | // 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",
".",
"RemoveContainerOpti... | // 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 th... | 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 th... | [
"func",
"(",
"e",
"*",
"fileExtractor",
")",
"copyFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"containerID",
",",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
... | // 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",
"}",
"... | // 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",
"(... | // 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",
"(",
"\"",
"\"",
",",
"\"",
"\... | // 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",
... | 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 releas... | 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 releas... | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReleaseCreate",
"(",
"appIdentity",
"string",
",",
"slug",
"string",
",",
"options",
"*",
"ReleaseCreateOpts",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Slug",
"string",
"`jso... | // 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",
"i... | 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+"/rel... | 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+"/rel... | [
"func",
"(",
"c",
"*",
"Client",
")",
"ReleaseRollback",
"(",
"appIdentity",
",",
"release",
",",
"message",
"string",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Release",
"string",
"`json:\"release\"`",
"\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"... | // 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_unauthor... | 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_unauthor... | [
"func",
"SAMLUnauthorized",
"(",
"loginURL",
"string",
")",
"func",
"(",
"error",
")",
"*",
"ErrorResource",
"{",
"return",
"func",
"(",
"reason",
"error",
")",
"*",
"ErrorResource",
"{",
"if",
"reason",
"==",
"nil",
"{",
"reason",
"=",
"errors",
".",
"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",
","... | // 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",
",",
"\"",
"\"",
"+",
"keyIdent... | // 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",
")",
... | // 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",
... | // 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",
")",
"{",
"// Defa... | // 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
}... | 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
}... | [
"func",
"StaticAuthenticator",
"(",
"username",
",",
"password",
",",
"otp",
"string",
",",
"user",
"*",
"empire",
".",
"User",
")",
"Authenticator",
"{",
"return",
"AuthenticatorFunc",
"(",
"func",
"(",
"givenUsername",
",",
"givenPassword",
",",
"givenOtp",
... | // 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",
"NewSess... | // 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; ... | 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; ... | [
"func",
"WithMaxSessionDuration",
"(",
"auth",
"Authenticator",
",",
"exp",
"func",
"(",
")",
"time",
".",
"Time",
")",
"Authenticator",
"{",
"return",
"AuthenticatorFunc",
"(",
"func",
"(",
"username",
",",
"password",
",",
"otp",
"string",
")",
"(",
"*",
... | // 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",
"existi... | 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",
"(",
"\"",
"... | // 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",
"... | // 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",
":",
"ke... | // 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",
... | 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 ... | 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 ... | [
"func",
"(",
"m",
"*",
"Migrator",
")",
"Exec",
"(",
"dir",
"MigrationDirection",
",",
"migrations",
"...",
"Migration",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"_",
",",
"err",
":=",
"m",... | // 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
def... | 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
def... | [
"func",
"(",
"m",
"*",
"Migrator",
")",
"runMigration",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"dir",
"MigrationDirection",
",",
"migration",
"Migration",
")",
"error",
"{",
"shouldMigrate",
",",
"err",
":=",
"m",
".",
"shouldMigrate",
"(",
"tx",
",",
... | // 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",
... | 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",... | // 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",
... | 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.SendRe... | 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.SendRe... | [
"func",
"NewCustomResourceProvisioner",
"(",
"empire",
"*",
"empire",
".",
"Empire",
",",
"config",
"client",
".",
"ConfigProvider",
")",
"*",
"CustomResourceProvisioner",
"{",
"db",
":=",
"empire",
".",
"DB",
".",
"DB",
".",
"DB",
"(",
")",
"\n",
"p",
":=... | // 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",
",",
"Pro... | // 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... | 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... | [
"func",
"(",
"c",
"*",
"CustomResourceProvisioner",
")",
"Handle",
"(",
"ctx",
"context",
".",
"Context",
",",
"message",
"*",
"sqs",
".",
"Message",
")",
"error",
"{",
"var",
"m",
"Message",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
... | // 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",
"}",
... | // 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.Comma... | 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.Comma... | [
"func",
"taskFromInstance",
"(",
"i",
"*",
"twelvefactor",
".",
"Task",
")",
"*",
"Task",
"{",
"version",
":=",
"i",
".",
"Process",
".",
"Env",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"version",
"==",
"\"",
"\"",
"{",
"version",
"=",
"\"",
"\"",
"\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",
"suppo... | 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://co... | 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://co... | [
"func",
"RecordToCloudWatch",
"(",
"group",
"string",
",",
"config",
"client",
".",
"ConfigProvider",
")",
"empire",
".",
"RunRecorder",
"{",
"c",
":=",
"cloudwatchlogs",
".",
"New",
"(",
"config",
")",
"\n",
"g",
":=",
"cloudwatch",
".",
"NewGroup",
"(",
... | // 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",
... | // 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 t... | 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 t... | [
"func",
"(",
"l",
"*",
"AdvisoryLock",
")",
"Lock",
"(",
")",
"error",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"commited",
"{",
"panic",
"(",
"\"",
"\"",
")",... | // 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... | 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... | [
"func",
"(",
"l",
"*",
"AdvisoryLock",
")",
"Unlock",
"(",
")",
"error",
"{",
"l",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"commited",
"{",
"panic",
"(",
"\"",
"\"",
")... | // 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... | 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... | [
"func",
"suggest",
"(",
"s",
"string",
")",
"(",
"a",
"[",
"]",
"string",
")",
"{",
"var",
"g",
"Suggestions",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"commands",
"{",
"if",
"d",
":=",
"editDistance",
"(",
"s",
",",
"c",
".",
"Name",
"(",
")... | // 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",
... | // 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",
"(",
"... | // 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",
"(",
"\"",
"... | // 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 |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.