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
|
processes.go
|
Merge
|
func (f Formation) Merge(other Formation) Formation {
new := make(Formation)
for name, p := range f {
if existing, found := other[name]; found {
// If the existing Formation already had a process
// configuration for this process type, copy over the
// instance count.
p.Quantity = existing.Quantity
p.SetConstraints(existing.Constraints())
} else {
p.Quantity = DefaultQuantities[name]
p.SetConstraints(DefaultConstraints)
}
new[name] = p
}
return new
}
|
go
|
func (f Formation) Merge(other Formation) Formation {
new := make(Formation)
for name, p := range f {
if existing, found := other[name]; found {
// If the existing Formation already had a process
// configuration for this process type, copy over the
// instance count.
p.Quantity = existing.Quantity
p.SetConstraints(existing.Constraints())
} else {
p.Quantity = DefaultQuantities[name]
p.SetConstraints(DefaultConstraints)
}
new[name] = p
}
return new
}
|
[
"func",
"(",
"f",
"Formation",
")",
"Merge",
"(",
"other",
"Formation",
")",
"Formation",
"{",
"new",
":=",
"make",
"(",
"Formation",
")",
"\n\n",
"for",
"name",
",",
"p",
":=",
"range",
"f",
"{",
"if",
"existing",
",",
"found",
":=",
"other",
"[",
"name",
"]",
";",
"found",
"{",
"// If the existing Formation already had a process",
"// configuration for this process type, copy over the",
"// instance count.",
"p",
".",
"Quantity",
"=",
"existing",
".",
"Quantity",
"\n",
"p",
".",
"SetConstraints",
"(",
"existing",
".",
"Constraints",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"Quantity",
"=",
"DefaultQuantities",
"[",
"name",
"]",
"\n",
"p",
".",
"SetConstraints",
"(",
"DefaultConstraints",
")",
"\n",
"}",
"\n\n",
"new",
"[",
"name",
"]",
"=",
"p",
"\n",
"}",
"\n\n",
"return",
"new",
"\n",
"}"
] |
// Merge merges in the existing quantity and constraints from the old Formation
// into this Formation.
|
[
"Merge",
"merges",
"in",
"the",
"existing",
"quantity",
"and",
"constraints",
"from",
"the",
"old",
"Formation",
"into",
"this",
"Formation",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/processes.go#L186-L205
|
train
|
remind101/empire
|
empire.go
|
New
|
func New(db *DB) *Empire {
e := &Empire{
LogsStreamer: logsDisabled,
EventStream: NullEventStream,
DB: db,
db: db.DB,
}
e.apps = &appsService{Empire: e}
e.configs = &configsService{Empire: e}
e.deployer = &deployerService{Empire: e}
e.domains = &domainsService{Empire: e}
e.slugs = &slugsService{Empire: e}
e.tasks = &tasksService{Empire: e}
e.runner = &runnerService{Empire: e}
e.releases = &releasesService{Empire: e}
e.certs = &certsService{Empire: e}
return e
}
|
go
|
func New(db *DB) *Empire {
e := &Empire{
LogsStreamer: logsDisabled,
EventStream: NullEventStream,
DB: db,
db: db.DB,
}
e.apps = &appsService{Empire: e}
e.configs = &configsService{Empire: e}
e.deployer = &deployerService{Empire: e}
e.domains = &domainsService{Empire: e}
e.slugs = &slugsService{Empire: e}
e.tasks = &tasksService{Empire: e}
e.runner = &runnerService{Empire: e}
e.releases = &releasesService{Empire: e}
e.certs = &certsService{Empire: e}
return e
}
|
[
"func",
"New",
"(",
"db",
"*",
"DB",
")",
"*",
"Empire",
"{",
"e",
":=",
"&",
"Empire",
"{",
"LogsStreamer",
":",
"logsDisabled",
",",
"EventStream",
":",
"NullEventStream",
",",
"DB",
":",
"db",
",",
"db",
":",
"db",
".",
"DB",
",",
"}",
"\n\n",
"e",
".",
"apps",
"=",
"&",
"appsService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"configs",
"=",
"&",
"configsService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"deployer",
"=",
"&",
"deployerService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"domains",
"=",
"&",
"domainsService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"slugs",
"=",
"&",
"slugsService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"tasks",
"=",
"&",
"tasksService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"runner",
"=",
"&",
"runnerService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"releases",
"=",
"&",
"releasesService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"e",
".",
"certs",
"=",
"&",
"certsService",
"{",
"Empire",
":",
"e",
"}",
"\n",
"return",
"e",
"\n",
"}"
] |
// New returns a new Empire instance.
|
[
"New",
"returns",
"a",
"new",
"Empire",
"instance",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L113-L132
|
train
|
remind101/empire
|
empire.go
|
AppsFind
|
func (e *Empire) AppsFind(q AppsQuery) (*App, error) {
return appsFind(e.db, q)
}
|
go
|
func (e *Empire) AppsFind(q AppsQuery) (*App, error) {
return appsFind(e.db, q)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"AppsFind",
"(",
"q",
"AppsQuery",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"return",
"appsFind",
"(",
"e",
".",
"db",
",",
"q",
")",
"\n",
"}"
] |
// AppsFind finds the first app matching the query.
|
[
"AppsFind",
"finds",
"the",
"first",
"app",
"matching",
"the",
"query",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L135-L137
|
train
|
remind101/empire
|
empire.go
|
Apps
|
func (e *Empire) Apps(q AppsQuery) ([]*App, error) {
return apps(e.db, q)
}
|
go
|
func (e *Empire) Apps(q AppsQuery) ([]*App, error) {
return apps(e.db, q)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Apps",
"(",
"q",
"AppsQuery",
")",
"(",
"[",
"]",
"*",
"App",
",",
"error",
")",
"{",
"return",
"apps",
"(",
"e",
".",
"db",
",",
"q",
")",
"\n",
"}"
] |
// Apps returns all Apps.
|
[
"Apps",
"returns",
"all",
"Apps",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L140-L142
|
train
|
remind101/empire
|
empire.go
|
Create
|
func (e *Empire) Create(ctx context.Context, opts CreateOpts) (*App, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
a, err := appsCreate(e.db, &App{Name: opts.Name})
if err != nil {
return a, err
}
return a, e.PublishEvent(opts.Event())
}
|
go
|
func (e *Empire) Create(ctx context.Context, opts CreateOpts) (*App, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
a, err := appsCreate(e.db, &App{Name: opts.Name})
if err != nil {
return a, err
}
return a, e.PublishEvent(opts.Event())
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"CreateOpts",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"a",
",",
"err",
":=",
"appsCreate",
"(",
"e",
".",
"db",
",",
"&",
"App",
"{",
"Name",
":",
"opts",
".",
"Name",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"a",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"a",
",",
"e",
".",
"PublishEvent",
"(",
"opts",
".",
"Event",
"(",
")",
")",
"\n",
"}"
] |
// Create creates a new app.
|
[
"Create",
"creates",
"a",
"new",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L176-L187
|
train
|
remind101/empire
|
empire.go
|
Destroy
|
func (e *Empire) Destroy(ctx context.Context, opts DestroyOpts) error {
if err := opts.Validate(e); err != nil {
return err
}
tx := e.db.Begin()
if err := e.apps.Destroy(ctx, tx, opts.App); err != nil {
tx.Rollback()
return err
}
if err := tx.Commit().Error; err != nil {
return err
}
return e.PublishEvent(opts.Event())
}
|
go
|
func (e *Empire) Destroy(ctx context.Context, opts DestroyOpts) error {
if err := opts.Validate(e); err != nil {
return err
}
tx := e.db.Begin()
if err := e.apps.Destroy(ctx, tx, opts.App); err != nil {
tx.Rollback()
return err
}
if err := tx.Commit().Error; err != nil {
return err
}
return e.PublishEvent(opts.Event())
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Destroy",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"DestroyOpts",
")",
"error",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"if",
"err",
":=",
"e",
".",
"apps",
".",
"Destroy",
"(",
"ctx",
",",
"tx",
",",
"opts",
".",
"App",
")",
";",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"e",
".",
"PublishEvent",
"(",
"opts",
".",
"Event",
"(",
")",
")",
"\n",
"}"
] |
// Destroy destroys an app.
|
[
"Destroy",
"destroys",
"an",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L214-L231
|
train
|
remind101/empire
|
empire.go
|
Config
|
func (e *Empire) Config(app *App) (*Config, error) {
tx := e.db.Begin()
c, err := e.configs.Config(tx, app)
if err != nil {
tx.Rollback()
return c, err
}
if err := tx.Commit().Error; err != nil {
return c, err
}
return c, nil
}
|
go
|
func (e *Empire) Config(app *App) (*Config, error) {
tx := e.db.Begin()
c, err := e.configs.Config(tx, app)
if err != nil {
tx.Rollback()
return c, err
}
if err := tx.Commit().Error; err != nil {
return c, err
}
return c, nil
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Config",
"(",
"app",
"*",
"App",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"c",
",",
"err",
":=",
"e",
".",
"configs",
".",
"Config",
"(",
"tx",
",",
"app",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"c",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"c",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] |
// Config returns the current Config for a given app.
|
[
"Config",
"returns",
"the",
"current",
"Config",
"for",
"a",
"given",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L234-L248
|
train
|
remind101/empire
|
empire.go
|
SetMaintenanceMode
|
func (e *Empire) SetMaintenanceMode(ctx context.Context, opts SetMaintenanceModeOpts) error {
if err := opts.Validate(e); err != nil {
return err
}
tx := e.db.Begin()
app := opts.App
app.Maintenance = opts.Maintenance
if err := appsUpdate(tx, app); err != nil {
tx.Rollback()
return err
}
if err := e.releases.ReleaseApp(ctx, tx, app, nil); err != nil {
tx.Rollback()
if err == ErrNoReleases {
return nil
}
return err
}
if err := tx.Commit().Error; err != nil {
return err
}
return e.PublishEvent(opts.Event())
}
|
go
|
func (e *Empire) SetMaintenanceMode(ctx context.Context, opts SetMaintenanceModeOpts) error {
if err := opts.Validate(e); err != nil {
return err
}
tx := e.db.Begin()
app := opts.App
app.Maintenance = opts.Maintenance
if err := appsUpdate(tx, app); err != nil {
tx.Rollback()
return err
}
if err := e.releases.ReleaseApp(ctx, tx, app, nil); err != nil {
tx.Rollback()
if err == ErrNoReleases {
return nil
}
return err
}
if err := tx.Commit().Error; err != nil {
return err
}
return e.PublishEvent(opts.Event())
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"SetMaintenanceMode",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"SetMaintenanceModeOpts",
")",
"error",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"app",
":=",
"opts",
".",
"App",
"\n\n",
"app",
".",
"Maintenance",
"=",
"opts",
".",
"Maintenance",
"\n\n",
"if",
"err",
":=",
"appsUpdate",
"(",
"tx",
",",
"app",
")",
";",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"e",
".",
"releases",
".",
"ReleaseApp",
"(",
"ctx",
",",
"tx",
",",
"app",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"if",
"err",
"==",
"ErrNoReleases",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"e",
".",
"PublishEvent",
"(",
"opts",
".",
"Event",
"(",
")",
")",
"\n",
"}"
] |
// SetMaintenanceMode enables or disables "maintenance mode" on the app. When an
// app is in maintenance mode, all processes will be scaled down to 0. When
// taken out of maintenance mode, all processes will be scaled up back to their
// existing values.
|
[
"SetMaintenanceMode",
"enables",
"or",
"disables",
"maintenance",
"mode",
"on",
"the",
"app",
".",
"When",
"an",
"app",
"is",
"in",
"maintenance",
"mode",
"all",
"processes",
"will",
"be",
"scaled",
"down",
"to",
"0",
".",
"When",
"taken",
"out",
"of",
"maintenance",
"mode",
"all",
"processes",
"will",
"be",
"scaled",
"up",
"back",
"to",
"their",
"existing",
"values",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L281-L311
|
train
|
remind101/empire
|
empire.go
|
Set
|
func (e *Empire) Set(ctx context.Context, opts SetOpts) (*Config, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
tx := e.db.Begin()
c, err := e.configs.Set(ctx, tx, opts)
if err != nil {
tx.Rollback()
return c, err
}
if err := tx.Commit().Error; err != nil {
return c, err
}
return c, e.PublishEvent(opts.Event())
}
|
go
|
func (e *Empire) Set(ctx context.Context, opts SetOpts) (*Config, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
tx := e.db.Begin()
c, err := e.configs.Set(ctx, tx, opts)
if err != nil {
tx.Rollback()
return c, err
}
if err := tx.Commit().Error; err != nil {
return c, err
}
return c, e.PublishEvent(opts.Event())
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Set",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"SetOpts",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"c",
",",
"err",
":=",
"e",
".",
"configs",
".",
"Set",
"(",
"ctx",
",",
"tx",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"c",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"c",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
",",
"e",
".",
"PublishEvent",
"(",
"opts",
".",
"Event",
"(",
")",
")",
"\n",
"}"
] |
// Set applies the new config vars to the apps current Config, returning the new
// Config. If the app has a running release, a new release will be created and
// run.
|
[
"Set",
"applies",
"the",
"new",
"config",
"vars",
"to",
"the",
"apps",
"current",
"Config",
"returning",
"the",
"new",
"Config",
".",
"If",
"the",
"app",
"has",
"a",
"running",
"release",
"a",
"new",
"release",
"will",
"be",
"created",
"and",
"run",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L350-L368
|
train
|
remind101/empire
|
empire.go
|
DomainsFind
|
func (e *Empire) DomainsFind(q DomainsQuery) (*Domain, error) {
return domainsFind(e.db, q)
}
|
go
|
func (e *Empire) DomainsFind(q DomainsQuery) (*Domain, error) {
return domainsFind(e.db, q)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"DomainsFind",
"(",
"q",
"DomainsQuery",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"return",
"domainsFind",
"(",
"e",
".",
"db",
",",
"q",
")",
"\n",
"}"
] |
// DomainsFind returns the first domain matching the query.
|
[
"DomainsFind",
"returns",
"the",
"first",
"domain",
"matching",
"the",
"query",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L371-L373
|
train
|
remind101/empire
|
empire.go
|
Domains
|
func (e *Empire) Domains(q DomainsQuery) ([]*Domain, error) {
return domains(e.db, q)
}
|
go
|
func (e *Empire) Domains(q DomainsQuery) ([]*Domain, error) {
return domains(e.db, q)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Domains",
"(",
"q",
"DomainsQuery",
")",
"(",
"[",
"]",
"*",
"Domain",
",",
"error",
")",
"{",
"return",
"domains",
"(",
"e",
".",
"db",
",",
"q",
")",
"\n",
"}"
] |
// Domains returns all domains matching the query.
|
[
"Domains",
"returns",
"all",
"domains",
"matching",
"the",
"query",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L376-L378
|
train
|
remind101/empire
|
empire.go
|
DomainsCreate
|
func (e *Empire) DomainsCreate(ctx context.Context, domain *Domain) (*Domain, error) {
tx := e.db.Begin()
d, err := e.domains.DomainsCreate(ctx, tx, domain)
if err != nil {
tx.Rollback()
return d, err
}
if err := tx.Commit().Error; err != nil {
return d, err
}
return d, nil
}
|
go
|
func (e *Empire) DomainsCreate(ctx context.Context, domain *Domain) (*Domain, error) {
tx := e.db.Begin()
d, err := e.domains.DomainsCreate(ctx, tx, domain)
if err != nil {
tx.Rollback()
return d, err
}
if err := tx.Commit().Error; err != nil {
return d, err
}
return d, nil
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"DomainsCreate",
"(",
"ctx",
"context",
".",
"Context",
",",
"domain",
"*",
"Domain",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"d",
",",
"err",
":=",
"e",
".",
"domains",
".",
"DomainsCreate",
"(",
"ctx",
",",
"tx",
",",
"domain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"d",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"d",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"d",
",",
"nil",
"\n",
"}"
] |
// DomainsCreate adds a new Domain for an App.
|
[
"DomainsCreate",
"adds",
"a",
"new",
"Domain",
"for",
"an",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L381-L395
|
train
|
remind101/empire
|
empire.go
|
Tasks
|
func (e *Empire) Tasks(ctx context.Context, app *App) ([]*Task, error) {
return e.tasks.Tasks(ctx, app)
}
|
go
|
func (e *Empire) Tasks(ctx context.Context, app *App) ([]*Task, error) {
return e.tasks.Tasks(ctx, app)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Tasks",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"*",
"App",
")",
"(",
"[",
"]",
"*",
"Task",
",",
"error",
")",
"{",
"return",
"e",
".",
"tasks",
".",
"Tasks",
"(",
"ctx",
",",
"app",
")",
"\n",
"}"
] |
// Tasks returns the Tasks for the given app.
|
[
"Tasks",
"returns",
"the",
"Tasks",
"for",
"the",
"given",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L414-L416
|
train
|
remind101/empire
|
empire.go
|
Restart
|
func (e *Empire) Restart(ctx context.Context, opts RestartOpts) error {
if err := opts.Validate(e); err != nil {
return err
}
if err := e.apps.Restart(ctx, e.db, opts); err != nil {
return err
}
return e.PublishEvent(opts.Event())
}
|
go
|
func (e *Empire) Restart(ctx context.Context, opts RestartOpts) error {
if err := opts.Validate(e); err != nil {
return err
}
if err := e.apps.Restart(ctx, e.db, opts); err != nil {
return err
}
return e.PublishEvent(opts.Event())
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Restart",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"RestartOpts",
")",
"error",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"e",
".",
"apps",
".",
"Restart",
"(",
"ctx",
",",
"e",
".",
"db",
",",
"opts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"e",
".",
"PublishEvent",
"(",
"opts",
".",
"Event",
"(",
")",
")",
"\n\n",
"}"
] |
// Restart restarts processes matching the given prefix for the given Release.
// If the prefix is empty, it will match all processes for the release.
|
[
"Restart",
"restarts",
"processes",
"matching",
"the",
"given",
"prefix",
"for",
"the",
"given",
"Release",
".",
"If",
"the",
"prefix",
"is",
"empty",
"it",
"will",
"match",
"all",
"processes",
"for",
"the",
"release",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L450-L461
|
train
|
remind101/empire
|
empire.go
|
Run
|
func (e *Empire) Run(ctx context.Context, opts RunOpts) error {
event := opts.Event()
if err := opts.Validate(e); err != nil {
return err
}
if e.RunRecorder != nil && (opts.Stdout != nil || opts.Stderr != nil) {
w, err := e.RunRecorder()
if err != nil {
return err
}
// Add the log url to the event, if there is one.
if w, ok := w.(interface {
URL() string
}); ok {
event.URL = w.URL()
}
msg := fmt.Sprintf("Running `%s` on %s as %s", opts.Command, opts.App.Name, opts.User.Name)
msg = appendCommitMessage(msg, opts.Message)
io.WriteString(w, fmt.Sprintf("%s\n", msg))
// Write output to both the original output as well as the
// record.
if opts.Stdout != nil {
opts.Stdout = io.MultiWriter(w, opts.Stdout)
}
if opts.Stderr != nil {
opts.Stderr = io.MultiWriter(w, opts.Stderr)
}
}
if err := e.PublishEvent(event); err != nil {
return err
}
if err := e.runner.Run(ctx, opts); err != nil {
return err
}
event.Finish()
return e.PublishEvent(event)
}
|
go
|
func (e *Empire) Run(ctx context.Context, opts RunOpts) error {
event := opts.Event()
if err := opts.Validate(e); err != nil {
return err
}
if e.RunRecorder != nil && (opts.Stdout != nil || opts.Stderr != nil) {
w, err := e.RunRecorder()
if err != nil {
return err
}
// Add the log url to the event, if there is one.
if w, ok := w.(interface {
URL() string
}); ok {
event.URL = w.URL()
}
msg := fmt.Sprintf("Running `%s` on %s as %s", opts.Command, opts.App.Name, opts.User.Name)
msg = appendCommitMessage(msg, opts.Message)
io.WriteString(w, fmt.Sprintf("%s\n", msg))
// Write output to both the original output as well as the
// record.
if opts.Stdout != nil {
opts.Stdout = io.MultiWriter(w, opts.Stdout)
}
if opts.Stderr != nil {
opts.Stderr = io.MultiWriter(w, opts.Stderr)
}
}
if err := e.PublishEvent(event); err != nil {
return err
}
if err := e.runner.Run(ctx, opts); err != nil {
return err
}
event.Finish()
return e.PublishEvent(event)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"RunOpts",
")",
"error",
"{",
"event",
":=",
"opts",
".",
"Event",
"(",
")",
"\n\n",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"e",
".",
"RunRecorder",
"!=",
"nil",
"&&",
"(",
"opts",
".",
"Stdout",
"!=",
"nil",
"||",
"opts",
".",
"Stderr",
"!=",
"nil",
")",
"{",
"w",
",",
"err",
":=",
"e",
".",
"RunRecorder",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Add the log url to the event, if there is one.",
"if",
"w",
",",
"ok",
":=",
"w",
".",
"(",
"interface",
"{",
"URL",
"(",
")",
"string",
"\n",
"}",
")",
";",
"ok",
"{",
"event",
".",
"URL",
"=",
"w",
".",
"URL",
"(",
")",
"\n",
"}",
"\n\n",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"Command",
",",
"opts",
".",
"App",
".",
"Name",
",",
"opts",
".",
"User",
".",
"Name",
")",
"\n",
"msg",
"=",
"appendCommitMessage",
"(",
"msg",
",",
"opts",
".",
"Message",
")",
"\n",
"io",
".",
"WriteString",
"(",
"w",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"msg",
")",
")",
"\n\n",
"// Write output to both the original output as well as the",
"// record.",
"if",
"opts",
".",
"Stdout",
"!=",
"nil",
"{",
"opts",
".",
"Stdout",
"=",
"io",
".",
"MultiWriter",
"(",
"w",
",",
"opts",
".",
"Stdout",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Stderr",
"!=",
"nil",
"{",
"opts",
".",
"Stderr",
"=",
"io",
".",
"MultiWriter",
"(",
"w",
",",
"opts",
".",
"Stderr",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"e",
".",
"PublishEvent",
"(",
"event",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"e",
".",
"runner",
".",
"Run",
"(",
"ctx",
",",
"opts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"event",
".",
"Finish",
"(",
")",
"\n",
"return",
"e",
".",
"PublishEvent",
"(",
"event",
")",
"\n",
"}"
] |
// Run runs a one-off process for a given App and command.
|
[
"Run",
"runs",
"a",
"one",
"-",
"off",
"process",
"for",
"a",
"given",
"App",
"and",
"command",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L510-L554
|
train
|
remind101/empire
|
empire.go
|
Releases
|
func (e *Empire) Releases(q ReleasesQuery) ([]*Release, error) {
return releases(e.db, q)
}
|
go
|
func (e *Empire) Releases(q ReleasesQuery) ([]*Release, error) {
return releases(e.db, q)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Releases",
"(",
"q",
"ReleasesQuery",
")",
"(",
"[",
"]",
"*",
"Release",
",",
"error",
")",
"{",
"return",
"releases",
"(",
"e",
".",
"db",
",",
"q",
")",
"\n",
"}"
] |
// Releases returns all Releases for a given App.
|
[
"Releases",
"returns",
"all",
"Releases",
"for",
"a",
"given",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L557-L559
|
train
|
remind101/empire
|
empire.go
|
ReleasesFind
|
func (e *Empire) ReleasesFind(q ReleasesQuery) (*Release, error) {
return releasesFind(e.db, q)
}
|
go
|
func (e *Empire) ReleasesFind(q ReleasesQuery) (*Release, error) {
return releasesFind(e.db, q)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"ReleasesFind",
"(",
"q",
"ReleasesQuery",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"return",
"releasesFind",
"(",
"e",
".",
"db",
",",
"q",
")",
"\n",
"}"
] |
// ReleasesFind returns the first releases for a given App.
|
[
"ReleasesFind",
"returns",
"the",
"first",
"releases",
"for",
"a",
"given",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L562-L564
|
train
|
remind101/empire
|
empire.go
|
Rollback
|
func (e *Empire) Rollback(ctx context.Context, opts RollbackOpts) (*Release, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
tx := e.db.Begin()
r, err := e.releases.Rollback(ctx, tx, opts)
if err != nil {
tx.Rollback()
return r, err
}
if err := tx.Commit().Error; err != nil {
return r, err
}
return r, e.PublishEvent(opts.Event())
}
|
go
|
func (e *Empire) Rollback(ctx context.Context, opts RollbackOpts) (*Release, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
tx := e.db.Begin()
r, err := e.releases.Rollback(ctx, tx, opts)
if err != nil {
tx.Rollback()
return r, err
}
if err := tx.Commit().Error; err != nil {
return r, err
}
return r, e.PublishEvent(opts.Event())
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Rollback",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"RollbackOpts",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"r",
",",
"err",
":=",
"e",
".",
"releases",
".",
"Rollback",
"(",
"ctx",
",",
"tx",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"r",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"e",
".",
"PublishEvent",
"(",
"opts",
".",
"Event",
"(",
")",
")",
"\n",
"}"
] |
// Rollback rolls an app back to a specific release version. Returns a
// new release.
|
[
"Rollback",
"rolls",
"an",
"app",
"back",
"to",
"a",
"specific",
"release",
"version",
".",
"Returns",
"a",
"new",
"release",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L597-L615
|
train
|
remind101/empire
|
empire.go
|
Deploy
|
func (e *Empire) Deploy(ctx context.Context, opts DeployOpts) (*Release, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
r, err := e.deployer.Deploy(ctx, opts)
if err != nil {
return r, err
}
event := opts.Event()
event.Release = r.Version
event.Environment = e.Environment
// Deals with new app creation on first deploy
if event.App == "" && r.App != nil {
event.App = r.App.Name
event.app = r.App
}
return r, e.PublishEvent(event)
}
|
go
|
func (e *Empire) Deploy(ctx context.Context, opts DeployOpts) (*Release, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
r, err := e.deployer.Deploy(ctx, opts)
if err != nil {
return r, err
}
event := opts.Event()
event.Release = r.Version
event.Environment = e.Environment
// Deals with new app creation on first deploy
if event.App == "" && r.App != nil {
event.App = r.App.Name
event.app = r.App
}
return r, e.PublishEvent(event)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Deploy",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"DeployOpts",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"e",
".",
"deployer",
".",
"Deploy",
"(",
"ctx",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n\n",
"event",
":=",
"opts",
".",
"Event",
"(",
")",
"\n",
"event",
".",
"Release",
"=",
"r",
".",
"Version",
"\n",
"event",
".",
"Environment",
"=",
"e",
".",
"Environment",
"\n",
"// Deals with new app creation on first deploy",
"if",
"event",
".",
"App",
"==",
"\"",
"\"",
"&&",
"r",
".",
"App",
"!=",
"nil",
"{",
"event",
".",
"App",
"=",
"r",
".",
"App",
".",
"Name",
"\n",
"event",
".",
"app",
"=",
"r",
".",
"App",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"e",
".",
"PublishEvent",
"(",
"event",
")",
"\n",
"}"
] |
// Deploy deploys an image and streams the output to w.
|
[
"Deploy",
"deploys",
"an",
"image",
"and",
"streams",
"the",
"output",
"to",
"w",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L662-L682
|
train
|
remind101/empire
|
empire.go
|
Scale
|
func (e *Empire) Scale(ctx context.Context, opts ScaleOpts) ([]*Process, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
tx := e.db.Begin()
ps, err := e.apps.Scale(ctx, tx, opts)
if err != nil {
tx.Rollback()
return ps, err
}
return ps, tx.Commit().Error
}
|
go
|
func (e *Empire) Scale(ctx context.Context, opts ScaleOpts) ([]*Process, error) {
if err := opts.Validate(e); err != nil {
return nil, err
}
tx := e.db.Begin()
ps, err := e.apps.Scale(ctx, tx, opts)
if err != nil {
tx.Rollback()
return ps, err
}
return ps, tx.Commit().Error
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"Scale",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"ScaleOpts",
")",
"(",
"[",
"]",
"*",
"Process",
",",
"error",
")",
"{",
"if",
"err",
":=",
"opts",
".",
"Validate",
"(",
"e",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"ps",
",",
"err",
":=",
"e",
".",
"apps",
".",
"Scale",
"(",
"ctx",
",",
"tx",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"ps",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ps",
",",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
"\n",
"}"
] |
// Scale scales an apps processes.
|
[
"Scale",
"scales",
"an",
"apps",
"processes",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L737-L751
|
train
|
remind101/empire
|
empire.go
|
ListScale
|
func (e *Empire) ListScale(ctx context.Context, app *App) (Formation, error) {
return currentFormation(e.db, app)
}
|
go
|
func (e *Empire) ListScale(ctx context.Context, app *App) (Formation, error) {
return currentFormation(e.db, app)
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"ListScale",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"*",
"App",
")",
"(",
"Formation",
",",
"error",
")",
"{",
"return",
"currentFormation",
"(",
"e",
".",
"db",
",",
"app",
")",
"\n",
"}"
] |
// ListScale lists the current scale settings for a given App
|
[
"ListScale",
"lists",
"the",
"current",
"scale",
"settings",
"for",
"a",
"given",
"App"
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L754-L756
|
train
|
remind101/empire
|
empire.go
|
StreamLogs
|
func (e *Empire) StreamLogs(app *App, w io.Writer, duration time.Duration) error {
if err := e.LogsStreamer.StreamLogs(app, w, duration); err != nil {
return fmt.Errorf("error streaming logs: %v", err)
}
return nil
}
|
go
|
func (e *Empire) StreamLogs(app *App, w io.Writer, duration time.Duration) error {
if err := e.LogsStreamer.StreamLogs(app, w, duration); err != nil {
return fmt.Errorf("error streaming logs: %v", err)
}
return nil
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"StreamLogs",
"(",
"app",
"*",
"App",
",",
"w",
"io",
".",
"Writer",
",",
"duration",
"time",
".",
"Duration",
")",
"error",
"{",
"if",
"err",
":=",
"e",
".",
"LogsStreamer",
".",
"StreamLogs",
"(",
"app",
",",
"w",
",",
"duration",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Streamlogs streams logs from an app.
|
[
"Streamlogs",
"streams",
"logs",
"from",
"an",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L759-L765
|
train
|
remind101/empire
|
empire.go
|
CertsAttach
|
func (e *Empire) CertsAttach(ctx context.Context, opts CertsAttachOpts) error {
tx := e.db.Begin()
if err := e.certs.CertsAttach(ctx, tx, opts); err != nil {
tx.Rollback()
return err
}
return tx.Commit().Error
}
|
go
|
func (e *Empire) CertsAttach(ctx context.Context, opts CertsAttachOpts) error {
tx := e.db.Begin()
if err := e.certs.CertsAttach(ctx, tx, opts); err != nil {
tx.Rollback()
return err
}
return tx.Commit().Error
}
|
[
"func",
"(",
"e",
"*",
"Empire",
")",
"CertsAttach",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"CertsAttachOpts",
")",
"error",
"{",
"tx",
":=",
"e",
".",
"db",
".",
"Begin",
"(",
")",
"\n\n",
"if",
"err",
":=",
"e",
".",
"certs",
".",
"CertsAttach",
"(",
"ctx",
",",
"tx",
",",
"opts",
")",
";",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"tx",
".",
"Commit",
"(",
")",
".",
"Error",
"\n",
"}"
] |
// CertsAttach attaches an SSL certificate to the app.
|
[
"CertsAttach",
"attaches",
"an",
"SSL",
"certificate",
"to",
"the",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/empire.go#L779-L788
|
train
|
remind101/empire
|
scheduler/cloudformation/clients.go
|
ecsWithCaching
|
func ecsWithCaching(ecs *ECS) *cachingECSClient {
return &cachingECSClient{
ecsClient: ecs,
taskDefinitions: cache.New(defaultExpiration, defaultPurge),
}
}
|
go
|
func ecsWithCaching(ecs *ECS) *cachingECSClient {
return &cachingECSClient{
ecsClient: ecs,
taskDefinitions: cache.New(defaultExpiration, defaultPurge),
}
}
|
[
"func",
"ecsWithCaching",
"(",
"ecs",
"*",
"ECS",
")",
"*",
"cachingECSClient",
"{",
"return",
"&",
"cachingECSClient",
"{",
"ecsClient",
":",
"ecs",
",",
"taskDefinitions",
":",
"cache",
".",
"New",
"(",
"defaultExpiration",
",",
"defaultPurge",
")",
",",
"}",
"\n",
"}"
] |
// ecsWithCaching wraps an ecs.ECS client with caching.
|
[
"ecsWithCaching",
"wraps",
"an",
"ecs",
".",
"ECS",
"client",
"with",
"caching",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/clients.go#L34-L39
|
train
|
remind101/empire
|
scheduler/cloudformation/clients.go
|
DescribeTaskDefinition
|
func (c *cachingECSClient) DescribeTaskDefinition(input *ecs.DescribeTaskDefinitionInput) (*ecs.DescribeTaskDefinitionOutput, error) {
if _, err := arn.Parse(*input.TaskDefinition); err != nil {
return c.ecsClient.DescribeTaskDefinition(input)
}
if v, ok := c.taskDefinitions.Get(*input.TaskDefinition); ok {
return &ecs.DescribeTaskDefinitionOutput{
TaskDefinition: v.(*ecs.TaskDefinition),
}, nil
}
resp, err := c.ecsClient.DescribeTaskDefinition(input)
if err != nil {
return resp, err
}
c.taskDefinitions.Set(*resp.TaskDefinition.TaskDefinitionArn, resp.TaskDefinition, 0)
return resp, err
}
|
go
|
func (c *cachingECSClient) DescribeTaskDefinition(input *ecs.DescribeTaskDefinitionInput) (*ecs.DescribeTaskDefinitionOutput, error) {
if _, err := arn.Parse(*input.TaskDefinition); err != nil {
return c.ecsClient.DescribeTaskDefinition(input)
}
if v, ok := c.taskDefinitions.Get(*input.TaskDefinition); ok {
return &ecs.DescribeTaskDefinitionOutput{
TaskDefinition: v.(*ecs.TaskDefinition),
}, nil
}
resp, err := c.ecsClient.DescribeTaskDefinition(input)
if err != nil {
return resp, err
}
c.taskDefinitions.Set(*resp.TaskDefinition.TaskDefinitionArn, resp.TaskDefinition, 0)
return resp, err
}
|
[
"func",
"(",
"c",
"*",
"cachingECSClient",
")",
"DescribeTaskDefinition",
"(",
"input",
"*",
"ecs",
".",
"DescribeTaskDefinitionInput",
")",
"(",
"*",
"ecs",
".",
"DescribeTaskDefinitionOutput",
",",
"error",
")",
"{",
"if",
"_",
",",
"err",
":=",
"arn",
".",
"Parse",
"(",
"*",
"input",
".",
"TaskDefinition",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"c",
".",
"ecsClient",
".",
"DescribeTaskDefinition",
"(",
"input",
")",
"\n",
"}",
"\n\n",
"if",
"v",
",",
"ok",
":=",
"c",
".",
"taskDefinitions",
".",
"Get",
"(",
"*",
"input",
".",
"TaskDefinition",
")",
";",
"ok",
"{",
"return",
"&",
"ecs",
".",
"DescribeTaskDefinitionOutput",
"{",
"TaskDefinition",
":",
"v",
".",
"(",
"*",
"ecs",
".",
"TaskDefinition",
")",
",",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"c",
".",
"ecsClient",
".",
"DescribeTaskDefinition",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"c",
".",
"taskDefinitions",
".",
"Set",
"(",
"*",
"resp",
".",
"TaskDefinition",
".",
"TaskDefinitionArn",
",",
"resp",
".",
"TaskDefinition",
",",
"0",
")",
"\n\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] |
// DescribeTaskDefinition will use the task definition from cache if provided
// with a task definition ARN.
|
[
"DescribeTaskDefinition",
"will",
"use",
"the",
"task",
"definition",
"from",
"cache",
"if",
"provided",
"with",
"a",
"task",
"definition",
"ARN",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/clients.go#L43-L62
|
train
|
remind101/empire
|
scheduler/cloudformation/clients.go
|
WaitUntilTasksNotPending
|
func (c *ECS) WaitUntilTasksNotPending(input *ecs.DescribeTasksInput) error {
waiterCfg := awswaiter.Config{
Operation: "DescribeTasks",
Delay: 6,
MaxAttempts: 100,
Acceptors: []awswaiter.WaitAcceptor{
{
State: "failure",
Matcher: "pathAny",
Argument: "failures[].reason",
Expected: "MISSING",
},
{
State: "success",
Matcher: "pathAll",
Argument: "tasks[].lastStatus",
Expected: "RUNNING",
},
{
State: "success",
Matcher: "pathAll",
Argument: "tasks[].lastStatus",
Expected: "STOPPED",
},
},
}
w := awswaiter.Waiter{
Client: c.ECS,
Input: input,
Config: waiterCfg,
}
return w.Wait()
}
|
go
|
func (c *ECS) WaitUntilTasksNotPending(input *ecs.DescribeTasksInput) error {
waiterCfg := awswaiter.Config{
Operation: "DescribeTasks",
Delay: 6,
MaxAttempts: 100,
Acceptors: []awswaiter.WaitAcceptor{
{
State: "failure",
Matcher: "pathAny",
Argument: "failures[].reason",
Expected: "MISSING",
},
{
State: "success",
Matcher: "pathAll",
Argument: "tasks[].lastStatus",
Expected: "RUNNING",
},
{
State: "success",
Matcher: "pathAll",
Argument: "tasks[].lastStatus",
Expected: "STOPPED",
},
},
}
w := awswaiter.Waiter{
Client: c.ECS,
Input: input,
Config: waiterCfg,
}
return w.Wait()
}
|
[
"func",
"(",
"c",
"*",
"ECS",
")",
"WaitUntilTasksNotPending",
"(",
"input",
"*",
"ecs",
".",
"DescribeTasksInput",
")",
"error",
"{",
"waiterCfg",
":=",
"awswaiter",
".",
"Config",
"{",
"Operation",
":",
"\"",
"\"",
",",
"Delay",
":",
"6",
",",
"MaxAttempts",
":",
"100",
",",
"Acceptors",
":",
"[",
"]",
"awswaiter",
".",
"WaitAcceptor",
"{",
"{",
"State",
":",
"\"",
"\"",
",",
"Matcher",
":",
"\"",
"\"",
",",
"Argument",
":",
"\"",
"\"",
",",
"Expected",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"State",
":",
"\"",
"\"",
",",
"Matcher",
":",
"\"",
"\"",
",",
"Argument",
":",
"\"",
"\"",
",",
"Expected",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"State",
":",
"\"",
"\"",
",",
"Matcher",
":",
"\"",
"\"",
",",
"Argument",
":",
"\"",
"\"",
",",
"Expected",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"w",
":=",
"awswaiter",
".",
"Waiter",
"{",
"Client",
":",
"c",
".",
"ECS",
",",
"Input",
":",
"input",
",",
"Config",
":",
"waiterCfg",
",",
"}",
"\n",
"return",
"w",
".",
"Wait",
"(",
")",
"\n",
"}"
] |
// WaitUntilTasksNotPending waits until all the given tasks are either RUNNING
// or STOPPED.
|
[
"WaitUntilTasksNotPending",
"waits",
"until",
"all",
"the",
"given",
"tasks",
"are",
"either",
"RUNNING",
"or",
"STOPPED",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/clients.go#L71-L104
|
train
|
remind101/empire
|
pkg/heroku/oauth_token.go
|
OAuthTokenCreate
|
func (c *Client) OAuthTokenCreate(grant OAuthTokenCreateGrant, client OAuthTokenCreateClient, refreshToken OAuthTokenCreateRefreshToken) (*OAuthToken, error) {
params := struct {
Grant OAuthTokenCreateGrant `json:"grant"`
Client OAuthTokenCreateClient `json:"client"`
RefreshToken OAuthTokenCreateRefreshToken `json:"refresh_token"`
}{
Grant: grant,
Client: client,
RefreshToken: refreshToken,
}
var oauthTokenRes OAuthToken
return &oauthTokenRes, c.Post(&oauthTokenRes, "/oauth/tokens", params)
}
|
go
|
func (c *Client) OAuthTokenCreate(grant OAuthTokenCreateGrant, client OAuthTokenCreateClient, refreshToken OAuthTokenCreateRefreshToken) (*OAuthToken, error) {
params := struct {
Grant OAuthTokenCreateGrant `json:"grant"`
Client OAuthTokenCreateClient `json:"client"`
RefreshToken OAuthTokenCreateRefreshToken `json:"refresh_token"`
}{
Grant: grant,
Client: client,
RefreshToken: refreshToken,
}
var oauthTokenRes OAuthToken
return &oauthTokenRes, c.Post(&oauthTokenRes, "/oauth/tokens", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthTokenCreate",
"(",
"grant",
"OAuthTokenCreateGrant",
",",
"client",
"OAuthTokenCreateClient",
",",
"refreshToken",
"OAuthTokenCreateRefreshToken",
")",
"(",
"*",
"OAuthToken",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Grant",
"OAuthTokenCreateGrant",
"`json:\"grant\"`",
"\n",
"Client",
"OAuthTokenCreateClient",
"`json:\"client\"`",
"\n",
"RefreshToken",
"OAuthTokenCreateRefreshToken",
"`json:\"refresh_token\"`",
"\n",
"}",
"{",
"Grant",
":",
"grant",
",",
"Client",
":",
"client",
",",
"RefreshToken",
":",
"refreshToken",
",",
"}",
"\n",
"var",
"oauthTokenRes",
"OAuthToken",
"\n",
"return",
"&",
"oauthTokenRes",
",",
"c",
".",
"Post",
"(",
"&",
"oauthTokenRes",
",",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new OAuth token.
//
// grant is the grant used on the underlying authorization. client is the OAuth
// client secret used to obtain token. refreshToken is the refresh token for
// this authorization.
|
[
"Create",
"a",
"new",
"OAuth",
"token",
".",
"grant",
"is",
"the",
"grant",
"used",
"on",
"the",
"underlying",
"authorization",
".",
"client",
"is",
"the",
"OAuth",
"client",
"secret",
"used",
"to",
"obtain",
"token",
".",
"refreshToken",
"is",
"the",
"refresh",
"token",
"for",
"this",
"authorization",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/oauth_token.go#L70-L82
|
train
|
remind101/empire
|
pkg/heroku/app_feature.go
|
AppFeatureInfo
|
func (c *Client) AppFeatureInfo(appIdentity string, appFeatureIdentity string) (*AppFeature, error) {
var appFeature AppFeature
return &appFeature, c.Get(&appFeature, "/apps/"+appIdentity+"/features/"+appFeatureIdentity)
}
|
go
|
func (c *Client) AppFeatureInfo(appIdentity string, appFeatureIdentity string) (*AppFeature, error) {
var appFeature AppFeature
return &appFeature, c.Get(&appFeature, "/apps/"+appIdentity+"/features/"+appFeatureIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppFeatureInfo",
"(",
"appIdentity",
"string",
",",
"appFeatureIdentity",
"string",
")",
"(",
"*",
"AppFeature",
",",
"error",
")",
"{",
"var",
"appFeature",
"AppFeature",
"\n",
"return",
"&",
"appFeature",
",",
"c",
".",
"Get",
"(",
"&",
"appFeature",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"appFeatureIdentity",
")",
"\n",
"}"
] |
// Info for an existing app feature.
//
// appIdentity is the unique identifier of the AppFeature's App.
// appFeatureIdentity is the unique identifier of the AppFeature.
|
[
"Info",
"for",
"an",
"existing",
"app",
"feature",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AppFeature",
"s",
"App",
".",
"appFeatureIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AppFeature",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app_feature.go#L43-L46
|
train
|
remind101/empire
|
pkg/heroku/app_feature.go
|
AppFeatureList
|
func (c *Client) AppFeatureList(appIdentity string, lr *ListRange) ([]AppFeature, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/features", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var appFeaturesRes []AppFeature
return appFeaturesRes, c.DoReq(req, &appFeaturesRes)
}
|
go
|
func (c *Client) AppFeatureList(appIdentity string, lr *ListRange) ([]AppFeature, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/features", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var appFeaturesRes []AppFeature
return appFeaturesRes, c.DoReq(req, &appFeaturesRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppFeatureList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"AppFeature",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"appFeaturesRes",
"[",
"]",
"AppFeature",
"\n",
"return",
"appFeaturesRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"appFeaturesRes",
")",
"\n",
"}"
] |
// List existing app features.
//
// appIdentity is the unique identifier of the AppFeature's App. lr is an
// optional ListRange that sets the Range options for the paginated list of
// results.
|
[
"List",
"existing",
"app",
"features",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AppFeature",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app_feature.go#L53-L65
|
train
|
remind101/empire
|
pkg/heroku/app_feature.go
|
AppFeatureUpdate
|
func (c *Client) AppFeatureUpdate(appIdentity string, appFeatureIdentity string, enabled bool) (*AppFeature, error) {
params := struct {
Enabled bool `json:"enabled"`
}{
Enabled: enabled,
}
var appFeatureRes AppFeature
return &appFeatureRes, c.Patch(&appFeatureRes, "/apps/"+appIdentity+"/features/"+appFeatureIdentity, params)
}
|
go
|
func (c *Client) AppFeatureUpdate(appIdentity string, appFeatureIdentity string, enabled bool) (*AppFeature, error) {
params := struct {
Enabled bool `json:"enabled"`
}{
Enabled: enabled,
}
var appFeatureRes AppFeature
return &appFeatureRes, c.Patch(&appFeatureRes, "/apps/"+appIdentity+"/features/"+appFeatureIdentity, params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppFeatureUpdate",
"(",
"appIdentity",
"string",
",",
"appFeatureIdentity",
"string",
",",
"enabled",
"bool",
")",
"(",
"*",
"AppFeature",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Enabled",
"bool",
"`json:\"enabled\"`",
"\n",
"}",
"{",
"Enabled",
":",
"enabled",
",",
"}",
"\n",
"var",
"appFeatureRes",
"AppFeature",
"\n",
"return",
"&",
"appFeatureRes",
",",
"c",
".",
"Patch",
"(",
"&",
"appFeatureRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"appFeatureIdentity",
",",
"params",
")",
"\n",
"}"
] |
// Update an existing app feature.
//
// appIdentity is the unique identifier of the AppFeature's App.
// appFeatureIdentity is the unique identifier of the AppFeature. enabled is the
// whether or not app feature has been enabled.
|
[
"Update",
"an",
"existing",
"app",
"feature",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AppFeature",
"s",
"App",
".",
"appFeatureIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AppFeature",
".",
"enabled",
"is",
"the",
"whether",
"or",
"not",
"app",
"feature",
"has",
"been",
"enabled",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app_feature.go#L72-L80
|
train
|
remind101/empire
|
server/middleware/request.go
|
WithRequest
|
func WithRequest(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = httpx.WithRequest(ctx, r)
// Add the request to the context.
reporter.AddRequest(ctx, r)
// Add the request id
reporter.AddContext(ctx, "request_id", httpx.RequestID(ctx))
h.ServeHTTP(w, r.WithContext(ctx))
})
}
|
go
|
func WithRequest(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = httpx.WithRequest(ctx, r)
// Add the request to the context.
reporter.AddRequest(ctx, r)
// Add the request id
reporter.AddContext(ctx, "request_id", httpx.RequestID(ctx))
h.ServeHTTP(w, r.WithContext(ctx))
})
}
|
[
"func",
"WithRequest",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n\n",
"ctx",
"=",
"httpx",
".",
"WithRequest",
"(",
"ctx",
",",
"r",
")",
"\n\n",
"// Add the request to the context.",
"reporter",
".",
"AddRequest",
"(",
"ctx",
",",
"r",
")",
"\n\n",
"// Add the request id",
"reporter",
".",
"AddContext",
"(",
"ctx",
",",
"\"",
"\"",
",",
"httpx",
".",
"RequestID",
"(",
"ctx",
")",
")",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// WithRequest adds information about the http.Request to reported errors.
|
[
"WithRequest",
"adds",
"information",
"about",
"the",
"http",
".",
"Request",
"to",
"reported",
"errors",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/middleware/request.go#L11-L25
|
train
|
remind101/empire
|
pkg/troposphere/troposphere.go
|
NewTemplate
|
func NewTemplate() *Template {
return &Template{
Conditions: make(map[string]interface{}),
Outputs: make(map[string]Output),
Parameters: make(map[string]Parameter),
Resources: make(map[string]Resource),
}
}
|
go
|
func NewTemplate() *Template {
return &Template{
Conditions: make(map[string]interface{}),
Outputs: make(map[string]Output),
Parameters: make(map[string]Parameter),
Resources: make(map[string]Resource),
}
}
|
[
"func",
"NewTemplate",
"(",
")",
"*",
"Template",
"{",
"return",
"&",
"Template",
"{",
"Conditions",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
",",
"Outputs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Output",
")",
",",
"Parameters",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Parameter",
")",
",",
"Resources",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Resource",
")",
",",
"}",
"\n",
"}"
] |
// NewTemplate returns an initialized Template.
|
[
"NewTemplate",
"returns",
"an",
"initialized",
"Template",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/troposphere/troposphere.go#L16-L23
|
train
|
remind101/empire
|
pkg/troposphere/troposphere.go
|
AddResource
|
func (t *Template) AddResource(resource NamedResource) {
if _, ok := t.Resources[resource.Name]; ok {
panic(fmt.Sprintf("%s is already defined in the template", resource.Name))
}
t.Resources[resource.Name] = resource.Resource
}
|
go
|
func (t *Template) AddResource(resource NamedResource) {
if _, ok := t.Resources[resource.Name]; ok {
panic(fmt.Sprintf("%s is already defined in the template", resource.Name))
}
t.Resources[resource.Name] = resource.Resource
}
|
[
"func",
"(",
"t",
"*",
"Template",
")",
"AddResource",
"(",
"resource",
"NamedResource",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"t",
".",
"Resources",
"[",
"resource",
".",
"Name",
"]",
";",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"resource",
".",
"Name",
")",
")",
"\n",
"}",
"\n",
"t",
".",
"Resources",
"[",
"resource",
".",
"Name",
"]",
"=",
"resource",
".",
"Resource",
"\n",
"}"
] |
// AddResource adds a named resource to the template.
|
[
"AddResource",
"adds",
"a",
"named",
"resource",
"to",
"the",
"template",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/troposphere/troposphere.go#L26-L31
|
train
|
remind101/empire
|
pkg/arn/arn.go
|
Parse
|
func Parse(arn string) (*ARN, error) {
p := strings.SplitN(arn, delimiter, 6)
// Ensure that we have all the components that make up an ARN.
if len(p) < 6 {
return nil, ErrInvalidARN
}
a := &ARN{
ARN: p[0],
AWS: p[1],
Service: p[2],
Region: p[3],
Account: p[4],
Resource: p[5],
}
// ARN's always start with "arn:aws" (hopefully).
if a.ARN != "arn" || a.AWS != "aws" {
return nil, ErrInvalidARN
}
return a, nil
}
|
go
|
func Parse(arn string) (*ARN, error) {
p := strings.SplitN(arn, delimiter, 6)
// Ensure that we have all the components that make up an ARN.
if len(p) < 6 {
return nil, ErrInvalidARN
}
a := &ARN{
ARN: p[0],
AWS: p[1],
Service: p[2],
Region: p[3],
Account: p[4],
Resource: p[5],
}
// ARN's always start with "arn:aws" (hopefully).
if a.ARN != "arn" || a.AWS != "aws" {
return nil, ErrInvalidARN
}
return a, nil
}
|
[
"func",
"Parse",
"(",
"arn",
"string",
")",
"(",
"*",
"ARN",
",",
"error",
")",
"{",
"p",
":=",
"strings",
".",
"SplitN",
"(",
"arn",
",",
"delimiter",
",",
"6",
")",
"\n\n",
"// Ensure that we have all the components that make up an ARN.",
"if",
"len",
"(",
"p",
")",
"<",
"6",
"{",
"return",
"nil",
",",
"ErrInvalidARN",
"\n",
"}",
"\n\n",
"a",
":=",
"&",
"ARN",
"{",
"ARN",
":",
"p",
"[",
"0",
"]",
",",
"AWS",
":",
"p",
"[",
"1",
"]",
",",
"Service",
":",
"p",
"[",
"2",
"]",
",",
"Region",
":",
"p",
"[",
"3",
"]",
",",
"Account",
":",
"p",
"[",
"4",
"]",
",",
"Resource",
":",
"p",
"[",
"5",
"]",
",",
"}",
"\n\n",
"// ARN's always start with \"arn:aws\" (hopefully).",
"if",
"a",
".",
"ARN",
"!=",
"\"",
"\"",
"||",
"a",
".",
"AWS",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"ErrInvalidARN",
"\n",
"}",
"\n\n",
"return",
"a",
",",
"nil",
"\n",
"}"
] |
// Parse parses an Amazon Resource Name from a String into an ARN.
|
[
"Parse",
"parses",
"an",
"Amazon",
"Resource",
"Name",
"from",
"a",
"String",
"into",
"an",
"ARN",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/arn/arn.go#L30-L53
|
train
|
remind101/empire
|
pkg/arn/arn.go
|
String
|
func (a *ARN) String() string {
return strings.Join(
[]string{a.ARN, a.AWS, a.Service, a.Region, a.Account, a.Resource},
delimiter,
)
}
|
go
|
func (a *ARN) String() string {
return strings.Join(
[]string{a.ARN, a.AWS, a.Service, a.Region, a.Account, a.Resource},
delimiter,
)
}
|
[
"func",
"(",
"a",
"*",
"ARN",
")",
"String",
"(",
")",
"string",
"{",
"return",
"strings",
".",
"Join",
"(",
"[",
"]",
"string",
"{",
"a",
".",
"ARN",
",",
"a",
".",
"AWS",
",",
"a",
".",
"Service",
",",
"a",
".",
"Region",
",",
"a",
".",
"Account",
",",
"a",
".",
"Resource",
"}",
",",
"delimiter",
",",
")",
"\n",
"}"
] |
// String returns the string representation of an Amazon Resource Name.
|
[
"String",
"returns",
"the",
"string",
"representation",
"of",
"an",
"Amazon",
"Resource",
"Name",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/arn/arn.go#L56-L61
|
train
|
remind101/empire
|
pkg/arn/arn.go
|
SplitResource
|
func SplitResource(r string) (resource, id string, err error) {
p := strings.Split(r, "/")
if len(p) != 2 {
err = ErrInvalidResource
return
}
resource = p[0]
id = p[1]
return
}
|
go
|
func SplitResource(r string) (resource, id string, err error) {
p := strings.Split(r, "/")
if len(p) != 2 {
err = ErrInvalidResource
return
}
resource = p[0]
id = p[1]
return
}
|
[
"func",
"SplitResource",
"(",
"r",
"string",
")",
"(",
"resource",
",",
"id",
"string",
",",
"err",
"error",
")",
"{",
"p",
":=",
"strings",
".",
"Split",
"(",
"r",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"p",
")",
"!=",
"2",
"{",
"err",
"=",
"ErrInvalidResource",
"\n",
"return",
"\n",
"}",
"\n\n",
"resource",
"=",
"p",
"[",
"0",
"]",
"\n",
"id",
"=",
"p",
"[",
"1",
"]",
"\n\n",
"return",
"\n",
"}"
] |
// SplitResource splits the Resource section of an ARN into its type and id
// components.
|
[
"SplitResource",
"splits",
"the",
"Resource",
"section",
"of",
"an",
"ARN",
"into",
"its",
"type",
"and",
"id",
"components",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/arn/arn.go#L65-L77
|
train
|
remind101/empire
|
pkg/arn/arn.go
|
ResourceID
|
func ResourceID(arn string) (string, error) {
a, err := Parse(arn)
if err != nil {
return "", err
}
_, id, err := SplitResource(a.Resource)
return id, err
}
|
go
|
func ResourceID(arn string) (string, error) {
a, err := Parse(arn)
if err != nil {
return "", err
}
_, id, err := SplitResource(a.Resource)
return id, err
}
|
[
"func",
"ResourceID",
"(",
"arn",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"a",
",",
"err",
":=",
"Parse",
"(",
"arn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"id",
",",
"err",
":=",
"SplitResource",
"(",
"a",
".",
"Resource",
")",
"\n",
"return",
"id",
",",
"err",
"\n",
"}"
] |
// ResourceID takes an ARN string and returns the resource ID from it.
|
[
"ResourceID",
"takes",
"an",
"ARN",
"string",
"and",
"returns",
"the",
"resource",
"ID",
"from",
"it",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/arn/arn.go#L80-L88
|
train
|
remind101/empire
|
server/middleware/middleware.go
|
LogRequests
|
func LogRequests(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
logger.Info(ctx, "request.start",
"method", r.Method,
"path", r.URL.Path,
"user_agent", r.Header.Get("User-Agent"),
"remote_ip", realip.RealIP(r),
)
h.ServeHTTP(w, r)
logger.Info(ctx, "request.complete")
})
}
|
go
|
func LogRequests(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
logger.Info(ctx, "request.start",
"method", r.Method,
"path", r.URL.Path,
"user_agent", r.Header.Get("User-Agent"),
"remote_ip", realip.RealIP(r),
)
h.ServeHTTP(w, r)
logger.Info(ctx, "request.complete")
})
}
|
[
"func",
"LogRequests",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"logger",
".",
"Info",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"r",
".",
"Method",
",",
"\"",
"\"",
",",
"r",
".",
"URL",
".",
"Path",
",",
"\"",
"\"",
",",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"realip",
".",
"RealIP",
"(",
"r",
")",
",",
")",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n\n",
"logger",
".",
"Info",
"(",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// LogRequests logs the requests to the embedded logger.
|
[
"LogRequests",
"logs",
"the",
"requests",
"to",
"the",
"embedded",
"logger",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/middleware/middleware.go#L32-L46
|
train
|
remind101/empire
|
server/middleware/middleware.go
|
PrefixRequestID
|
func PrefixRequestID(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if l, ok := logger.FromContext(ctx); ok {
if l, ok := l.(log15.Logger); ok {
ctx = logger.WithLogger(ctx, l.New("request_id", httpx.RequestID(ctx)))
}
}
h.ServeHTTP(w, r.WithContext(ctx))
})
}
|
go
|
func PrefixRequestID(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if l, ok := logger.FromContext(ctx); ok {
if l, ok := l.(log15.Logger); ok {
ctx = logger.WithLogger(ctx, l.New("request_id", httpx.RequestID(ctx)))
}
}
h.ServeHTTP(w, r.WithContext(ctx))
})
}
|
[
"func",
"PrefixRequestID",
"(",
"h",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n\n",
"if",
"l",
",",
"ok",
":=",
"logger",
".",
"FromContext",
"(",
"ctx",
")",
";",
"ok",
"{",
"if",
"l",
",",
"ok",
":=",
"l",
".",
"(",
"log15",
".",
"Logger",
")",
";",
"ok",
"{",
"ctx",
"=",
"logger",
".",
"WithLogger",
"(",
"ctx",
",",
"l",
".",
"New",
"(",
"\"",
"\"",
",",
"httpx",
".",
"RequestID",
"(",
"ctx",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
".",
"WithContext",
"(",
"ctx",
")",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// PrefixRequestID adds the request as a prefix to the log15.Logger.
|
[
"PrefixRequestID",
"adds",
"the",
"request",
"as",
"a",
"prefix",
"to",
"the",
"log15",
".",
"Logger",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/middleware/middleware.go#L49-L61
|
train
|
remind101/empire
|
stats/dogstatsd.go
|
NewDogstatsd
|
func NewDogstatsd(addr string) (*Dogstatsd, error) {
c, err := statsd.New(addr)
if err != nil {
return nil, err
}
return &Dogstatsd{
Client: c,
}, nil
}
|
go
|
func NewDogstatsd(addr string) (*Dogstatsd, error) {
c, err := statsd.New(addr)
if err != nil {
return nil, err
}
return &Dogstatsd{
Client: c,
}, nil
}
|
[
"func",
"NewDogstatsd",
"(",
"addr",
"string",
")",
"(",
"*",
"Dogstatsd",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"statsd",
".",
"New",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"Dogstatsd",
"{",
"Client",
":",
"c",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewDogstatsd returns a new Dogstatsd instance that sends statsd metrics to addr.
|
[
"NewDogstatsd",
"returns",
"a",
"new",
"Dogstatsd",
"instance",
"that",
"sends",
"statsd",
"metrics",
"to",
"addr",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/dogstatsd.go#L16-L25
|
train
|
remind101/empire
|
pkg/heroku/collaborator.go
|
CollaboratorCreate
|
func (c *Client) CollaboratorCreate(appIdentity string, user string, options *CollaboratorCreateOpts) (*Collaborator, error) {
params := struct {
User string `json:"user"`
Silent *bool `json:"silent,omitempty"`
}{
User: user,
}
if options != nil {
params.Silent = options.Silent
}
var collaboratorRes Collaborator
return &collaboratorRes, c.Post(&collaboratorRes, "/apps/"+appIdentity+"/collaborators", params)
}
|
go
|
func (c *Client) CollaboratorCreate(appIdentity string, user string, options *CollaboratorCreateOpts) (*Collaborator, error) {
params := struct {
User string `json:"user"`
Silent *bool `json:"silent,omitempty"`
}{
User: user,
}
if options != nil {
params.Silent = options.Silent
}
var collaboratorRes Collaborator
return &collaboratorRes, c.Post(&collaboratorRes, "/apps/"+appIdentity+"/collaborators", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CollaboratorCreate",
"(",
"appIdentity",
"string",
",",
"user",
"string",
",",
"options",
"*",
"CollaboratorCreateOpts",
")",
"(",
"*",
"Collaborator",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"User",
"string",
"`json:\"user\"`",
"\n",
"Silent",
"*",
"bool",
"`json:\"silent,omitempty\"`",
"\n",
"}",
"{",
"User",
":",
"user",
",",
"}",
"\n",
"if",
"options",
"!=",
"nil",
"{",
"params",
".",
"Silent",
"=",
"options",
".",
"Silent",
"\n",
"}",
"\n",
"var",
"collaboratorRes",
"Collaborator",
"\n",
"return",
"&",
"collaboratorRes",
",",
"c",
".",
"Post",
"(",
"&",
"collaboratorRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new collaborator.
//
// appIdentity is the unique identifier of the Collaborator's App. user is the
// unique email address of account or unique identifier of an account. options
// is the struct of optional parameters for this action.
|
[
"Create",
"a",
"new",
"collaborator",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Collaborator",
"s",
"App",
".",
"user",
"is",
"the",
"unique",
"email",
"address",
"of",
"account",
"or",
"unique",
"identifier",
"of",
"an",
"account",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/collaborator.go#L35-L47
|
train
|
remind101/empire
|
pkg/heroku/collaborator.go
|
CollaboratorDelete
|
func (c *Client) CollaboratorDelete(appIdentity string, collaboratorIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/collaborators/" + collaboratorIdentity)
}
|
go
|
func (c *Client) CollaboratorDelete(appIdentity string, collaboratorIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/collaborators/" + collaboratorIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CollaboratorDelete",
"(",
"appIdentity",
"string",
",",
"collaboratorIdentity",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Delete",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"collaboratorIdentity",
")",
"\n",
"}"
] |
// Delete an existing collaborator.
//
// appIdentity is the unique identifier of the Collaborator's App.
// collaboratorIdentity is the unique identifier of the Collaborator.
|
[
"Delete",
"an",
"existing",
"collaborator",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Collaborator",
"s",
"App",
".",
"collaboratorIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Collaborator",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/collaborator.go#L59-L61
|
train
|
remind101/empire
|
pkg/heroku/collaborator.go
|
CollaboratorInfo
|
func (c *Client) CollaboratorInfo(appIdentity string, collaboratorIdentity string) (*Collaborator, error) {
var collaborator Collaborator
return &collaborator, c.Get(&collaborator, "/apps/"+appIdentity+"/collaborators/"+collaboratorIdentity)
}
|
go
|
func (c *Client) CollaboratorInfo(appIdentity string, collaboratorIdentity string) (*Collaborator, error) {
var collaborator Collaborator
return &collaborator, c.Get(&collaborator, "/apps/"+appIdentity+"/collaborators/"+collaboratorIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CollaboratorInfo",
"(",
"appIdentity",
"string",
",",
"collaboratorIdentity",
"string",
")",
"(",
"*",
"Collaborator",
",",
"error",
")",
"{",
"var",
"collaborator",
"Collaborator",
"\n",
"return",
"&",
"collaborator",
",",
"c",
".",
"Get",
"(",
"&",
"collaborator",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"collaboratorIdentity",
")",
"\n",
"}"
] |
// Info for existing collaborator.
//
// appIdentity is the unique identifier of the Collaborator's App.
// collaboratorIdentity is the unique identifier of the Collaborator.
|
[
"Info",
"for",
"existing",
"collaborator",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Collaborator",
"s",
"App",
".",
"collaboratorIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Collaborator",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/collaborator.go#L67-L70
|
train
|
remind101/empire
|
pkg/heroku/collaborator.go
|
CollaboratorList
|
func (c *Client) CollaboratorList(appIdentity string, lr *ListRange) ([]Collaborator, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/collaborators", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var collaboratorsRes []Collaborator
return collaboratorsRes, c.DoReq(req, &collaboratorsRes)
}
|
go
|
func (c *Client) CollaboratorList(appIdentity string, lr *ListRange) ([]Collaborator, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/collaborators", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var collaboratorsRes []Collaborator
return collaboratorsRes, c.DoReq(req, &collaboratorsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"CollaboratorList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Collaborator",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"collaboratorsRes",
"[",
"]",
"Collaborator",
"\n",
"return",
"collaboratorsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"collaboratorsRes",
")",
"\n",
"}"
] |
// List existing collaborators.
//
// appIdentity is the unique identifier of the Collaborator's App. lr is an
// optional ListRange that sets the Range options for the paginated list of
// results.
|
[
"List",
"existing",
"collaborators",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Collaborator",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/collaborator.go#L77-L89
|
train
|
remind101/empire
|
pkg/heroku/slug.go
|
SlugInfo
|
func (c *Client) SlugInfo(appIdentity string, slugIdentity string) (*Slug, error) {
var slug Slug
return &slug, c.Get(&slug, "/apps/"+appIdentity+"/slugs/"+slugIdentity)
}
|
go
|
func (c *Client) SlugInfo(appIdentity string, slugIdentity string) (*Slug, error) {
var slug Slug
return &slug, c.Get(&slug, "/apps/"+appIdentity+"/slugs/"+slugIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SlugInfo",
"(",
"appIdentity",
"string",
",",
"slugIdentity",
"string",
")",
"(",
"*",
"Slug",
",",
"error",
")",
"{",
"var",
"slug",
"Slug",
"\n",
"return",
"&",
"slug",
",",
"c",
".",
"Get",
"(",
"&",
"slug",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"slugIdentity",
")",
"\n",
"}"
] |
// Info for existing slug.
//
// appIdentity is the unique identifier of the Slug's App. slugIdentity is the
// unique identifier of the Slug.
|
[
"Info",
"for",
"existing",
"slug",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Slug",
"s",
"App",
".",
"slugIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Slug",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/slug.go#L46-L49
|
train
|
remind101/empire
|
pkg/heroku/slug.go
|
SlugCreate
|
func (c *Client) SlugCreate(appIdentity string, processTypes map[string]string, options *SlugCreateOpts) (*Slug, error) {
params := struct {
ProcessTypes map[string]string `json:"process_types"`
BuildpackProvidedDescription *string `json:"buildpack_provided_description,omitempty"`
Commit *string `json:"commit,omitempty"`
}{
ProcessTypes: processTypes,
}
if options != nil {
params.BuildpackProvidedDescription = options.BuildpackProvidedDescription
params.Commit = options.Commit
}
var slugRes Slug
return &slugRes, c.Post(&slugRes, "/apps/"+appIdentity+"/slugs", params)
}
|
go
|
func (c *Client) SlugCreate(appIdentity string, processTypes map[string]string, options *SlugCreateOpts) (*Slug, error) {
params := struct {
ProcessTypes map[string]string `json:"process_types"`
BuildpackProvidedDescription *string `json:"buildpack_provided_description,omitempty"`
Commit *string `json:"commit,omitempty"`
}{
ProcessTypes: processTypes,
}
if options != nil {
params.BuildpackProvidedDescription = options.BuildpackProvidedDescription
params.Commit = options.Commit
}
var slugRes Slug
return &slugRes, c.Post(&slugRes, "/apps/"+appIdentity+"/slugs", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"SlugCreate",
"(",
"appIdentity",
"string",
",",
"processTypes",
"map",
"[",
"string",
"]",
"string",
",",
"options",
"*",
"SlugCreateOpts",
")",
"(",
"*",
"Slug",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"ProcessTypes",
"map",
"[",
"string",
"]",
"string",
"`json:\"process_types\"`",
"\n",
"BuildpackProvidedDescription",
"*",
"string",
"`json:\"buildpack_provided_description,omitempty\"`",
"\n",
"Commit",
"*",
"string",
"`json:\"commit,omitempty\"`",
"\n",
"}",
"{",
"ProcessTypes",
":",
"processTypes",
",",
"}",
"\n",
"if",
"options",
"!=",
"nil",
"{",
"params",
".",
"BuildpackProvidedDescription",
"=",
"options",
".",
"BuildpackProvidedDescription",
"\n",
"params",
".",
"Commit",
"=",
"options",
".",
"Commit",
"\n",
"}",
"\n",
"var",
"slugRes",
"Slug",
"\n",
"return",
"&",
"slugRes",
",",
"c",
".",
"Post",
"(",
"&",
"slugRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new slug. For more information please refer to Deploying Slugs using
// the Platform API.
//
// appIdentity is the unique identifier of the Slug's App. processTypes is the
// hash mapping process type names to their respective command. options is the
// struct of optional parameters for this action.
|
[
"Create",
"a",
"new",
"slug",
".",
"For",
"more",
"information",
"please",
"refer",
"to",
"Deploying",
"Slugs",
"using",
"the",
"Platform",
"API",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Slug",
"s",
"App",
".",
"processTypes",
"is",
"the",
"hash",
"mapping",
"process",
"type",
"names",
"to",
"their",
"respective",
"command",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/slug.go#L57-L71
|
train
|
remind101/empire
|
pkg/dockerutil/client.go
|
NewDockerClient
|
func NewDockerClient(host, certPath string) (*docker.Client, error) {
if certPath != "" {
cert := certPath + "/cert.pem"
key := certPath + "/key.pem"
ca := certPath + "/ca.pem"
return docker.NewTLSClient(host, cert, key, ca)
}
return docker.NewClient(host)
}
|
go
|
func NewDockerClient(host, certPath string) (*docker.Client, error) {
if certPath != "" {
cert := certPath + "/cert.pem"
key := certPath + "/key.pem"
ca := certPath + "/ca.pem"
return docker.NewTLSClient(host, cert, key, ca)
}
return docker.NewClient(host)
}
|
[
"func",
"NewDockerClient",
"(",
"host",
",",
"certPath",
"string",
")",
"(",
"*",
"docker",
".",
"Client",
",",
"error",
")",
"{",
"if",
"certPath",
"!=",
"\"",
"\"",
"{",
"cert",
":=",
"certPath",
"+",
"\"",
"\"",
"\n",
"key",
":=",
"certPath",
"+",
"\"",
"\"",
"\n",
"ca",
":=",
"certPath",
"+",
"\"",
"\"",
"\n",
"return",
"docker",
".",
"NewTLSClient",
"(",
"host",
",",
"cert",
",",
"key",
",",
"ca",
")",
"\n",
"}",
"\n\n",
"return",
"docker",
".",
"NewClient",
"(",
"host",
")",
"\n",
"}"
] |
// NewDockerClient returns a new docker.Client using the given host and certificate path.
|
[
"NewDockerClient",
"returns",
"a",
"new",
"docker",
".",
"Client",
"using",
"the",
"given",
"host",
"and",
"certificate",
"path",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/client.go#L17-L26
|
train
|
remind101/empire
|
pkg/dockerutil/client.go
|
NewClient
|
func NewClient(authProvider dockerauth.AuthProvider, host, certPath string) (*Client, error) {
c, err := NewDockerClient(host, certPath)
if err != nil {
return nil, err
}
return newClient(authProvider, c)
}
|
go
|
func NewClient(authProvider dockerauth.AuthProvider, host, certPath string) (*Client, error) {
c, err := NewDockerClient(host, certPath)
if err != nil {
return nil, err
}
return newClient(authProvider, c)
}
|
[
"func",
"NewClient",
"(",
"authProvider",
"dockerauth",
".",
"AuthProvider",
",",
"host",
",",
"certPath",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"NewDockerClient",
"(",
"host",
",",
"certPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newClient",
"(",
"authProvider",
",",
"c",
")",
"\n",
"}"
] |
// NewClient returns a new Client instance.
|
[
"NewClient",
"returns",
"a",
"new",
"Client",
"instance",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/client.go#L40-L46
|
train
|
remind101/empire
|
pkg/dockerutil/client.go
|
PullImage
|
func (c *Client) PullImage(ctx context.Context, opts docker.PullImageOptions) error {
// This is to workaround an issue in the Docker API, where it doesn't
// respect the registry param. We have to put the registry in the
// repository field.
if opts.Registry != "" {
opts.Repository = fmt.Sprintf("%s/%s", opts.Registry, opts.Repository)
}
authConf, err := authConfiguration(c.AuthProvider, opts.Registry)
if err != nil {
return err
}
return c.Client.PullImage(opts, authConf)
}
|
go
|
func (c *Client) PullImage(ctx context.Context, opts docker.PullImageOptions) error {
// This is to workaround an issue in the Docker API, where it doesn't
// respect the registry param. We have to put the registry in the
// repository field.
if opts.Registry != "" {
opts.Repository = fmt.Sprintf("%s/%s", opts.Registry, opts.Repository)
}
authConf, err := authConfiguration(c.AuthProvider, opts.Registry)
if err != nil {
return err
}
return c.Client.PullImage(opts, authConf)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"PullImage",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"docker",
".",
"PullImageOptions",
")",
"error",
"{",
"// This is to workaround an issue in the Docker API, where it doesn't",
"// respect the registry param. We have to put the registry in the",
"// repository field.",
"if",
"opts",
".",
"Registry",
"!=",
"\"",
"\"",
"{",
"opts",
".",
"Repository",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"Registry",
",",
"opts",
".",
"Repository",
")",
"\n",
"}",
"\n\n",
"authConf",
",",
"err",
":=",
"authConfiguration",
"(",
"c",
".",
"AuthProvider",
",",
"opts",
".",
"Registry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"Client",
".",
"PullImage",
"(",
"opts",
",",
"authConf",
")",
"\n",
"}"
] |
// PullImage wraps the docker clients PullImage to handle authentication.
|
[
"PullImage",
"wraps",
"the",
"docker",
"clients",
"PullImage",
"to",
"handle",
"authentication",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/dockerutil/client.go#L71-L85
|
train
|
remind101/empire
|
pkg/heroku/addon_service.go
|
AddonServiceInfo
|
func (c *Client) AddonServiceInfo(addonServiceIdentity string) (*AddonService, error) {
var addonService AddonService
return &addonService, c.Get(&addonService, "/addon-services/"+addonServiceIdentity)
}
|
go
|
func (c *Client) AddonServiceInfo(addonServiceIdentity string) (*AddonService, error) {
var addonService AddonService
return &addonService, c.Get(&addonService, "/addon-services/"+addonServiceIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AddonServiceInfo",
"(",
"addonServiceIdentity",
"string",
")",
"(",
"*",
"AddonService",
",",
"error",
")",
"{",
"var",
"addonService",
"AddonService",
"\n",
"return",
"&",
"addonService",
",",
"c",
".",
"Get",
"(",
"&",
"addonService",
",",
"\"",
"\"",
"+",
"addonServiceIdentity",
")",
"\n",
"}"
] |
// Info for existing addon-service.
//
// addonServiceIdentity is the unique identifier of the AddonService.
|
[
"Info",
"for",
"existing",
"addon",
"-",
"service",
".",
"addonServiceIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"AddonService",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/addon_service.go#L29-L32
|
train
|
remind101/empire
|
pkg/heroku/addon_service.go
|
AddonServiceList
|
func (c *Client) AddonServiceList(lr *ListRange) ([]AddonService, error) {
req, err := c.NewRequest("GET", "/addon-services", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var addonServicesRes []AddonService
return addonServicesRes, c.DoReq(req, &addonServicesRes)
}
|
go
|
func (c *Client) AddonServiceList(lr *ListRange) ([]AddonService, error) {
req, err := c.NewRequest("GET", "/addon-services", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var addonServicesRes []AddonService
return addonServicesRes, c.DoReq(req, &addonServicesRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AddonServiceList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"AddonService",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"addonServicesRes",
"[",
"]",
"AddonService",
"\n",
"return",
"addonServicesRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"addonServicesRes",
")",
"\n",
"}"
] |
// List existing addon-services.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results.
|
[
"List",
"existing",
"addon",
"-",
"services",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/addon_service.go#L38-L50
|
train
|
remind101/empire
|
procfile/procfile.go
|
ParsePort
|
func ParsePort(s string) (p Port, err error) {
if strings.Contains(s, ":") {
return portFromHostContainer(s)
}
var port int
port, err = toPort(s)
if err != nil {
return
}
p.Host = port
p.Container = port
return
}
|
go
|
func ParsePort(s string) (p Port, err error) {
if strings.Contains(s, ":") {
return portFromHostContainer(s)
}
var port int
port, err = toPort(s)
if err != nil {
return
}
p.Host = port
p.Container = port
return
}
|
[
"func",
"ParsePort",
"(",
"s",
"string",
")",
"(",
"p",
"Port",
",",
"err",
"error",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"s",
",",
"\"",
"\"",
")",
"{",
"return",
"portFromHostContainer",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"var",
"port",
"int",
"\n",
"port",
",",
"err",
"=",
"toPort",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"p",
".",
"Host",
"=",
"port",
"\n",
"p",
".",
"Container",
"=",
"port",
"\n",
"return",
"\n",
"}"
] |
// ParsePort parses a string into a Port.
|
[
"ParsePort",
"parses",
"a",
"string",
"into",
"a",
"Port",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/procfile/procfile.go#L51-L64
|
train
|
remind101/empire
|
procfile/procfile.go
|
Parse
|
func Parse(r io.Reader) (Procfile, error) {
raw, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return ParseProcfile(raw)
}
|
go
|
func Parse(r io.Reader) (Procfile, error) {
raw, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return ParseProcfile(raw)
}
|
[
"func",
"Parse",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"Procfile",
",",
"error",
")",
"{",
"raw",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseProcfile",
"(",
"raw",
")",
"\n",
"}"
] |
// Parse parses the Procfile by reading from r.
|
[
"Parse",
"parses",
"the",
"Procfile",
"by",
"reading",
"from",
"r",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/procfile/procfile.go#L139-L146
|
train
|
remind101/empire
|
procfile/procfile.go
|
ParseProcfile
|
func ParseProcfile(b []byte) (Procfile, error) {
p, err := parseStandardProcfile(b)
if err != nil {
p, err = parseExtendedProcfile(b)
}
return p, err
}
|
go
|
func ParseProcfile(b []byte) (Procfile, error) {
p, err := parseStandardProcfile(b)
if err != nil {
p, err = parseExtendedProcfile(b)
}
return p, err
}
|
[
"func",
"ParseProcfile",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"Procfile",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"parseStandardProcfile",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"p",
",",
"err",
"=",
"parseExtendedProcfile",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"p",
",",
"err",
"\n",
"}"
] |
// ParseProcfile takes a byte slice representing a YAML Procfile and parses it
// into a Procfile.
|
[
"ParseProcfile",
"takes",
"a",
"byte",
"slice",
"representing",
"a",
"YAML",
"Procfile",
"and",
"parses",
"it",
"into",
"a",
"Procfile",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/procfile/procfile.go#L150-L156
|
train
|
remind101/empire
|
pkg/heroku/oauth_client.go
|
OAuthClientCreate
|
func (c *Client) OAuthClientCreate(name string, redirectUri string) (*OAuthClient, error) {
params := struct {
Name string `json:"name"`
RedirectUri string `json:"redirect_uri"`
}{
Name: name,
RedirectUri: redirectUri,
}
var oauthClientRes OAuthClient
return &oauthClientRes, c.Post(&oauthClientRes, "/oauth/clients", params)
}
|
go
|
func (c *Client) OAuthClientCreate(name string, redirectUri string) (*OAuthClient, error) {
params := struct {
Name string `json:"name"`
RedirectUri string `json:"redirect_uri"`
}{
Name: name,
RedirectUri: redirectUri,
}
var oauthClientRes OAuthClient
return &oauthClientRes, c.Post(&oauthClientRes, "/oauth/clients", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthClientCreate",
"(",
"name",
"string",
",",
"redirectUri",
"string",
")",
"(",
"*",
"OAuthClient",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"RedirectUri",
"string",
"`json:\"redirect_uri\"`",
"\n",
"}",
"{",
"Name",
":",
"name",
",",
"RedirectUri",
":",
"redirectUri",
",",
"}",
"\n",
"var",
"oauthClientRes",
"OAuthClient",
"\n",
"return",
"&",
"oauthClientRes",
",",
"c",
".",
"Post",
"(",
"&",
"oauthClientRes",
",",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new OAuth client.
//
// name is the OAuth client name. redirectUri is the endpoint for redirection
// after authorization with OAuth client.
|
[
"Create",
"a",
"new",
"OAuth",
"client",
".",
"name",
"is",
"the",
"OAuth",
"client",
"name",
".",
"redirectUri",
"is",
"the",
"endpoint",
"for",
"redirection",
"after",
"authorization",
"with",
"OAuth",
"client",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/oauth_client.go#L41-L51
|
train
|
remind101/empire
|
pkg/heroku/oauth_client.go
|
OAuthClientInfo
|
func (c *Client) OAuthClientInfo(oauthClientIdentity string) (*OAuthClient, error) {
var oauthClient OAuthClient
return &oauthClient, c.Get(&oauthClient, "/oauth/clients/"+oauthClientIdentity)
}
|
go
|
func (c *Client) OAuthClientInfo(oauthClientIdentity string) (*OAuthClient, error) {
var oauthClient OAuthClient
return &oauthClient, c.Get(&oauthClient, "/oauth/clients/"+oauthClientIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthClientInfo",
"(",
"oauthClientIdentity",
"string",
")",
"(",
"*",
"OAuthClient",
",",
"error",
")",
"{",
"var",
"oauthClient",
"OAuthClient",
"\n",
"return",
"&",
"oauthClient",
",",
"c",
".",
"Get",
"(",
"&",
"oauthClient",
",",
"\"",
"\"",
"+",
"oauthClientIdentity",
")",
"\n",
"}"
] |
// Info for an OAuth client
//
// oauthClientIdentity is the unique identifier of the OAuthClient.
|
[
"Info",
"for",
"an",
"OAuth",
"client",
"oauthClientIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OAuthClient",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/oauth_client.go#L63-L66
|
train
|
remind101/empire
|
pkg/heroku/oauth_client.go
|
OAuthClientList
|
func (c *Client) OAuthClientList(lr *ListRange) ([]OAuthClient, error) {
req, err := c.NewRequest("GET", "/oauth/clients", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var oauthClientsRes []OAuthClient
return oauthClientsRes, c.DoReq(req, &oauthClientsRes)
}
|
go
|
func (c *Client) OAuthClientList(lr *ListRange) ([]OAuthClient, error) {
req, err := c.NewRequest("GET", "/oauth/clients", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var oauthClientsRes []OAuthClient
return oauthClientsRes, c.DoReq(req, &oauthClientsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthClientList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"OAuthClient",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"oauthClientsRes",
"[",
"]",
"OAuthClient",
"\n",
"return",
"oauthClientsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"oauthClientsRes",
")",
"\n",
"}"
] |
// List OAuth clients
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results.
|
[
"List",
"OAuth",
"clients",
"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/oauth_client.go#L72-L84
|
train
|
remind101/empire
|
pkg/heroku/oauth_client.go
|
OAuthClientUpdate
|
func (c *Client) OAuthClientUpdate(oauthClientIdentity string, options *OAuthClientUpdateOpts) (*OAuthClient, error) {
var oauthClientRes OAuthClient
return &oauthClientRes, c.Patch(&oauthClientRes, "/oauth/clients/"+oauthClientIdentity, options)
}
|
go
|
func (c *Client) OAuthClientUpdate(oauthClientIdentity string, options *OAuthClientUpdateOpts) (*OAuthClient, error) {
var oauthClientRes OAuthClient
return &oauthClientRes, c.Patch(&oauthClientRes, "/oauth/clients/"+oauthClientIdentity, options)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthClientUpdate",
"(",
"oauthClientIdentity",
"string",
",",
"options",
"*",
"OAuthClientUpdateOpts",
")",
"(",
"*",
"OAuthClient",
",",
"error",
")",
"{",
"var",
"oauthClientRes",
"OAuthClient",
"\n",
"return",
"&",
"oauthClientRes",
",",
"c",
".",
"Patch",
"(",
"&",
"oauthClientRes",
",",
"\"",
"\"",
"+",
"oauthClientIdentity",
",",
"options",
")",
"\n",
"}"
] |
// Update OAuth client
//
// oauthClientIdentity is the unique identifier of the OAuthClient. options is
// the struct of optional parameters for this action.
|
[
"Update",
"OAuth",
"client",
"oauthClientIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OAuthClient",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/oauth_client.go#L90-L93
|
train
|
remind101/empire
|
pkg/heroku/log_session.go
|
LogSessionCreate
|
func (c *Client) LogSessionCreate(appIdentity string, options *LogSessionCreateOpts) (*LogSession, error) {
var logSessionRes LogSession
return &logSessionRes, c.Post(&logSessionRes, "/apps/"+appIdentity+"/log-sessions", options)
}
|
go
|
func (c *Client) LogSessionCreate(appIdentity string, options *LogSessionCreateOpts) (*LogSession, error) {
var logSessionRes LogSession
return &logSessionRes, c.Post(&logSessionRes, "/apps/"+appIdentity+"/log-sessions", options)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"LogSessionCreate",
"(",
"appIdentity",
"string",
",",
"options",
"*",
"LogSessionCreateOpts",
")",
"(",
"*",
"LogSession",
",",
"error",
")",
"{",
"var",
"logSessionRes",
"LogSession",
"\n",
"return",
"&",
"logSessionRes",
",",
"c",
".",
"Post",
"(",
"&",
"logSessionRes",
",",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
",",
"options",
")",
"\n",
"}"
] |
// Create a new log session.
//
// appIdentity is the unique identifier of the LogSession's App. options is the
// struct of optional parameters for this action.
|
[
"Create",
"a",
"new",
"log",
"session",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"LogSession",
"s",
"App",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/log_session.go#L30-L33
|
train
|
remind101/empire
|
server/server.go
|
newDeployer
|
func newDeployer(e *empire.Empire, options Options) github.Deployer {
ed := github.NewEmpireDeployer(e)
ed.ImageBuilder = options.GitHub.Deployments.ImageBuilder
var d github.Deployer = ed
// Enables the Tugboat integration, which will send logs to a Tugboat
// instance.
if url := options.GitHub.Deployments.TugboatURL; url != "" {
d = github.NotifyTugboat(d, url)
}
// Perform the deployment within a go routine so we don't timeout
// githubs webhook requests.
d = github.DeployAsync(d)
return d
}
|
go
|
func newDeployer(e *empire.Empire, options Options) github.Deployer {
ed := github.NewEmpireDeployer(e)
ed.ImageBuilder = options.GitHub.Deployments.ImageBuilder
var d github.Deployer = ed
// Enables the Tugboat integration, which will send logs to a Tugboat
// instance.
if url := options.GitHub.Deployments.TugboatURL; url != "" {
d = github.NotifyTugboat(d, url)
}
// Perform the deployment within a go routine so we don't timeout
// githubs webhook requests.
d = github.DeployAsync(d)
return d
}
|
[
"func",
"newDeployer",
"(",
"e",
"*",
"empire",
".",
"Empire",
",",
"options",
"Options",
")",
"github",
".",
"Deployer",
"{",
"ed",
":=",
"github",
".",
"NewEmpireDeployer",
"(",
"e",
")",
"\n",
"ed",
".",
"ImageBuilder",
"=",
"options",
".",
"GitHub",
".",
"Deployments",
".",
"ImageBuilder",
"\n\n",
"var",
"d",
"github",
".",
"Deployer",
"=",
"ed",
"\n\n",
"// Enables the Tugboat integration, which will send logs to a Tugboat",
"// instance.",
"if",
"url",
":=",
"options",
".",
"GitHub",
".",
"Deployments",
".",
"TugboatURL",
";",
"url",
"!=",
"\"",
"\"",
"{",
"d",
"=",
"github",
".",
"NotifyTugboat",
"(",
"d",
",",
"url",
")",
"\n",
"}",
"\n\n",
"// Perform the deployment within a go routine so we don't timeout",
"// githubs webhook requests.",
"d",
"=",
"github",
".",
"DeployAsync",
"(",
"d",
")",
"\n\n",
"return",
"d",
"\n",
"}"
] |
// newDeployer generates a new github.Deployer implementation for the given
// options.
|
[
"newDeployer",
"generates",
"a",
"new",
"github",
".",
"Deployer",
"implementation",
"for",
"the",
"given",
"options",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/server.go#L132-L149
|
train
|
remind101/empire
|
pkg/heroku/organization_member.go
|
OrganizationMemberCreateOrUpdate
|
func (c *Client) OrganizationMemberCreateOrUpdate(organizationIdentity string, email string, role string) (*OrganizationMember, error) {
params := struct {
Email string `json:"email"`
Role string `json:"role"`
}{
Email: email,
Role: role,
}
var organizationMemberRes OrganizationMember
return &organizationMemberRes, c.Put(&organizationMemberRes, "/organizations/"+organizationIdentity+"/members", params)
}
|
go
|
func (c *Client) OrganizationMemberCreateOrUpdate(organizationIdentity string, email string, role string) (*OrganizationMember, error) {
params := struct {
Email string `json:"email"`
Role string `json:"role"`
}{
Email: email,
Role: role,
}
var organizationMemberRes OrganizationMember
return &organizationMemberRes, c.Put(&organizationMemberRes, "/organizations/"+organizationIdentity+"/members", params)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationMemberCreateOrUpdate",
"(",
"organizationIdentity",
"string",
",",
"email",
"string",
",",
"role",
"string",
")",
"(",
"*",
"OrganizationMember",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Email",
"string",
"`json:\"email\"`",
"\n",
"Role",
"string",
"`json:\"role\"`",
"\n",
"}",
"{",
"Email",
":",
"email",
",",
"Role",
":",
"role",
",",
"}",
"\n",
"var",
"organizationMemberRes",
"OrganizationMember",
"\n",
"return",
"&",
"organizationMemberRes",
",",
"c",
".",
"Put",
"(",
"&",
"organizationMemberRes",
",",
"\"",
"\"",
"+",
"organizationIdentity",
"+",
"\"",
"\"",
",",
"params",
")",
"\n",
"}"
] |
// Create a new organization member, or update their role.
//
// organizationIdentity is the unique identifier of the OrganizationMember's
// Organization. email is the email address of the organization member. role is
// the role in the organization.
|
[
"Create",
"a",
"new",
"organization",
"member",
"or",
"update",
"their",
"role",
".",
"organizationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationMember",
"s",
"Organization",
".",
"email",
"is",
"the",
"email",
"address",
"of",
"the",
"organization",
"member",
".",
"role",
"is",
"the",
"role",
"in",
"the",
"organization",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_member.go#L31-L41
|
train
|
remind101/empire
|
pkg/heroku/organization_member.go
|
OrganizationMemberDelete
|
func (c *Client) OrganizationMemberDelete(organizationIdentity string, organizationMemberIdentity string) error {
return c.Delete("/organizations/" + organizationIdentity + "/members/" + organizationIdentity)
}
|
go
|
func (c *Client) OrganizationMemberDelete(organizationIdentity string, organizationMemberIdentity string) error {
return c.Delete("/organizations/" + organizationIdentity + "/members/" + organizationIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationMemberDelete",
"(",
"organizationIdentity",
"string",
",",
"organizationMemberIdentity",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Delete",
"(",
"\"",
"\"",
"+",
"organizationIdentity",
"+",
"\"",
"\"",
"+",
"organizationIdentity",
")",
"\n",
"}"
] |
// Remove a member from the organization.
//
// organizationIdentity is the unique identifier of the OrganizationMember's
// Organization. organizationMemberIdentity is the unique identifier of the
// OrganizationMember.
|
[
"Remove",
"a",
"member",
"from",
"the",
"organization",
".",
"organizationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationMember",
"s",
"Organization",
".",
"organizationMemberIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationMember",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_member.go#L48-L50
|
train
|
remind101/empire
|
pkg/heroku/organization_member.go
|
OrganizationMemberList
|
func (c *Client) OrganizationMemberList(organizationIdentity string, lr *ListRange) ([]OrganizationMember, error) {
req, err := c.NewRequest("GET", "/organizations/"+organizationIdentity+"/members", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationMembersRes []OrganizationMember
return organizationMembersRes, c.DoReq(req, &organizationMembersRes)
}
|
go
|
func (c *Client) OrganizationMemberList(organizationIdentity string, lr *ListRange) ([]OrganizationMember, error) {
req, err := c.NewRequest("GET", "/organizations/"+organizationIdentity+"/members", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationMembersRes []OrganizationMember
return organizationMembersRes, c.DoReq(req, &organizationMembersRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationMemberList",
"(",
"organizationIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"OrganizationMember",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"organizationIdentity",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"organizationMembersRes",
"[",
"]",
"OrganizationMember",
"\n",
"return",
"organizationMembersRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"organizationMembersRes",
")",
"\n",
"}"
] |
// List members of the organization.
//
// organizationIdentity is the unique identifier of the OrganizationMember's
// Organization. lr is an optional ListRange that sets the Range options for the
// paginated list of results.
|
[
"List",
"members",
"of",
"the",
"organization",
".",
"organizationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationMember",
"s",
"Organization",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"results",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_member.go#L57-L69
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
NewScheduler
|
func NewScheduler(db *sql.DB, config client.ConfigProvider) *Scheduler {
return &Scheduler{
cloudformation: cloudformation.New(config),
ecs: ecsWithCaching(&ECS{ecs.New(config)}),
s3: s3.New(config),
ec2: ec2.New(config),
db: db,
after: time.After,
}
}
|
go
|
func NewScheduler(db *sql.DB, config client.ConfigProvider) *Scheduler {
return &Scheduler{
cloudformation: cloudformation.New(config),
ecs: ecsWithCaching(&ECS{ecs.New(config)}),
s3: s3.New(config),
ec2: ec2.New(config),
db: db,
after: time.After,
}
}
|
[
"func",
"NewScheduler",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"config",
"client",
".",
"ConfigProvider",
")",
"*",
"Scheduler",
"{",
"return",
"&",
"Scheduler",
"{",
"cloudformation",
":",
"cloudformation",
".",
"New",
"(",
"config",
")",
",",
"ecs",
":",
"ecsWithCaching",
"(",
"&",
"ECS",
"{",
"ecs",
".",
"New",
"(",
"config",
")",
"}",
")",
",",
"s3",
":",
"s3",
".",
"New",
"(",
"config",
")",
",",
"ec2",
":",
"ec2",
".",
"New",
"(",
"config",
")",
",",
"db",
":",
"db",
",",
"after",
":",
"time",
".",
"After",
",",
"}",
"\n",
"}"
] |
// NewScheduler returns a new Scheduler instance.
|
[
"NewScheduler",
"returns",
"a",
"new",
"Scheduler",
"instance",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L190-L199
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
createTemplate
|
func (s *Scheduler) createTemplate(ctx context.Context, app *twelvefactor.Manifest, stackTags []*cloudformation.Tag) (*cloudformationTemplate, error) {
data := &TemplateData{
Manifest: app,
StackTags: stackTags,
}
buf := new(bytes.Buffer)
if err := s.Template.Execute(buf, data); err != nil {
return nil, err
}
key := fmt.Sprintf("%s/%s/%x", app.Name, app.AppID, sha1.Sum(buf.Bytes()))
url := fmt.Sprintf("https://%s.s3.amazonaws.com/%s", s.Bucket, key)
if _, err := s.s3.PutObject(&s3.PutObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(fmt.Sprintf("/%s", key)),
Body: bytes.NewReader(buf.Bytes()),
ContentType: aws.String("application/json"),
}); err != nil {
return nil, fmt.Errorf("error uploading stack template to s3: %v", err)
}
t := &cloudformationTemplate{
URL: aws.String(url),
Size: buf.Len(),
}
resp, err := s.cloudformation.ValidateTemplate(&cloudformation.ValidateTemplateInput{
TemplateURL: aws.String(url),
})
if err != nil {
return t, &templateValidationError{template: t, err: err}
}
t.Parameters = resp.Parameters
return t, nil
}
|
go
|
func (s *Scheduler) createTemplate(ctx context.Context, app *twelvefactor.Manifest, stackTags []*cloudformation.Tag) (*cloudformationTemplate, error) {
data := &TemplateData{
Manifest: app,
StackTags: stackTags,
}
buf := new(bytes.Buffer)
if err := s.Template.Execute(buf, data); err != nil {
return nil, err
}
key := fmt.Sprintf("%s/%s/%x", app.Name, app.AppID, sha1.Sum(buf.Bytes()))
url := fmt.Sprintf("https://%s.s3.amazonaws.com/%s", s.Bucket, key)
if _, err := s.s3.PutObject(&s3.PutObjectInput{
Bucket: aws.String(s.Bucket),
Key: aws.String(fmt.Sprintf("/%s", key)),
Body: bytes.NewReader(buf.Bytes()),
ContentType: aws.String("application/json"),
}); err != nil {
return nil, fmt.Errorf("error uploading stack template to s3: %v", err)
}
t := &cloudformationTemplate{
URL: aws.String(url),
Size: buf.Len(),
}
resp, err := s.cloudformation.ValidateTemplate(&cloudformation.ValidateTemplateInput{
TemplateURL: aws.String(url),
})
if err != nil {
return t, &templateValidationError{template: t, err: err}
}
t.Parameters = resp.Parameters
return t, nil
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"createTemplate",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"*",
"twelvefactor",
".",
"Manifest",
",",
"stackTags",
"[",
"]",
"*",
"cloudformation",
".",
"Tag",
")",
"(",
"*",
"cloudformationTemplate",
",",
"error",
")",
"{",
"data",
":=",
"&",
"TemplateData",
"{",
"Manifest",
":",
"app",
",",
"StackTags",
":",
"stackTags",
",",
"}",
"\n\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"if",
"err",
":=",
"s",
".",
"Template",
".",
"Execute",
"(",
"buf",
",",
"data",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"key",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"app",
".",
"Name",
",",
"app",
".",
"AppID",
",",
"sha1",
".",
"Sum",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
")",
"\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Bucket",
",",
"key",
")",
"\n\n",
"if",
"_",
",",
"err",
":=",
"s",
".",
"s3",
".",
"PutObject",
"(",
"&",
"s3",
".",
"PutObjectInput",
"{",
"Bucket",
":",
"aws",
".",
"String",
"(",
"s",
".",
"Bucket",
")",
",",
"Key",
":",
"aws",
".",
"String",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
")",
")",
",",
"Body",
":",
"bytes",
".",
"NewReader",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
",",
"ContentType",
":",
"aws",
".",
"String",
"(",
"\"",
"\"",
")",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"t",
":=",
"&",
"cloudformationTemplate",
"{",
"URL",
":",
"aws",
".",
"String",
"(",
"url",
")",
",",
"Size",
":",
"buf",
".",
"Len",
"(",
")",
",",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"s",
".",
"cloudformation",
".",
"ValidateTemplate",
"(",
"&",
"cloudformation",
".",
"ValidateTemplateInput",
"{",
"TemplateURL",
":",
"aws",
".",
"String",
"(",
"url",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"t",
",",
"&",
"templateValidationError",
"{",
"template",
":",
"t",
",",
"err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"t",
".",
"Parameters",
"=",
"resp",
".",
"Parameters",
"\n\n",
"return",
"t",
",",
"nil",
"\n",
"}"
] |
// createTemplate takes a scheduler.App, and returns a validated cloudformation
// template.
|
[
"createTemplate",
"takes",
"a",
"scheduler",
".",
"App",
"and",
"returns",
"a",
"validated",
"cloudformation",
"template",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L426-L464
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
createStack
|
func (s *Scheduler) createStack(ctx context.Context, input *createStackInput, output chan stackOperationOutput, ss twelvefactor.StatusStream) error {
waiter := s.waitFor(ctx, createStack, ss)
submitted := make(chan error)
fn := func() error {
_, err := s.cloudformation.CreateStack(&cloudformation.CreateStackInput{
StackName: input.StackName,
TemplateURL: input.Template.URL,
Tags: input.Tags,
Parameters: input.Parameters,
})
submitted <- err
return err
}
go func() {
stack, err := s.performStackOperation(ctx, *input.StackName, fn, waiter, ss)
output <- stackOperationOutput{stack, err}
}()
return <-submitted
}
|
go
|
func (s *Scheduler) createStack(ctx context.Context, input *createStackInput, output chan stackOperationOutput, ss twelvefactor.StatusStream) error {
waiter := s.waitFor(ctx, createStack, ss)
submitted := make(chan error)
fn := func() error {
_, err := s.cloudformation.CreateStack(&cloudformation.CreateStackInput{
StackName: input.StackName,
TemplateURL: input.Template.URL,
Tags: input.Tags,
Parameters: input.Parameters,
})
submitted <- err
return err
}
go func() {
stack, err := s.performStackOperation(ctx, *input.StackName, fn, waiter, ss)
output <- stackOperationOutput{stack, err}
}()
return <-submitted
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"createStack",
"(",
"ctx",
"context",
".",
"Context",
",",
"input",
"*",
"createStackInput",
",",
"output",
"chan",
"stackOperationOutput",
",",
"ss",
"twelvefactor",
".",
"StatusStream",
")",
"error",
"{",
"waiter",
":=",
"s",
".",
"waitFor",
"(",
"ctx",
",",
"createStack",
",",
"ss",
")",
"\n\n",
"submitted",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"fn",
":=",
"func",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"s",
".",
"cloudformation",
".",
"CreateStack",
"(",
"&",
"cloudformation",
".",
"CreateStackInput",
"{",
"StackName",
":",
"input",
".",
"StackName",
",",
"TemplateURL",
":",
"input",
".",
"Template",
".",
"URL",
",",
"Tags",
":",
"input",
".",
"Tags",
",",
"Parameters",
":",
"input",
".",
"Parameters",
",",
"}",
")",
"\n",
"submitted",
"<-",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"go",
"func",
"(",
")",
"{",
"stack",
",",
"err",
":=",
"s",
".",
"performStackOperation",
"(",
"ctx",
",",
"*",
"input",
".",
"StackName",
",",
"fn",
",",
"waiter",
",",
"ss",
")",
"\n",
"output",
"<-",
"stackOperationOutput",
"{",
"stack",
",",
"err",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"<-",
"submitted",
"\n",
"}"
] |
// createStack creates a new CloudFormation stack with the given input. This
// function returns as soon as the stack creation has been submitted. It does
// not wait for the stack creation to complete.
|
[
"createStack",
"creates",
"a",
"new",
"CloudFormation",
"stack",
"with",
"the",
"given",
"input",
".",
"This",
"function",
"returns",
"as",
"soon",
"as",
"the",
"stack",
"creation",
"has",
"been",
"submitted",
".",
"It",
"does",
"not",
"wait",
"for",
"the",
"stack",
"creation",
"to",
"complete",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L484-L504
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
updateStack
|
func (s *Scheduler) updateStack(ctx context.Context, input *updateStackInput, output chan stackOperationOutput, ss twelvefactor.StatusStream) error {
waiter := s.waitFor(ctx, updateStack, ss)
locked := make(chan struct{})
submitted := make(chan error, 1)
fn := func() error {
close(locked)
err := s.executeStackUpdate(input)
if err == nil {
publish(ctx, ss, "Stack update submitted")
}
submitted <- err
return err
}
go func() {
stack, err := s.performStackOperation(ctx, *input.StackName, fn, waiter, ss)
output <- stackOperationOutput{stack, err}
}()
var err error
select {
case <-s.after(lockWait):
publish(ctx, ss, "Waiting for existing stack operation to complete")
// FIXME: At this point, we don't want to affect UX by waiting
// around, so we return. But, if the stack update times out, or
// there's an error, that information is essentially silenced.
return nil
case <-locked:
// if a lock is obtained within the time frame, we might as well
// just wait for the update to get submitted.
err = <-submitted
}
return err
}
|
go
|
func (s *Scheduler) updateStack(ctx context.Context, input *updateStackInput, output chan stackOperationOutput, ss twelvefactor.StatusStream) error {
waiter := s.waitFor(ctx, updateStack, ss)
locked := make(chan struct{})
submitted := make(chan error, 1)
fn := func() error {
close(locked)
err := s.executeStackUpdate(input)
if err == nil {
publish(ctx, ss, "Stack update submitted")
}
submitted <- err
return err
}
go func() {
stack, err := s.performStackOperation(ctx, *input.StackName, fn, waiter, ss)
output <- stackOperationOutput{stack, err}
}()
var err error
select {
case <-s.after(lockWait):
publish(ctx, ss, "Waiting for existing stack operation to complete")
// FIXME: At this point, we don't want to affect UX by waiting
// around, so we return. But, if the stack update times out, or
// there's an error, that information is essentially silenced.
return nil
case <-locked:
// if a lock is obtained within the time frame, we might as well
// just wait for the update to get submitted.
err = <-submitted
}
return err
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"updateStack",
"(",
"ctx",
"context",
".",
"Context",
",",
"input",
"*",
"updateStackInput",
",",
"output",
"chan",
"stackOperationOutput",
",",
"ss",
"twelvefactor",
".",
"StatusStream",
")",
"error",
"{",
"waiter",
":=",
"s",
".",
"waitFor",
"(",
"ctx",
",",
"updateStack",
",",
"ss",
")",
"\n\n",
"locked",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"submitted",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"fn",
":=",
"func",
"(",
")",
"error",
"{",
"close",
"(",
"locked",
")",
"\n",
"err",
":=",
"s",
".",
"executeStackUpdate",
"(",
"input",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"publish",
"(",
"ctx",
",",
"ss",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"submitted",
"<-",
"err",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"stack",
",",
"err",
":=",
"s",
".",
"performStackOperation",
"(",
"ctx",
",",
"*",
"input",
".",
"StackName",
",",
"fn",
",",
"waiter",
",",
"ss",
")",
"\n",
"output",
"<-",
"stackOperationOutput",
"{",
"stack",
",",
"err",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"select",
"{",
"case",
"<-",
"s",
".",
"after",
"(",
"lockWait",
")",
":",
"publish",
"(",
"ctx",
",",
"ss",
",",
"\"",
"\"",
")",
"\n",
"// FIXME: At this point, we don't want to affect UX by waiting",
"// around, so we return. But, if the stack update times out, or",
"// there's an error, that information is essentially silenced.",
"return",
"nil",
"\n",
"case",
"<-",
"locked",
":",
"// if a lock is obtained within the time frame, we might as well",
"// just wait for the update to get submitted.",
"err",
"=",
"<-",
"submitted",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// updateStack updates an existing CloudFormation stack with the given input.
// If there are no other active updates, this function returns as soon as the
// stack update has been submitted. If there are other updates, the function
// returns after `lockTimeout` and the update continues in the background.
|
[
"updateStack",
"updates",
"an",
"existing",
"CloudFormation",
"stack",
"with",
"the",
"given",
"input",
".",
"If",
"there",
"are",
"no",
"other",
"active",
"updates",
"this",
"function",
"returns",
"as",
"soon",
"as",
"the",
"stack",
"update",
"has",
"been",
"submitted",
".",
"If",
"there",
"are",
"other",
"updates",
"the",
"function",
"returns",
"after",
"lockTimeout",
"and",
"the",
"update",
"continues",
"in",
"the",
"background",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L518-L553
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
waitUntilStackOperationComplete
|
func (s *Scheduler) waitUntilStackOperationComplete(lock *pglock.AdvisoryLock, wait func() error) error {
errCh := make(chan error)
go func() { errCh <- wait() }()
var err error
select {
case <-s.after(stackOperationTimeout):
err = errors.New("timed out waiting for stack operation to complete")
case err = <-errCh:
}
return err
}
|
go
|
func (s *Scheduler) waitUntilStackOperationComplete(lock *pglock.AdvisoryLock, wait func() error) error {
errCh := make(chan error)
go func() { errCh <- wait() }()
var err error
select {
case <-s.after(stackOperationTimeout):
err = errors.New("timed out waiting for stack operation to complete")
case err = <-errCh:
}
return err
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"waitUntilStackOperationComplete",
"(",
"lock",
"*",
"pglock",
".",
"AdvisoryLock",
",",
"wait",
"func",
"(",
")",
"error",
")",
"error",
"{",
"errCh",
":=",
"make",
"(",
"chan",
"error",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"errCh",
"<-",
"wait",
"(",
")",
"}",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"select",
"{",
"case",
"<-",
"s",
".",
"after",
"(",
"stackOperationTimeout",
")",
":",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"err",
"=",
"<-",
"errCh",
":",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// waitUntilStackOperationComplete waits until wait returns, or it times out.
|
[
"waitUntilStackOperationComplete",
"waits",
"until",
"wait",
"returns",
"or",
"it",
"times",
"out",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L615-L627
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
executeStackUpdate
|
func (s *Scheduler) executeStackUpdate(input *updateStackInput) error {
stack, err := s.stack(input.StackName)
if err != nil {
return err
}
i := &cloudformation.UpdateStackInput{
StackName: input.StackName,
Parameters: updateParameters(input.Parameters, stack, input.Template),
Tags: input.Tags,
}
if input.Template != nil {
i.TemplateURL = input.Template.URL
} else {
i.UsePreviousTemplate = aws.Bool(true)
}
_, err = s.cloudformation.UpdateStack(i)
if err != nil {
if err, ok := err.(awserr.Error); ok {
if err.Code() == "ValidationError" && err.Message() == "No updates are to be performed." {
return nil
}
}
return fmt.Errorf("error updating stack: %v", err)
}
return nil
}
|
go
|
func (s *Scheduler) executeStackUpdate(input *updateStackInput) error {
stack, err := s.stack(input.StackName)
if err != nil {
return err
}
i := &cloudformation.UpdateStackInput{
StackName: input.StackName,
Parameters: updateParameters(input.Parameters, stack, input.Template),
Tags: input.Tags,
}
if input.Template != nil {
i.TemplateURL = input.Template.URL
} else {
i.UsePreviousTemplate = aws.Bool(true)
}
_, err = s.cloudformation.UpdateStack(i)
if err != nil {
if err, ok := err.(awserr.Error); ok {
if err.Code() == "ValidationError" && err.Message() == "No updates are to be performed." {
return nil
}
}
return fmt.Errorf("error updating stack: %v", err)
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"executeStackUpdate",
"(",
"input",
"*",
"updateStackInput",
")",
"error",
"{",
"stack",
",",
"err",
":=",
"s",
".",
"stack",
"(",
"input",
".",
"StackName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"i",
":=",
"&",
"cloudformation",
".",
"UpdateStackInput",
"{",
"StackName",
":",
"input",
".",
"StackName",
",",
"Parameters",
":",
"updateParameters",
"(",
"input",
".",
"Parameters",
",",
"stack",
",",
"input",
".",
"Template",
")",
",",
"Tags",
":",
"input",
".",
"Tags",
",",
"}",
"\n",
"if",
"input",
".",
"Template",
"!=",
"nil",
"{",
"i",
".",
"TemplateURL",
"=",
"input",
".",
"Template",
".",
"URL",
"\n",
"}",
"else",
"{",
"i",
".",
"UsePreviousTemplate",
"=",
"aws",
".",
"Bool",
"(",
"true",
")",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"s",
".",
"cloudformation",
".",
"UpdateStack",
"(",
"i",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"awserr",
".",
"Error",
")",
";",
"ok",
"{",
"if",
"err",
".",
"Code",
"(",
")",
"==",
"\"",
"\"",
"&&",
"err",
".",
"Message",
"(",
")",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// executeStackUpdate performs a stack update.
|
[
"executeStackUpdate",
"performs",
"a",
"stack",
"update",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L630-L659
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
stack
|
func (s *Scheduler) stack(stackName *string) (*cloudformation.Stack, error) {
resp, err := s.cloudformation.DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: stackName,
})
if err != nil {
return nil, err
}
return resp.Stacks[0], nil
}
|
go
|
func (s *Scheduler) stack(stackName *string) (*cloudformation.Stack, error) {
resp, err := s.cloudformation.DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: stackName,
})
if err != nil {
return nil, err
}
return resp.Stacks[0], nil
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"stack",
"(",
"stackName",
"*",
"string",
")",
"(",
"*",
"cloudformation",
".",
"Stack",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"s",
".",
"cloudformation",
".",
"DescribeStacks",
"(",
"&",
"cloudformation",
".",
"DescribeStacksInput",
"{",
"StackName",
":",
"stackName",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"resp",
".",
"Stacks",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] |
// stack returns the cloudformation.Stack for the given stack name.
|
[
"stack",
"returns",
"the",
"cloudformation",
".",
"Stack",
"for",
"the",
"given",
"stack",
"name",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L662-L670
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
Remove
|
func (s *Scheduler) Remove(ctx context.Context, appID string) error {
tx, err := s.db.Begin()
if err != nil {
return err
}
err = s.remove(ctx, tx, appID)
if err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
|
go
|
func (s *Scheduler) Remove(ctx context.Context, appID string) error {
tx, err := s.db.Begin()
if err != nil {
return err
}
err = s.remove(ctx, tx, appID)
if err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
",",
"appID",
"string",
")",
"error",
"{",
"tx",
",",
"err",
":=",
"s",
".",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"s",
".",
"remove",
"(",
"ctx",
",",
"tx",
",",
"appID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"tx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"tx",
".",
"Commit",
"(",
")",
"\n",
"}"
] |
// Remove removes the CloudFormation stack for the given app.
|
[
"Remove",
"removes",
"the",
"CloudFormation",
"stack",
"for",
"the",
"given",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L673-L686
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
remove
|
func (s *Scheduler) remove(_ context.Context, tx *sql.Tx, appID string) error {
stackName, err := s.stackName(appID)
// if there's no stack entry in the db for this app, nothing to remove
if err == errNoStack {
return nil
}
if err != nil {
return err
}
_, err = tx.Exec(`DELETE FROM stacks WHERE app_id = $1`, appID)
if err != nil {
return err
}
_, err = s.cloudformation.DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: aws.String(stackName),
})
if err, ok := err.(awserr.Error); ok && err.Message() == fmt.Sprintf("Stack with id %s does not exist", stackName) {
return nil
}
if _, err := s.cloudformation.DeleteStack(&cloudformation.DeleteStackInput{
StackName: aws.String(stackName),
}); err != nil {
return fmt.Errorf("error deleting stack: %v", err)
}
return nil
}
|
go
|
func (s *Scheduler) remove(_ context.Context, tx *sql.Tx, appID string) error {
stackName, err := s.stackName(appID)
// if there's no stack entry in the db for this app, nothing to remove
if err == errNoStack {
return nil
}
if err != nil {
return err
}
_, err = tx.Exec(`DELETE FROM stacks WHERE app_id = $1`, appID)
if err != nil {
return err
}
_, err = s.cloudformation.DescribeStacks(&cloudformation.DescribeStacksInput{
StackName: aws.String(stackName),
})
if err, ok := err.(awserr.Error); ok && err.Message() == fmt.Sprintf("Stack with id %s does not exist", stackName) {
return nil
}
if _, err := s.cloudformation.DeleteStack(&cloudformation.DeleteStackInput{
StackName: aws.String(stackName),
}); err != nil {
return fmt.Errorf("error deleting stack: %v", err)
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"remove",
"(",
"_",
"context",
".",
"Context",
",",
"tx",
"*",
"sql",
".",
"Tx",
",",
"appID",
"string",
")",
"error",
"{",
"stackName",
",",
"err",
":=",
"s",
".",
"stackName",
"(",
"appID",
")",
"\n\n",
"// if there's no stack entry in the db for this app, nothing to remove",
"if",
"err",
"==",
"errNoStack",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"tx",
".",
"Exec",
"(",
"`DELETE FROM stacks WHERE app_id = $1`",
",",
"appID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"s",
".",
"cloudformation",
".",
"DescribeStacks",
"(",
"&",
"cloudformation",
".",
"DescribeStacksInput",
"{",
"StackName",
":",
"aws",
".",
"String",
"(",
"stackName",
")",
",",
"}",
")",
"\n",
"if",
"err",
",",
"ok",
":=",
"err",
".",
"(",
"awserr",
".",
"Error",
")",
";",
"ok",
"&&",
"err",
".",
"Message",
"(",
")",
"==",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"stackName",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"s",
".",
"cloudformation",
".",
"DeleteStack",
"(",
"&",
"cloudformation",
".",
"DeleteStackInput",
"{",
"StackName",
":",
"aws",
".",
"String",
"(",
"stackName",
")",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Remove removes the CloudFormation stack for the given app, if it exists.
|
[
"Remove",
"removes",
"the",
"CloudFormation",
"stack",
"for",
"the",
"given",
"app",
"if",
"it",
"exists",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L689-L719
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
tasks
|
func (s *Scheduler) tasks(app string) ([]*ecs.Task, error) {
services, err := s.Services(app)
if err != nil {
return nil, err
}
var arns []*string
// Find all of the tasks started by the ECS services.
for process, serviceArn := range services {
id, err := arn.ResourceID(serviceArn)
if err != nil {
return nil, err
}
var taskArns []*string
if err := s.ecs.ListTasksPages(&ecs.ListTasksInput{
Cluster: aws.String(s.Cluster),
ServiceName: aws.String(id),
}, func(resp *ecs.ListTasksOutput, lastPage bool) bool {
taskArns = append(taskArns, resp.TaskArns...)
return true
}); err != nil {
return nil, fmt.Errorf("error listing tasks for %s: %v", process, err)
}
if len(taskArns) == 0 {
continue
}
arns = append(arns, taskArns...)
}
// Find all of the tasks started by Run.
if err := s.ecs.ListTasksPages(&ecs.ListTasksInput{
Cluster: aws.String(s.Cluster),
StartedBy: aws.String(app),
}, func(resp *ecs.ListTasksOutput, lastPage bool) bool {
arns = append(arns, resp.TaskArns...)
return true
}); err != nil {
return nil, fmt.Errorf("error listing tasks started by %s: %v", app, err)
}
var tasks []*ecs.Task
for _, chunk := range chunkStrings(arns, MaxDescribeTasks) {
resp, err := s.ecs.DescribeTasks(&ecs.DescribeTasksInput{
Cluster: aws.String(s.Cluster),
Tasks: chunk,
})
if err != nil {
return nil, fmt.Errorf("error describing %d tasks: %v", len(chunk), err)
}
tasks = append(tasks, resp.Tasks...)
}
return tasks, nil
}
|
go
|
func (s *Scheduler) tasks(app string) ([]*ecs.Task, error) {
services, err := s.Services(app)
if err != nil {
return nil, err
}
var arns []*string
// Find all of the tasks started by the ECS services.
for process, serviceArn := range services {
id, err := arn.ResourceID(serviceArn)
if err != nil {
return nil, err
}
var taskArns []*string
if err := s.ecs.ListTasksPages(&ecs.ListTasksInput{
Cluster: aws.String(s.Cluster),
ServiceName: aws.String(id),
}, func(resp *ecs.ListTasksOutput, lastPage bool) bool {
taskArns = append(taskArns, resp.TaskArns...)
return true
}); err != nil {
return nil, fmt.Errorf("error listing tasks for %s: %v", process, err)
}
if len(taskArns) == 0 {
continue
}
arns = append(arns, taskArns...)
}
// Find all of the tasks started by Run.
if err := s.ecs.ListTasksPages(&ecs.ListTasksInput{
Cluster: aws.String(s.Cluster),
StartedBy: aws.String(app),
}, func(resp *ecs.ListTasksOutput, lastPage bool) bool {
arns = append(arns, resp.TaskArns...)
return true
}); err != nil {
return nil, fmt.Errorf("error listing tasks started by %s: %v", app, err)
}
var tasks []*ecs.Task
for _, chunk := range chunkStrings(arns, MaxDescribeTasks) {
resp, err := s.ecs.DescribeTasks(&ecs.DescribeTasksInput{
Cluster: aws.String(s.Cluster),
Tasks: chunk,
})
if err != nil {
return nil, fmt.Errorf("error describing %d tasks: %v", len(chunk), err)
}
tasks = append(tasks, resp.Tasks...)
}
return tasks, nil
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"tasks",
"(",
"app",
"string",
")",
"(",
"[",
"]",
"*",
"ecs",
".",
"Task",
",",
"error",
")",
"{",
"services",
",",
"err",
":=",
"s",
".",
"Services",
"(",
"app",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"arns",
"[",
"]",
"*",
"string",
"\n\n",
"// Find all of the tasks started by the ECS services.",
"for",
"process",
",",
"serviceArn",
":=",
"range",
"services",
"{",
"id",
",",
"err",
":=",
"arn",
".",
"ResourceID",
"(",
"serviceArn",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"taskArns",
"[",
"]",
"*",
"string",
"\n",
"if",
"err",
":=",
"s",
".",
"ecs",
".",
"ListTasksPages",
"(",
"&",
"ecs",
".",
"ListTasksInput",
"{",
"Cluster",
":",
"aws",
".",
"String",
"(",
"s",
".",
"Cluster",
")",
",",
"ServiceName",
":",
"aws",
".",
"String",
"(",
"id",
")",
",",
"}",
",",
"func",
"(",
"resp",
"*",
"ecs",
".",
"ListTasksOutput",
",",
"lastPage",
"bool",
")",
"bool",
"{",
"taskArns",
"=",
"append",
"(",
"taskArns",
",",
"resp",
".",
"TaskArns",
"...",
")",
"\n",
"return",
"true",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"process",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"taskArns",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"arns",
"=",
"append",
"(",
"arns",
",",
"taskArns",
"...",
")",
"\n",
"}",
"\n\n",
"// Find all of the tasks started by Run.",
"if",
"err",
":=",
"s",
".",
"ecs",
".",
"ListTasksPages",
"(",
"&",
"ecs",
".",
"ListTasksInput",
"{",
"Cluster",
":",
"aws",
".",
"String",
"(",
"s",
".",
"Cluster",
")",
",",
"StartedBy",
":",
"aws",
".",
"String",
"(",
"app",
")",
",",
"}",
",",
"func",
"(",
"resp",
"*",
"ecs",
".",
"ListTasksOutput",
",",
"lastPage",
"bool",
")",
"bool",
"{",
"arns",
"=",
"append",
"(",
"arns",
",",
"resp",
".",
"TaskArns",
"...",
")",
"\n",
"return",
"true",
"\n",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"app",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"tasks",
"[",
"]",
"*",
"ecs",
".",
"Task",
"\n",
"for",
"_",
",",
"chunk",
":=",
"range",
"chunkStrings",
"(",
"arns",
",",
"MaxDescribeTasks",
")",
"{",
"resp",
",",
"err",
":=",
"s",
".",
"ecs",
".",
"DescribeTasks",
"(",
"&",
"ecs",
".",
"DescribeTasksInput",
"{",
"Cluster",
":",
"aws",
".",
"String",
"(",
"s",
".",
"Cluster",
")",
",",
"Tasks",
":",
"chunk",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"chunk",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"tasks",
"=",
"append",
"(",
"tasks",
",",
"resp",
".",
"Tasks",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"tasks",
",",
"nil",
"\n",
"}"
] |
// tasks returns all of the ECS tasks for this app.
|
[
"tasks",
"returns",
"all",
"of",
"the",
"ECS",
"tasks",
"for",
"this",
"app",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L829-L887
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
Stop
|
func (s *Scheduler) Stop(ctx context.Context, taskID string) error {
_, err := s.ecs.StopTask(&ecs.StopTaskInput{
Cluster: aws.String(s.Cluster),
Task: aws.String(taskID),
})
return err
}
|
go
|
func (s *Scheduler) Stop(ctx context.Context, taskID string) error {
_, err := s.ecs.StopTask(&ecs.StopTaskInput{
Cluster: aws.String(s.Cluster),
Task: aws.String(taskID),
})
return err
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
",",
"taskID",
"string",
")",
"error",
"{",
"_",
",",
"err",
":=",
"s",
".",
"ecs",
".",
"StopTask",
"(",
"&",
"ecs",
".",
"StopTaskInput",
"{",
"Cluster",
":",
"aws",
".",
"String",
"(",
"s",
".",
"Cluster",
")",
",",
"Task",
":",
"aws",
".",
"String",
"(",
"taskID",
")",
",",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// Stop stops the given ECS task.
|
[
"Stop",
"stops",
"the",
"given",
"ECS",
"task",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L916-L922
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
Run
|
func (m *Scheduler) Run(ctx context.Context, app *twelvefactor.Manifest) error {
for _, process := range app.Processes {
var attached bool
if process.Stdout != nil || process.Stderr != nil {
attached = true
}
t, ok := m.Template.(interface {
ContainerDefinition(*twelvefactor.Manifest, *twelvefactor.Process) *ecs.ContainerDefinition
})
if !ok {
return errors.New("provided template can't generate a container definition for this process")
}
containerDefinition := t.ContainerDefinition(app, process)
if attached {
if containerDefinition.DockerLabels == nil {
containerDefinition.DockerLabels = make(map[string]*string)
}
// NOTE: Currently, this depends on a patched version of the
// Amazon ECS Container Agent, since the official agent doesn't
// provide a method to pass these down to the `CreateContainer`
// call.
containerDefinition.DockerLabels["docker.config.Tty"] = aws.String("true")
containerDefinition.DockerLabels["docker.config.OpenStdin"] = aws.String("true")
}
resp, err := m.ecs.RegisterTaskDefinition(&ecs.RegisterTaskDefinitionInput{
Family: aws.String(fmt.Sprintf("%s--%s", app.AppID, process.Type)),
TaskRoleArn: taskRoleArn(app),
ContainerDefinitions: []*ecs.ContainerDefinition{
containerDefinition,
},
})
if err != nil {
return fmt.Errorf("error registering TaskDefinition: %v", err)
}
input := &ecs.RunTaskInput{
TaskDefinition: resp.TaskDefinition.TaskDefinitionArn,
Cluster: aws.String(m.Cluster),
Count: aws.Int64(1),
StartedBy: aws.String(app.AppID),
}
if v := process.ECS; v != nil {
input.PlacementConstraints = v.PlacementConstraints
input.PlacementStrategy = v.PlacementStrategy
}
runResp, err := m.ecs.RunTask(input)
if err != nil {
return fmt.Errorf("error calling RunTask: %v", err)
}
for _, f := range runResp.Failures {
return fmt.Errorf("error running task %s: %s", aws.StringValue(f.Arn), aws.StringValue(f.Reason))
}
task := runResp.Tasks[0]
if attached {
// Ensure that we atleast try to stop the task, after we detach
// from the process. This ensures that we don't have zombie
// one-off processes lying around.
defer m.ecs.StopTask(&ecs.StopTaskInput{
Cluster: task.ClusterArn,
Task: task.TaskArn,
})
if err := m.attach(ctx, task, process.Stdin, process.Stdout, process.Stderr); err != nil {
return err
}
}
}
return nil
}
|
go
|
func (m *Scheduler) Run(ctx context.Context, app *twelvefactor.Manifest) error {
for _, process := range app.Processes {
var attached bool
if process.Stdout != nil || process.Stderr != nil {
attached = true
}
t, ok := m.Template.(interface {
ContainerDefinition(*twelvefactor.Manifest, *twelvefactor.Process) *ecs.ContainerDefinition
})
if !ok {
return errors.New("provided template can't generate a container definition for this process")
}
containerDefinition := t.ContainerDefinition(app, process)
if attached {
if containerDefinition.DockerLabels == nil {
containerDefinition.DockerLabels = make(map[string]*string)
}
// NOTE: Currently, this depends on a patched version of the
// Amazon ECS Container Agent, since the official agent doesn't
// provide a method to pass these down to the `CreateContainer`
// call.
containerDefinition.DockerLabels["docker.config.Tty"] = aws.String("true")
containerDefinition.DockerLabels["docker.config.OpenStdin"] = aws.String("true")
}
resp, err := m.ecs.RegisterTaskDefinition(&ecs.RegisterTaskDefinitionInput{
Family: aws.String(fmt.Sprintf("%s--%s", app.AppID, process.Type)),
TaskRoleArn: taskRoleArn(app),
ContainerDefinitions: []*ecs.ContainerDefinition{
containerDefinition,
},
})
if err != nil {
return fmt.Errorf("error registering TaskDefinition: %v", err)
}
input := &ecs.RunTaskInput{
TaskDefinition: resp.TaskDefinition.TaskDefinitionArn,
Cluster: aws.String(m.Cluster),
Count: aws.Int64(1),
StartedBy: aws.String(app.AppID),
}
if v := process.ECS; v != nil {
input.PlacementConstraints = v.PlacementConstraints
input.PlacementStrategy = v.PlacementStrategy
}
runResp, err := m.ecs.RunTask(input)
if err != nil {
return fmt.Errorf("error calling RunTask: %v", err)
}
for _, f := range runResp.Failures {
return fmt.Errorf("error running task %s: %s", aws.StringValue(f.Arn), aws.StringValue(f.Reason))
}
task := runResp.Tasks[0]
if attached {
// Ensure that we atleast try to stop the task, after we detach
// from the process. This ensures that we don't have zombie
// one-off processes lying around.
defer m.ecs.StopTask(&ecs.StopTaskInput{
Cluster: task.ClusterArn,
Task: task.TaskArn,
})
if err := m.attach(ctx, task, process.Stdin, process.Stdout, process.Stderr); err != nil {
return err
}
}
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Scheduler",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"*",
"twelvefactor",
".",
"Manifest",
")",
"error",
"{",
"for",
"_",
",",
"process",
":=",
"range",
"app",
".",
"Processes",
"{",
"var",
"attached",
"bool",
"\n",
"if",
"process",
".",
"Stdout",
"!=",
"nil",
"||",
"process",
".",
"Stderr",
"!=",
"nil",
"{",
"attached",
"=",
"true",
"\n",
"}",
"\n\n",
"t",
",",
"ok",
":=",
"m",
".",
"Template",
".",
"(",
"interface",
"{",
"ContainerDefinition",
"(",
"*",
"twelvefactor",
".",
"Manifest",
",",
"*",
"twelvefactor",
".",
"Process",
")",
"*",
"ecs",
".",
"ContainerDefinition",
"\n",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"containerDefinition",
":=",
"t",
".",
"ContainerDefinition",
"(",
"app",
",",
"process",
")",
"\n",
"if",
"attached",
"{",
"if",
"containerDefinition",
".",
"DockerLabels",
"==",
"nil",
"{",
"containerDefinition",
".",
"DockerLabels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"string",
")",
"\n",
"}",
"\n",
"// NOTE: Currently, this depends on a patched version of the",
"// Amazon ECS Container Agent, since the official agent doesn't",
"// provide a method to pass these down to the `CreateContainer`",
"// call.",
"containerDefinition",
".",
"DockerLabels",
"[",
"\"",
"\"",
"]",
"=",
"aws",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"containerDefinition",
".",
"DockerLabels",
"[",
"\"",
"\"",
"]",
"=",
"aws",
".",
"String",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"m",
".",
"ecs",
".",
"RegisterTaskDefinition",
"(",
"&",
"ecs",
".",
"RegisterTaskDefinitionInput",
"{",
"Family",
":",
"aws",
".",
"String",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"app",
".",
"AppID",
",",
"process",
".",
"Type",
")",
")",
",",
"TaskRoleArn",
":",
"taskRoleArn",
"(",
"app",
")",
",",
"ContainerDefinitions",
":",
"[",
"]",
"*",
"ecs",
".",
"ContainerDefinition",
"{",
"containerDefinition",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"input",
":=",
"&",
"ecs",
".",
"RunTaskInput",
"{",
"TaskDefinition",
":",
"resp",
".",
"TaskDefinition",
".",
"TaskDefinitionArn",
",",
"Cluster",
":",
"aws",
".",
"String",
"(",
"m",
".",
"Cluster",
")",
",",
"Count",
":",
"aws",
".",
"Int64",
"(",
"1",
")",
",",
"StartedBy",
":",
"aws",
".",
"String",
"(",
"app",
".",
"AppID",
")",
",",
"}",
"\n\n",
"if",
"v",
":=",
"process",
".",
"ECS",
";",
"v",
"!=",
"nil",
"{",
"input",
".",
"PlacementConstraints",
"=",
"v",
".",
"PlacementConstraints",
"\n",
"input",
".",
"PlacementStrategy",
"=",
"v",
".",
"PlacementStrategy",
"\n",
"}",
"\n\n",
"runResp",
",",
"err",
":=",
"m",
".",
"ecs",
".",
"RunTask",
"(",
"input",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"f",
":=",
"range",
"runResp",
".",
"Failures",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"f",
".",
"Arn",
")",
",",
"aws",
".",
"StringValue",
"(",
"f",
".",
"Reason",
")",
")",
"\n",
"}",
"\n\n",
"task",
":=",
"runResp",
".",
"Tasks",
"[",
"0",
"]",
"\n\n",
"if",
"attached",
"{",
"// Ensure that we atleast try to stop the task, after we detach",
"// from the process. This ensures that we don't have zombie",
"// one-off processes lying around.",
"defer",
"m",
".",
"ecs",
".",
"StopTask",
"(",
"&",
"ecs",
".",
"StopTaskInput",
"{",
"Cluster",
":",
"task",
".",
"ClusterArn",
",",
"Task",
":",
"task",
".",
"TaskArn",
",",
"}",
")",
"\n\n",
"if",
"err",
":=",
"m",
".",
"attach",
"(",
"ctx",
",",
"task",
",",
"process",
".",
"Stdin",
",",
"process",
".",
"Stdout",
",",
"process",
".",
"Stderr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Run registers a TaskDefinition for the process, and calls RunTask.
|
[
"Run",
"registers",
"a",
"TaskDefinition",
"for",
"the",
"process",
"and",
"calls",
"RunTask",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L925-L1002
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
attach
|
func (m *Scheduler) attach(ctx context.Context, task *ecs.Task, stdin io.Reader, stdout, stderr io.Writer) error {
if a, _ := arn.Parse(aws.StringValue(task.TaskArn)); a != nil {
fmt.Fprintf(stderr, "Attaching to %s...\r\n", a.Resource)
}
descContainerInstanceResp, err := m.ecs.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
Cluster: task.ClusterArn,
ContainerInstances: []*string{task.ContainerInstanceArn},
})
if err != nil {
return fmt.Errorf("error describing container instance (%s): %v", aws.StringValue(task.ContainerInstanceArn), err)
}
containerInstance := descContainerInstanceResp.ContainerInstances[0]
descInstanceResp, err := m.ec2.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: []*string{containerInstance.Ec2InstanceId},
})
if err != nil {
return fmt.Errorf("error describing ec2 instance (%s): %v", aws.StringValue(containerInstance.Ec2InstanceId), err)
}
ec2Instance := descInstanceResp.Reservations[0].Instances[0]
// Wait for the task to start running. It will stay in the
// PENDING state while the container is being pulled.
if err := m.ecs.WaitUntilTasksNotPending(&ecs.DescribeTasksInput{
Cluster: task.ClusterArn,
Tasks: []*string{task.TaskArn},
}); err != nil {
return fmt.Errorf("error waiting for %s to transition from PENDING state: %s", aws.StringValue(task.TaskArn), err)
}
// Open a new connection to the Docker daemon on the EC2
// instance where the task is running.
d, err := m.NewDockerClient(ec2Instance)
if err != nil {
return fmt.Errorf("error connecting to docker daemon on %s: %v", aws.StringValue(ec2Instance.InstanceId), err)
}
// Find the container id for the ECS task.
containers, err := d.ListContainers(docker.ListContainersOptions{
All: true,
Filters: map[string][]string{
"label": []string{
fmt.Sprintf("com.amazonaws.ecs.task-arn=%s", aws.StringValue(task.TaskArn)),
//fmt.Sprintf("com.amazonaws.ecs.container-name", p)
},
},
})
if err != nil {
return fmt.Errorf("error listing containers for task: %v", err)
}
if len(containers) != 1 {
return fmt.Errorf("unable to find container for %s running on %s", aws.StringValue(task.TaskArn), aws.StringValue(ec2Instance.InstanceId))
}
containerID := containers[0].ID
if err := d.AttachToContainer(docker.AttachToContainerOptions{
Container: containerID,
InputStream: stdin,
OutputStream: stdout,
ErrorStream: stderr,
Logs: true,
Stream: true,
Stdin: true,
Stdout: true,
Stderr: true,
RawTerminal: true,
}); err != nil {
return fmt.Errorf("error attaching to container (%s): %v", containerID, err)
}
return nil
}
|
go
|
func (m *Scheduler) attach(ctx context.Context, task *ecs.Task, stdin io.Reader, stdout, stderr io.Writer) error {
if a, _ := arn.Parse(aws.StringValue(task.TaskArn)); a != nil {
fmt.Fprintf(stderr, "Attaching to %s...\r\n", a.Resource)
}
descContainerInstanceResp, err := m.ecs.DescribeContainerInstances(&ecs.DescribeContainerInstancesInput{
Cluster: task.ClusterArn,
ContainerInstances: []*string{task.ContainerInstanceArn},
})
if err != nil {
return fmt.Errorf("error describing container instance (%s): %v", aws.StringValue(task.ContainerInstanceArn), err)
}
containerInstance := descContainerInstanceResp.ContainerInstances[0]
descInstanceResp, err := m.ec2.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: []*string{containerInstance.Ec2InstanceId},
})
if err != nil {
return fmt.Errorf("error describing ec2 instance (%s): %v", aws.StringValue(containerInstance.Ec2InstanceId), err)
}
ec2Instance := descInstanceResp.Reservations[0].Instances[0]
// Wait for the task to start running. It will stay in the
// PENDING state while the container is being pulled.
if err := m.ecs.WaitUntilTasksNotPending(&ecs.DescribeTasksInput{
Cluster: task.ClusterArn,
Tasks: []*string{task.TaskArn},
}); err != nil {
return fmt.Errorf("error waiting for %s to transition from PENDING state: %s", aws.StringValue(task.TaskArn), err)
}
// Open a new connection to the Docker daemon on the EC2
// instance where the task is running.
d, err := m.NewDockerClient(ec2Instance)
if err != nil {
return fmt.Errorf("error connecting to docker daemon on %s: %v", aws.StringValue(ec2Instance.InstanceId), err)
}
// Find the container id for the ECS task.
containers, err := d.ListContainers(docker.ListContainersOptions{
All: true,
Filters: map[string][]string{
"label": []string{
fmt.Sprintf("com.amazonaws.ecs.task-arn=%s", aws.StringValue(task.TaskArn)),
//fmt.Sprintf("com.amazonaws.ecs.container-name", p)
},
},
})
if err != nil {
return fmt.Errorf("error listing containers for task: %v", err)
}
if len(containers) != 1 {
return fmt.Errorf("unable to find container for %s running on %s", aws.StringValue(task.TaskArn), aws.StringValue(ec2Instance.InstanceId))
}
containerID := containers[0].ID
if err := d.AttachToContainer(docker.AttachToContainerOptions{
Container: containerID,
InputStream: stdin,
OutputStream: stdout,
ErrorStream: stderr,
Logs: true,
Stream: true,
Stdin: true,
Stdout: true,
Stderr: true,
RawTerminal: true,
}); err != nil {
return fmt.Errorf("error attaching to container (%s): %v", containerID, err)
}
return nil
}
|
[
"func",
"(",
"m",
"*",
"Scheduler",
")",
"attach",
"(",
"ctx",
"context",
".",
"Context",
",",
"task",
"*",
"ecs",
".",
"Task",
",",
"stdin",
"io",
".",
"Reader",
",",
"stdout",
",",
"stderr",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"a",
",",
"_",
":=",
"arn",
".",
"Parse",
"(",
"aws",
".",
"StringValue",
"(",
"task",
".",
"TaskArn",
")",
")",
";",
"a",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"stderr",
",",
"\"",
"\\r",
"\\n",
"\"",
",",
"a",
".",
"Resource",
")",
"\n",
"}",
"\n\n",
"descContainerInstanceResp",
",",
"err",
":=",
"m",
".",
"ecs",
".",
"DescribeContainerInstances",
"(",
"&",
"ecs",
".",
"DescribeContainerInstancesInput",
"{",
"Cluster",
":",
"task",
".",
"ClusterArn",
",",
"ContainerInstances",
":",
"[",
"]",
"*",
"string",
"{",
"task",
".",
"ContainerInstanceArn",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"task",
".",
"ContainerInstanceArn",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"containerInstance",
":=",
"descContainerInstanceResp",
".",
"ContainerInstances",
"[",
"0",
"]",
"\n",
"descInstanceResp",
",",
"err",
":=",
"m",
".",
"ec2",
".",
"DescribeInstances",
"(",
"&",
"ec2",
".",
"DescribeInstancesInput",
"{",
"InstanceIds",
":",
"[",
"]",
"*",
"string",
"{",
"containerInstance",
".",
"Ec2InstanceId",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"containerInstance",
".",
"Ec2InstanceId",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"ec2Instance",
":=",
"descInstanceResp",
".",
"Reservations",
"[",
"0",
"]",
".",
"Instances",
"[",
"0",
"]",
"\n\n",
"// Wait for the task to start running. It will stay in the",
"// PENDING state while the container is being pulled.",
"if",
"err",
":=",
"m",
".",
"ecs",
".",
"WaitUntilTasksNotPending",
"(",
"&",
"ecs",
".",
"DescribeTasksInput",
"{",
"Cluster",
":",
"task",
".",
"ClusterArn",
",",
"Tasks",
":",
"[",
"]",
"*",
"string",
"{",
"task",
".",
"TaskArn",
"}",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"task",
".",
"TaskArn",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Open a new connection to the Docker daemon on the EC2",
"// instance where the task is running.",
"d",
",",
"err",
":=",
"m",
".",
"NewDockerClient",
"(",
"ec2Instance",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"ec2Instance",
".",
"InstanceId",
")",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Find the container id for the ECS task.",
"containers",
",",
"err",
":=",
"d",
".",
"ListContainers",
"(",
"docker",
".",
"ListContainersOptions",
"{",
"All",
":",
"true",
",",
"Filters",
":",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"task",
".",
"TaskArn",
")",
")",
",",
"//fmt.Sprintf(\"com.amazonaws.ecs.container-name\", p)",
"}",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"containers",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"aws",
".",
"StringValue",
"(",
"task",
".",
"TaskArn",
")",
",",
"aws",
".",
"StringValue",
"(",
"ec2Instance",
".",
"InstanceId",
")",
")",
"\n",
"}",
"\n\n",
"containerID",
":=",
"containers",
"[",
"0",
"]",
".",
"ID",
"\n\n",
"if",
"err",
":=",
"d",
".",
"AttachToContainer",
"(",
"docker",
".",
"AttachToContainerOptions",
"{",
"Container",
":",
"containerID",
",",
"InputStream",
":",
"stdin",
",",
"OutputStream",
":",
"stdout",
",",
"ErrorStream",
":",
"stderr",
",",
"Logs",
":",
"true",
",",
"Stream",
":",
"true",
",",
"Stdin",
":",
"true",
",",
"Stdout",
":",
"true",
",",
"Stderr",
":",
"true",
",",
"RawTerminal",
":",
"true",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"containerID",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// attach attaches to the given ECS task.
|
[
"attach",
"attaches",
"to",
"the",
"given",
"ECS",
"task",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1005-L1080
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
stackName
|
func (s *Scheduler) stackName(appID string) (string, error) {
var stackName string
err := s.db.QueryRow(`SELECT stack_name FROM stacks WHERE app_id = $1`, appID).Scan(&stackName)
if err == sql.ErrNoRows {
return "", errNoStack
}
return stackName, err
}
|
go
|
func (s *Scheduler) stackName(appID string) (string, error) {
var stackName string
err := s.db.QueryRow(`SELECT stack_name FROM stacks WHERE app_id = $1`, appID).Scan(&stackName)
if err == sql.ErrNoRows {
return "", errNoStack
}
return stackName, err
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"stackName",
"(",
"appID",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"stackName",
"string",
"\n",
"err",
":=",
"s",
".",
"db",
".",
"QueryRow",
"(",
"`SELECT stack_name FROM stacks WHERE app_id = $1`",
",",
"appID",
")",
".",
"Scan",
"(",
"&",
"stackName",
")",
"\n",
"if",
"err",
"==",
"sql",
".",
"ErrNoRows",
"{",
"return",
"\"",
"\"",
",",
"errNoStack",
"\n",
"}",
"\n",
"return",
"stackName",
",",
"err",
"\n",
"}"
] |
// stackName returns the name of the CloudFormation stack for the app id.
|
[
"stackName",
"returns",
"the",
"name",
"of",
"the",
"CloudFormation",
"stack",
"for",
"the",
"app",
"id",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1083-L1090
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
waitFor
|
func (s *Scheduler) waitFor(ctx context.Context, op stackOperation, ss twelvefactor.StatusStream) func(*cloudformation.DescribeStacksInput) error {
waiter := waiters[op]
wait := waiter.wait(s.cloudformation)
return func(input *cloudformation.DescribeStacksInput) error {
tags := []string{
fmt.Sprintf("stack:%s", *input.StackName),
}
publish(ctx, ss, waiter.startMessage)
start := time.Now()
err := wait(input)
stats.Timing(ctx, fmt.Sprintf("scheduler.cloudformation.%s", op), time.Since(start), 1.0, tags)
if err == nil {
publish(ctx, ss, waiter.successMessage)
}
return err
}
}
|
go
|
func (s *Scheduler) waitFor(ctx context.Context, op stackOperation, ss twelvefactor.StatusStream) func(*cloudformation.DescribeStacksInput) error {
waiter := waiters[op]
wait := waiter.wait(s.cloudformation)
return func(input *cloudformation.DescribeStacksInput) error {
tags := []string{
fmt.Sprintf("stack:%s", *input.StackName),
}
publish(ctx, ss, waiter.startMessage)
start := time.Now()
err := wait(input)
stats.Timing(ctx, fmt.Sprintf("scheduler.cloudformation.%s", op), time.Since(start), 1.0, tags)
if err == nil {
publish(ctx, ss, waiter.successMessage)
}
return err
}
}
|
[
"func",
"(",
"s",
"*",
"Scheduler",
")",
"waitFor",
"(",
"ctx",
"context",
".",
"Context",
",",
"op",
"stackOperation",
",",
"ss",
"twelvefactor",
".",
"StatusStream",
")",
"func",
"(",
"*",
"cloudformation",
".",
"DescribeStacksInput",
")",
"error",
"{",
"waiter",
":=",
"waiters",
"[",
"op",
"]",
"\n",
"wait",
":=",
"waiter",
".",
"wait",
"(",
"s",
".",
"cloudformation",
")",
"\n\n",
"return",
"func",
"(",
"input",
"*",
"cloudformation",
".",
"DescribeStacksInput",
")",
"error",
"{",
"tags",
":=",
"[",
"]",
"string",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"input",
".",
"StackName",
")",
",",
"}",
"\n",
"publish",
"(",
"ctx",
",",
"ss",
",",
"waiter",
".",
"startMessage",
")",
"\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"err",
":=",
"wait",
"(",
"input",
")",
"\n",
"stats",
".",
"Timing",
"(",
"ctx",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"op",
")",
",",
"time",
".",
"Since",
"(",
"start",
")",
",",
"1.0",
",",
"tags",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"publish",
"(",
"ctx",
",",
"ss",
",",
"waiter",
".",
"successMessage",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}"
] |
// waitFor returns a wait function that will wait for the given stack operation
// to complete, and sends status messages to the status stream, and also records
// metrics for how long the operation took.
|
[
"waitFor",
"returns",
"a",
"wait",
"function",
"that",
"will",
"wait",
"for",
"the",
"given",
"stack",
"operation",
"to",
"complete",
"and",
"sends",
"status",
"messages",
"to",
"the",
"status",
"stream",
"and",
"also",
"records",
"metrics",
"for",
"how",
"long",
"the",
"operation",
"took",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1128-L1145
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
extractProcessData
|
func extractProcessData(value string) map[string]string {
data := make(map[string]string)
pairs := strings.Split(value, ",")
for _, p := range pairs {
parts := strings.Split(p, "=")
data[parts[0]] = parts[1]
}
return data
}
|
go
|
func extractProcessData(value string) map[string]string {
data := make(map[string]string)
pairs := strings.Split(value, ",")
for _, p := range pairs {
parts := strings.Split(p, "=")
data[parts[0]] = parts[1]
}
return data
}
|
[
"func",
"extractProcessData",
"(",
"value",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"data",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"pairs",
":=",
"strings",
".",
"Split",
"(",
"value",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"pairs",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"p",
",",
"\"",
"\"",
")",
"\n",
"data",
"[",
"parts",
"[",
"0",
"]",
"]",
"=",
"parts",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"return",
"data",
"\n",
"}"
] |
// extractProcessData extracts a map that maps the process name to some
// corresponding value.
|
[
"extractProcessData",
"extracts",
"a",
"map",
"that",
"maps",
"the",
"process",
"name",
"to",
"some",
"corresponding",
"value",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1149-L1159
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
taskDefinitionToProcess
|
func taskDefinitionToProcess(td *ecs.TaskDefinition) (*twelvefactor.Process, error) {
// If this task definition has no container definitions, then something
// funky is up.
if len(td.ContainerDefinitions) == 0 {
return nil, errors.New("task definition had no container definitions")
}
container := td.ContainerDefinitions[0]
var command []string
for _, s := range container.Command {
command = append(command, *s)
}
env := make(map[string]string)
for _, kvp := range container.Environment {
if kvp != nil {
env[aws.StringValue(kvp.Name)] = aws.StringValue(kvp.Value)
}
}
return &twelvefactor.Process{
Type: aws.StringValue(container.Name),
Command: command,
Env: env,
CPUShares: uint(*container.Cpu),
Memory: uint(*container.Memory) * bytesize.MB,
Nproc: uint(softLimit(container.Ulimits, "nproc")),
}, nil
}
|
go
|
func taskDefinitionToProcess(td *ecs.TaskDefinition) (*twelvefactor.Process, error) {
// If this task definition has no container definitions, then something
// funky is up.
if len(td.ContainerDefinitions) == 0 {
return nil, errors.New("task definition had no container definitions")
}
container := td.ContainerDefinitions[0]
var command []string
for _, s := range container.Command {
command = append(command, *s)
}
env := make(map[string]string)
for _, kvp := range container.Environment {
if kvp != nil {
env[aws.StringValue(kvp.Name)] = aws.StringValue(kvp.Value)
}
}
return &twelvefactor.Process{
Type: aws.StringValue(container.Name),
Command: command,
Env: env,
CPUShares: uint(*container.Cpu),
Memory: uint(*container.Memory) * bytesize.MB,
Nproc: uint(softLimit(container.Ulimits, "nproc")),
}, nil
}
|
[
"func",
"taskDefinitionToProcess",
"(",
"td",
"*",
"ecs",
".",
"TaskDefinition",
")",
"(",
"*",
"twelvefactor",
".",
"Process",
",",
"error",
")",
"{",
"// If this task definition has no container definitions, then something",
"// funky is up.",
"if",
"len",
"(",
"td",
".",
"ContainerDefinitions",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"container",
":=",
"td",
".",
"ContainerDefinitions",
"[",
"0",
"]",
"\n\n",
"var",
"command",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"container",
".",
"Command",
"{",
"command",
"=",
"append",
"(",
"command",
",",
"*",
"s",
")",
"\n",
"}",
"\n\n",
"env",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"kvp",
":=",
"range",
"container",
".",
"Environment",
"{",
"if",
"kvp",
"!=",
"nil",
"{",
"env",
"[",
"aws",
".",
"StringValue",
"(",
"kvp",
".",
"Name",
")",
"]",
"=",
"aws",
".",
"StringValue",
"(",
"kvp",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"twelvefactor",
".",
"Process",
"{",
"Type",
":",
"aws",
".",
"StringValue",
"(",
"container",
".",
"Name",
")",
",",
"Command",
":",
"command",
",",
"Env",
":",
"env",
",",
"CPUShares",
":",
"uint",
"(",
"*",
"container",
".",
"Cpu",
")",
",",
"Memory",
":",
"uint",
"(",
"*",
"container",
".",
"Memory",
")",
"*",
"bytesize",
".",
"MB",
",",
"Nproc",
":",
"uint",
"(",
"softLimit",
"(",
"container",
".",
"Ulimits",
",",
"\"",
"\"",
")",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// taskDefinitionToProcess takes an ECS Task Definition and converts it to a
// Process.
|
[
"taskDefinitionToProcess",
"takes",
"an",
"ECS",
"Task",
"Definition",
"and",
"converts",
"it",
"to",
"a",
"Process",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1163-L1192
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
chunkStrings
|
func chunkStrings(s []*string, size int) [][]*string {
var chunks [][]*string
for len(s) > 0 {
end := size
if len(s) < size {
end = len(s)
}
chunks = append(chunks, s[0:end])
s = s[end:]
}
return chunks
}
|
go
|
func chunkStrings(s []*string, size int) [][]*string {
var chunks [][]*string
for len(s) > 0 {
end := size
if len(s) < size {
end = len(s)
}
chunks = append(chunks, s[0:end])
s = s[end:]
}
return chunks
}
|
[
"func",
"chunkStrings",
"(",
"s",
"[",
"]",
"*",
"string",
",",
"size",
"int",
")",
"[",
"]",
"[",
"]",
"*",
"string",
"{",
"var",
"chunks",
"[",
"]",
"[",
"]",
"*",
"string",
"\n",
"for",
"len",
"(",
"s",
")",
">",
"0",
"{",
"end",
":=",
"size",
"\n",
"if",
"len",
"(",
"s",
")",
"<",
"size",
"{",
"end",
"=",
"len",
"(",
"s",
")",
"\n",
"}",
"\n\n",
"chunks",
"=",
"append",
"(",
"chunks",
",",
"s",
"[",
"0",
":",
"end",
"]",
")",
"\n",
"s",
"=",
"s",
"[",
"end",
":",
"]",
"\n",
"}",
"\n",
"return",
"chunks",
"\n",
"}"
] |
// chunkStrings slices a slice of string pointers in equal length chunks, with
// the last slice being the leftovers.
|
[
"chunkStrings",
"slices",
"a",
"slice",
"of",
"string",
"pointers",
"in",
"equal",
"length",
"chunks",
"with",
"the",
"last",
"slice",
"being",
"the",
"leftovers",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1210-L1222
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
updateParameters
|
func updateParameters(provided []*cloudformation.Parameter, stack *cloudformation.Stack, template *cloudformationTemplate) []*cloudformation.Parameter {
parameters := provided[:]
// This tracks the names of the parameters that have pre-existing values
// on the stack.
existingParams := make(map[string]bool)
for _, p := range stack.Parameters {
existingParams[*p.ParameterKey] = true
}
// These are the parameters that can be set for the stack. If a template
// is provided, then these are the parameters defined in the template.
// If no template is provided, then these are the parameters that the
// stack provides.
settableParams := make(map[string]bool)
if template != nil {
for _, p := range template.Parameters {
settableParams[*p.ParameterKey] = true
}
} else {
settableParams = existingParams
}
// The parameters that are provided in this update.
providedParams := make(map[string]bool)
for _, p := range parameters {
providedParams[*p.ParameterKey] = true
}
// Fill in any parameters that weren't provided with their previous
// value, if available
for k := range settableParams {
notProvided := !providedParams[k]
hasExistingValue := existingParams[k]
// If the parameter hasn't been provided with an explicit value,
// and the stack has this parameter set, we'll use the previous
// value. Not doing this would result in the parameters
// `Default` getting used.
if notProvided && hasExistingValue {
parameters = append(parameters, &cloudformation.Parameter{
ParameterKey: aws.String(k),
UsePreviousValue: aws.Bool(true),
})
}
}
return parameters
}
|
go
|
func updateParameters(provided []*cloudformation.Parameter, stack *cloudformation.Stack, template *cloudformationTemplate) []*cloudformation.Parameter {
parameters := provided[:]
// This tracks the names of the parameters that have pre-existing values
// on the stack.
existingParams := make(map[string]bool)
for _, p := range stack.Parameters {
existingParams[*p.ParameterKey] = true
}
// These are the parameters that can be set for the stack. If a template
// is provided, then these are the parameters defined in the template.
// If no template is provided, then these are the parameters that the
// stack provides.
settableParams := make(map[string]bool)
if template != nil {
for _, p := range template.Parameters {
settableParams[*p.ParameterKey] = true
}
} else {
settableParams = existingParams
}
// The parameters that are provided in this update.
providedParams := make(map[string]bool)
for _, p := range parameters {
providedParams[*p.ParameterKey] = true
}
// Fill in any parameters that weren't provided with their previous
// value, if available
for k := range settableParams {
notProvided := !providedParams[k]
hasExistingValue := existingParams[k]
// If the parameter hasn't been provided with an explicit value,
// and the stack has this parameter set, we'll use the previous
// value. Not doing this would result in the parameters
// `Default` getting used.
if notProvided && hasExistingValue {
parameters = append(parameters, &cloudformation.Parameter{
ParameterKey: aws.String(k),
UsePreviousValue: aws.Bool(true),
})
}
}
return parameters
}
|
[
"func",
"updateParameters",
"(",
"provided",
"[",
"]",
"*",
"cloudformation",
".",
"Parameter",
",",
"stack",
"*",
"cloudformation",
".",
"Stack",
",",
"template",
"*",
"cloudformationTemplate",
")",
"[",
"]",
"*",
"cloudformation",
".",
"Parameter",
"{",
"parameters",
":=",
"provided",
"[",
":",
"]",
"\n\n",
"// This tracks the names of the parameters that have pre-existing values",
"// on the stack.",
"existingParams",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"stack",
".",
"Parameters",
"{",
"existingParams",
"[",
"*",
"p",
".",
"ParameterKey",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"// These are the parameters that can be set for the stack. If a template",
"// is provided, then these are the parameters defined in the template.",
"// If no template is provided, then these are the parameters that the",
"// stack provides.",
"settableParams",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"if",
"template",
"!=",
"nil",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"template",
".",
"Parameters",
"{",
"settableParams",
"[",
"*",
"p",
".",
"ParameterKey",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"else",
"{",
"settableParams",
"=",
"existingParams",
"\n",
"}",
"\n\n",
"// The parameters that are provided in this update.",
"providedParams",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"parameters",
"{",
"providedParams",
"[",
"*",
"p",
".",
"ParameterKey",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"// Fill in any parameters that weren't provided with their previous",
"// value, if available",
"for",
"k",
":=",
"range",
"settableParams",
"{",
"notProvided",
":=",
"!",
"providedParams",
"[",
"k",
"]",
"\n",
"hasExistingValue",
":=",
"existingParams",
"[",
"k",
"]",
"\n\n",
"// If the parameter hasn't been provided with an explicit value,",
"// and the stack has this parameter set, we'll use the previous",
"// value. Not doing this would result in the parameters",
"// `Default` getting used.",
"if",
"notProvided",
"&&",
"hasExistingValue",
"{",
"parameters",
"=",
"append",
"(",
"parameters",
",",
"&",
"cloudformation",
".",
"Parameter",
"{",
"ParameterKey",
":",
"aws",
".",
"String",
"(",
"k",
")",
",",
"UsePreviousValue",
":",
"aws",
".",
"Bool",
"(",
"true",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"parameters",
"\n",
"}"
] |
// updateParameters returns the parameters that should be provided in an
// UpdateStack operation.
|
[
"updateParameters",
"returns",
"the",
"parameters",
"that",
"should",
"be",
"provided",
"in",
"an",
"UpdateStack",
"operation",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1226-L1274
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
stackLockKey
|
func stackLockKey(stackName string) uint32 {
return crc32.ChecksumIEEE([]byte(fmt.Sprintf("stack_%s", stackName)))
}
|
go
|
func stackLockKey(stackName string) uint32 {
return crc32.ChecksumIEEE([]byte(fmt.Sprintf("stack_%s", stackName)))
}
|
[
"func",
"stackLockKey",
"(",
"stackName",
"string",
")",
"uint32",
"{",
"return",
"crc32",
".",
"ChecksumIEEE",
"(",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"stackName",
")",
")",
")",
"\n",
"}"
] |
// stackLackKey returns the key to use when obtaining an advisory lock for a
// CloudFormation stack.
|
[
"stackLackKey",
"returns",
"the",
"key",
"to",
"use",
"when",
"obtaining",
"an",
"advisory",
"lock",
"for",
"a",
"CloudFormation",
"stack",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1278-L1280
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
newAdvisoryLock
|
func newAdvisoryLock(db *sql.DB, stackName string) (*pglock.AdvisoryLock, error) {
l, err := pglock.NewAdvisoryLock(db, stackLockKey(stackName))
if err != nil {
return l, err
}
l.LockTimeout = lockTimeout
l.Context = fmt.Sprintf("stack %s", stackName)
return l, nil
}
|
go
|
func newAdvisoryLock(db *sql.DB, stackName string) (*pglock.AdvisoryLock, error) {
l, err := pglock.NewAdvisoryLock(db, stackLockKey(stackName))
if err != nil {
return l, err
}
l.LockTimeout = lockTimeout
l.Context = fmt.Sprintf("stack %s", stackName)
return l, nil
}
|
[
"func",
"newAdvisoryLock",
"(",
"db",
"*",
"sql",
".",
"DB",
",",
"stackName",
"string",
")",
"(",
"*",
"pglock",
".",
"AdvisoryLock",
",",
"error",
")",
"{",
"l",
",",
"err",
":=",
"pglock",
".",
"NewAdvisoryLock",
"(",
"db",
",",
"stackLockKey",
"(",
"stackName",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"l",
",",
"err",
"\n",
"}",
"\n",
"l",
".",
"LockTimeout",
"=",
"lockTimeout",
"\n",
"l",
".",
"Context",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"stackName",
")",
"\n",
"return",
"l",
",",
"nil",
"\n",
"}"
] |
// newAdvsiroyLock returns a new AdvisoryLock suitable for obtaining a lock to
// perform the stack update.
|
[
"newAdvsiroyLock",
"returns",
"a",
"new",
"AdvisoryLock",
"suitable",
"for",
"obtaining",
"a",
"lock",
"to",
"perform",
"the",
"stack",
"update",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1284-L1292
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
output
|
func output(stack *cloudformation.Stack, key string) (output *cloudformation.Output) {
for _, o := range stack.Outputs {
if *o.OutputKey == key {
output = o
}
}
return
}
|
go
|
func output(stack *cloudformation.Stack, key string) (output *cloudformation.Output) {
for _, o := range stack.Outputs {
if *o.OutputKey == key {
output = o
}
}
return
}
|
[
"func",
"output",
"(",
"stack",
"*",
"cloudformation",
".",
"Stack",
",",
"key",
"string",
")",
"(",
"output",
"*",
"cloudformation",
".",
"Output",
")",
"{",
"for",
"_",
",",
"o",
":=",
"range",
"stack",
".",
"Outputs",
"{",
"if",
"*",
"o",
".",
"OutputKey",
"==",
"key",
"{",
"output",
"=",
"o",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] |
// output returns the cloudformation.Output that matches the given key.
|
[
"output",
"returns",
"the",
"cloudformation",
".",
"Output",
"that",
"matches",
"the",
"given",
"key",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1310-L1317
|
train
|
remind101/empire
|
scheduler/cloudformation/cloudformation.go
|
deploymentsToWatch
|
func deploymentsToWatch(stack *cloudformation.Stack) (map[string]*ecsDeployment, error) {
deployments := output(stack, deploymentsOutput)
services := output(stack, servicesOutput)
if deployments == nil {
return nil, fmt.Errorf("deployments output missing from stack")
}
if services == nil {
return nil, fmt.Errorf("services output missing from stack")
}
arns := extractProcessData(*services.OutputValue)
deploymentIDs := extractProcessData(*deployments.OutputValue)
if len(arns) == 0 {
return nil, fmt.Errorf("no services found in output")
}
if len(deploymentIDs) == 0 {
return nil, fmt.Errorf("no deploymentIDs found in output")
}
ecsDeployments := make(map[string]*ecsDeployment)
for p, a := range arns {
deploymentID, ok := deploymentIDs[p]
if !ok {
return nil, fmt.Errorf("deployment id not found for process: %v", p)
}
ecsDeployments[a] = &ecsDeployment{
process: p,
ID: deploymentID,
}
}
return ecsDeployments, nil
}
|
go
|
func deploymentsToWatch(stack *cloudformation.Stack) (map[string]*ecsDeployment, error) {
deployments := output(stack, deploymentsOutput)
services := output(stack, servicesOutput)
if deployments == nil {
return nil, fmt.Errorf("deployments output missing from stack")
}
if services == nil {
return nil, fmt.Errorf("services output missing from stack")
}
arns := extractProcessData(*services.OutputValue)
deploymentIDs := extractProcessData(*deployments.OutputValue)
if len(arns) == 0 {
return nil, fmt.Errorf("no services found in output")
}
if len(deploymentIDs) == 0 {
return nil, fmt.Errorf("no deploymentIDs found in output")
}
ecsDeployments := make(map[string]*ecsDeployment)
for p, a := range arns {
deploymentID, ok := deploymentIDs[p]
if !ok {
return nil, fmt.Errorf("deployment id not found for process: %v", p)
}
ecsDeployments[a] = &ecsDeployment{
process: p,
ID: deploymentID,
}
}
return ecsDeployments, nil
}
|
[
"func",
"deploymentsToWatch",
"(",
"stack",
"*",
"cloudformation",
".",
"Stack",
")",
"(",
"map",
"[",
"string",
"]",
"*",
"ecsDeployment",
",",
"error",
")",
"{",
"deployments",
":=",
"output",
"(",
"stack",
",",
"deploymentsOutput",
")",
"\n",
"services",
":=",
"output",
"(",
"stack",
",",
"servicesOutput",
")",
"\n",
"if",
"deployments",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"services",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"arns",
":=",
"extractProcessData",
"(",
"*",
"services",
".",
"OutputValue",
")",
"\n",
"deploymentIDs",
":=",
"extractProcessData",
"(",
"*",
"deployments",
".",
"OutputValue",
")",
"\n\n",
"if",
"len",
"(",
"arns",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"deploymentIDs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"ecsDeployments",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ecsDeployment",
")",
"\n",
"for",
"p",
",",
"a",
":=",
"range",
"arns",
"{",
"deploymentID",
",",
"ok",
":=",
"deploymentIDs",
"[",
"p",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
")",
"\n",
"}",
"\n",
"ecsDeployments",
"[",
"a",
"]",
"=",
"&",
"ecsDeployment",
"{",
"process",
":",
"p",
",",
"ID",
":",
"deploymentID",
",",
"}",
"\n",
"}",
"\n",
"return",
"ecsDeployments",
",",
"nil",
"\n",
"}"
] |
// deploymentsToWatch returns an array of ecsDeployments for the given cloudformation stack
|
[
"deploymentsToWatch",
"returns",
"an",
"array",
"of",
"ecsDeployments",
"for",
"the",
"given",
"cloudformation",
"stack"
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/cloudformation.go#L1325-L1357
|
train
|
remind101/empire
|
server/cloudformation/queue.go
|
Start
|
func (q *SQSDispatcher) Start(handle func(context.Context, *sqs.Message) error) {
var wg sync.WaitGroup
for i := 0; i < q.NumWorkers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
q.start(handle)
}()
}
wg.Wait()
}
|
go
|
func (q *SQSDispatcher) Start(handle func(context.Context, *sqs.Message) error) {
var wg sync.WaitGroup
for i := 0; i < q.NumWorkers; i++ {
wg.Add(1)
go func() {
defer wg.Done()
q.start(handle)
}()
}
wg.Wait()
}
|
[
"func",
"(",
"q",
"*",
"SQSDispatcher",
")",
"Start",
"(",
"handle",
"func",
"(",
"context",
".",
"Context",
",",
"*",
"sqs",
".",
"Message",
")",
"error",
")",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"q",
".",
"NumWorkers",
";",
"i",
"++",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"q",
".",
"start",
"(",
"handle",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}"
] |
// Start starts multiple goroutines pulling messages off of the queue.
|
[
"Start",
"starts",
"multiple",
"goroutines",
"pulling",
"messages",
"off",
"of",
"the",
"queue",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/queue.go#L65-L76
|
train
|
remind101/empire
|
server/cloudformation/queue.go
|
start
|
func (q *SQSDispatcher) start(handle func(context.Context, *sqs.Message) error) {
var wg sync.WaitGroup
for {
select {
case <-q.stopped:
wg.Wait()
return
default:
ctx := q.Context
resp, err := q.sqs.ReceiveMessage(&sqs.ReceiveMessageInput{
QueueUrl: aws.String(q.QueueURL),
WaitTimeSeconds: aws.Int64(defaultWaitTime),
})
if err != nil {
reporter.Report(ctx, err)
continue
}
for _, m := range resp.Messages {
wg.Add(1)
go func(m *sqs.Message) {
defer wg.Done()
if err := q.handle(ctx, handle, m); err != nil {
reporter.Report(ctx, err)
}
}(m)
}
}
}
}
|
go
|
func (q *SQSDispatcher) start(handle func(context.Context, *sqs.Message) error) {
var wg sync.WaitGroup
for {
select {
case <-q.stopped:
wg.Wait()
return
default:
ctx := q.Context
resp, err := q.sqs.ReceiveMessage(&sqs.ReceiveMessageInput{
QueueUrl: aws.String(q.QueueURL),
WaitTimeSeconds: aws.Int64(defaultWaitTime),
})
if err != nil {
reporter.Report(ctx, err)
continue
}
for _, m := range resp.Messages {
wg.Add(1)
go func(m *sqs.Message) {
defer wg.Done()
if err := q.handle(ctx, handle, m); err != nil {
reporter.Report(ctx, err)
}
}(m)
}
}
}
}
|
[
"func",
"(",
"q",
"*",
"SQSDispatcher",
")",
"start",
"(",
"handle",
"func",
"(",
"context",
".",
"Context",
",",
"*",
"sqs",
".",
"Message",
")",
"error",
")",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"q",
".",
"stopped",
":",
"wg",
".",
"Wait",
"(",
")",
"\n",
"return",
"\n",
"default",
":",
"ctx",
":=",
"q",
".",
"Context",
"\n\n",
"resp",
",",
"err",
":=",
"q",
".",
"sqs",
".",
"ReceiveMessage",
"(",
"&",
"sqs",
".",
"ReceiveMessageInput",
"{",
"QueueUrl",
":",
"aws",
".",
"String",
"(",
"q",
".",
"QueueURL",
")",
",",
"WaitTimeSeconds",
":",
"aws",
".",
"Int64",
"(",
"defaultWaitTime",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"reporter",
".",
"Report",
"(",
"ctx",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"m",
":=",
"range",
"resp",
".",
"Messages",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"m",
"*",
"sqs",
".",
"Message",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"if",
"err",
":=",
"q",
".",
"handle",
"(",
"ctx",
",",
"handle",
",",
"m",
")",
";",
"err",
"!=",
"nil",
"{",
"reporter",
".",
"Report",
"(",
"ctx",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"(",
"m",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// start starts a pulling messages off of the queue and passing them to the
// handler.
|
[
"start",
"starts",
"a",
"pulling",
"messages",
"off",
"of",
"the",
"queue",
"and",
"passing",
"them",
"to",
"the",
"handler",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/queue.go#L84-L114
|
train
|
remind101/empire
|
server/cloudformation/queue.go
|
extendMessageVisibilityTimeout
|
func (q *SQSDispatcher) extendMessageVisibilityTimeout(receiptHandle *string) (<-chan time.Time, error) {
visibilityTimeout := int64(float64(q.VisibilityHeartbeat) / float64(time.Second))
_, err := q.sqs.ChangeMessageVisibility(&sqs.ChangeMessageVisibilityInput{
QueueUrl: aws.String(q.QueueURL),
ReceiptHandle: receiptHandle,
VisibilityTimeout: aws.Int64(visibilityTimeout),
})
if err != nil {
return nil, err
}
return q.after(q.VisibilityHeartbeat / 2), nil
}
|
go
|
func (q *SQSDispatcher) extendMessageVisibilityTimeout(receiptHandle *string) (<-chan time.Time, error) {
visibilityTimeout := int64(float64(q.VisibilityHeartbeat) / float64(time.Second))
_, err := q.sqs.ChangeMessageVisibility(&sqs.ChangeMessageVisibilityInput{
QueueUrl: aws.String(q.QueueURL),
ReceiptHandle: receiptHandle,
VisibilityTimeout: aws.Int64(visibilityTimeout),
})
if err != nil {
return nil, err
}
return q.after(q.VisibilityHeartbeat / 2), nil
}
|
[
"func",
"(",
"q",
"*",
"SQSDispatcher",
")",
"extendMessageVisibilityTimeout",
"(",
"receiptHandle",
"*",
"string",
")",
"(",
"<-",
"chan",
"time",
".",
"Time",
",",
"error",
")",
"{",
"visibilityTimeout",
":=",
"int64",
"(",
"float64",
"(",
"q",
".",
"VisibilityHeartbeat",
")",
"/",
"float64",
"(",
"time",
".",
"Second",
")",
")",
"\n\n",
"_",
",",
"err",
":=",
"q",
".",
"sqs",
".",
"ChangeMessageVisibility",
"(",
"&",
"sqs",
".",
"ChangeMessageVisibilityInput",
"{",
"QueueUrl",
":",
"aws",
".",
"String",
"(",
"q",
".",
"QueueURL",
")",
",",
"ReceiptHandle",
":",
"receiptHandle",
",",
"VisibilityTimeout",
":",
"aws",
".",
"Int64",
"(",
"visibilityTimeout",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"q",
".",
"after",
"(",
"q",
".",
"VisibilityHeartbeat",
"/",
"2",
")",
",",
"nil",
"\n",
"}"
] |
// extendMessageVisibilityTimeout extends the messages visibility timeout by
// VisibilityHeartbeat, and returns a channel that will receive after half of
// VisibilityTimeout has elapsed.
|
[
"extendMessageVisibilityTimeout",
"extends",
"the",
"messages",
"visibility",
"timeout",
"by",
"VisibilityHeartbeat",
"and",
"returns",
"a",
"channel",
"that",
"will",
"receive",
"after",
"half",
"of",
"VisibilityTimeout",
"has",
"elapsed",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/cloudformation/queue.go#L155-L168
|
train
|
remind101/empire
|
pkg/heroku/app.go
|
AppCreate
|
func (c *Client) AppCreate(options *AppCreateOpts) (*App, error) {
var appRes App
return &appRes, c.Post(&appRes, "/apps", options)
}
|
go
|
func (c *Client) AppCreate(options *AppCreateOpts) (*App, error) {
var appRes App
return &appRes, c.Post(&appRes, "/apps", options)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppCreate",
"(",
"options",
"*",
"AppCreateOpts",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"var",
"appRes",
"App",
"\n",
"return",
"&",
"appRes",
",",
"c",
".",
"Post",
"(",
"&",
"appRes",
",",
"\"",
"\"",
",",
"options",
")",
"\n",
"}"
] |
// Create a new app.
//
// options is the struct of optional parameters for this action.
|
[
"Create",
"a",
"new",
"app",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app.go#L78-L81
|
train
|
remind101/empire
|
pkg/heroku/app.go
|
AppInfo
|
func (c *Client) AppInfo(appIdentity string) (*App, error) {
var app App
return &app, c.Get(&app, "/apps/"+appIdentity)
}
|
go
|
func (c *Client) AppInfo(appIdentity string) (*App, error) {
var app App
return &app, c.Get(&app, "/apps/"+appIdentity)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppInfo",
"(",
"appIdentity",
"string",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"var",
"app",
"App",
"\n",
"return",
"&",
"app",
",",
"c",
".",
"Get",
"(",
"&",
"app",
",",
"\"",
"\"",
"+",
"appIdentity",
")",
"\n",
"}"
] |
// Info for existing app.
//
// appIdentity is the unique identifier of the App.
|
[
"Info",
"for",
"existing",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"App",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app.go#L104-L107
|
train
|
remind101/empire
|
pkg/heroku/app.go
|
AppList
|
func (c *Client) AppList(lr *ListRange) ([]App, error) {
req, err := c.NewRequest("GET", "/apps", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var appsRes []App
return appsRes, c.DoReq(req, &appsRes)
}
|
go
|
func (c *Client) AppList(lr *ListRange) ([]App, error) {
req, err := c.NewRequest("GET", "/apps", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var appsRes []App
return appsRes, c.DoReq(req, &appsRes)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"App",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"lr",
"!=",
"nil",
"{",
"lr",
".",
"SetHeader",
"(",
"req",
")",
"\n",
"}",
"\n\n",
"var",
"appsRes",
"[",
"]",
"App",
"\n",
"return",
"appsRes",
",",
"c",
".",
"DoReq",
"(",
"req",
",",
"&",
"appsRes",
")",
"\n",
"}"
] |
// List existing apps.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results.
|
[
"List",
"existing",
"apps",
".",
"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.go#L113-L125
|
train
|
remind101/empire
|
pkg/heroku/app.go
|
AppUpdate
|
func (c *Client) AppUpdate(appIdentity string, options *AppUpdateOpts, message string) (*App, error) {
rh := RequestHeaders{CommitMessage: message}
var appRes App
return &appRes, c.PatchWithHeaders(&appRes, "/apps/"+appIdentity, options, rh.Headers())
}
|
go
|
func (c *Client) AppUpdate(appIdentity string, options *AppUpdateOpts, message string) (*App, error) {
rh := RequestHeaders{CommitMessage: message}
var appRes App
return &appRes, c.PatchWithHeaders(&appRes, "/apps/"+appIdentity, options, rh.Headers())
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"AppUpdate",
"(",
"appIdentity",
"string",
",",
"options",
"*",
"AppUpdateOpts",
",",
"message",
"string",
")",
"(",
"*",
"App",
",",
"error",
")",
"{",
"rh",
":=",
"RequestHeaders",
"{",
"CommitMessage",
":",
"message",
"}",
"\n",
"var",
"appRes",
"App",
"\n",
"return",
"&",
"appRes",
",",
"c",
".",
"PatchWithHeaders",
"(",
"&",
"appRes",
",",
"\"",
"\"",
"+",
"appIdentity",
",",
"options",
",",
"rh",
".",
"Headers",
"(",
")",
")",
"\n",
"}"
] |
// Update an existing app.
//
// appIdentity is the unique identifier of the App. options is the struct of
// optional parameters for this action.
|
[
"Update",
"an",
"existing",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"App",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/app.go#L131-L135
|
train
|
remind101/empire
|
pkg/image/image.go
|
Decode
|
func Decode(in string) (image Image, err error) {
repo, tag := parseRepositoryTag(in)
image.Registry, image.Repository = splitRepository(repo)
if strings.Contains(tag, ":") {
image.Digest = tag
} else {
image.Tag = tag
}
if image.Repository == "" {
err = ErrInvalidImage
return
}
return
}
|
go
|
func Decode(in string) (image Image, err error) {
repo, tag := parseRepositoryTag(in)
image.Registry, image.Repository = splitRepository(repo)
if strings.Contains(tag, ":") {
image.Digest = tag
} else {
image.Tag = tag
}
if image.Repository == "" {
err = ErrInvalidImage
return
}
return
}
|
[
"func",
"Decode",
"(",
"in",
"string",
")",
"(",
"image",
"Image",
",",
"err",
"error",
")",
"{",
"repo",
",",
"tag",
":=",
"parseRepositoryTag",
"(",
"in",
")",
"\n",
"image",
".",
"Registry",
",",
"image",
".",
"Repository",
"=",
"splitRepository",
"(",
"repo",
")",
"\n\n",
"if",
"strings",
".",
"Contains",
"(",
"tag",
",",
"\"",
"\"",
")",
"{",
"image",
".",
"Digest",
"=",
"tag",
"\n",
"}",
"else",
"{",
"image",
".",
"Tag",
"=",
"tag",
"\n",
"}",
"\n\n",
"if",
"image",
".",
"Repository",
"==",
"\"",
"\"",
"{",
"err",
"=",
"ErrInvalidImage",
"\n",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] |
// Decode decodes the string representation of an image into an Image structure.
|
[
"Decode",
"decodes",
"the",
"string",
"representation",
"of",
"an",
"image",
"into",
"an",
"Image",
"structure",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/image/image.go#L87-L103
|
train
|
remind101/empire
|
pkg/image/image.go
|
Encode
|
func Encode(image Image) string {
repo := image.Repository
if image.Registry != "" {
repo = fmt.Sprintf("%s/%s", image.Registry, repo)
}
if image.Digest != "" {
return fmt.Sprintf("%s@%s", repo, image.Digest)
} else if image.Tag != "" {
return fmt.Sprintf("%s:%s", repo, image.Tag)
}
return repo
}
|
go
|
func Encode(image Image) string {
repo := image.Repository
if image.Registry != "" {
repo = fmt.Sprintf("%s/%s", image.Registry, repo)
}
if image.Digest != "" {
return fmt.Sprintf("%s@%s", repo, image.Digest)
} else if image.Tag != "" {
return fmt.Sprintf("%s:%s", repo, image.Tag)
}
return repo
}
|
[
"func",
"Encode",
"(",
"image",
"Image",
")",
"string",
"{",
"repo",
":=",
"image",
".",
"Repository",
"\n",
"if",
"image",
".",
"Registry",
"!=",
"\"",
"\"",
"{",
"repo",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"image",
".",
"Registry",
",",
"repo",
")",
"\n",
"}",
"\n\n",
"if",
"image",
".",
"Digest",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"repo",
",",
"image",
".",
"Digest",
")",
"\n",
"}",
"else",
"if",
"image",
".",
"Tag",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"repo",
",",
"image",
".",
"Tag",
")",
"\n",
"}",
"\n\n",
"return",
"repo",
"\n",
"}"
] |
// Encode encodes an Image to it's string representation.
|
[
"Encode",
"encodes",
"an",
"Image",
"to",
"it",
"s",
"string",
"representation",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/image/image.go#L106-L119
|
train
|
remind101/empire
|
pkg/image/image.go
|
splitRepository
|
func splitRepository(fullRepo string) (registry string, path string) {
parts := strings.Split(fullRepo, "/")
if len(parts) < 2 {
return "", parts[0]
}
if len(parts) == 2 {
return "", strings.Join(parts, "/")
}
return parts[0], strings.Join(parts[1:], "/")
}
|
go
|
func splitRepository(fullRepo string) (registry string, path string) {
parts := strings.Split(fullRepo, "/")
if len(parts) < 2 {
return "", parts[0]
}
if len(parts) == 2 {
return "", strings.Join(parts, "/")
}
return parts[0], strings.Join(parts[1:], "/")
}
|
[
"func",
"splitRepository",
"(",
"fullRepo",
"string",
")",
"(",
"registry",
"string",
",",
"path",
"string",
")",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"fullRepo",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"parts",
")",
"<",
"2",
"{",
"return",
"\"",
"\"",
",",
"parts",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"parts",
")",
"==",
"2",
"{",
"return",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"parts",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"parts",
"[",
"0",
"]",
",",
"strings",
".",
"Join",
"(",
"parts",
"[",
"1",
":",
"]",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// splitRepository splits a full docker repo into registry and path segments.
|
[
"splitRepository",
"splits",
"a",
"full",
"docker",
"repo",
"into",
"registry",
"and",
"path",
"segments",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/image/image.go#L122-L134
|
train
|
remind101/empire
|
deployments.go
|
createRelease
|
func (s *deployerService) createRelease(ctx context.Context, db *gorm.DB, ss twelvefactor.StatusStream, opts DeployOpts) (*Release, error) {
app, img := opts.App, opts.Image
// If no app is specified, attempt to find the app that relates to this
// images repository, or create it if not found.
if app == nil {
var err error
app, err = appsFindOrCreateByRepo(db, img.Repository)
if err != nil {
return nil, err
}
} else {
// If the app doesn't already have a repo attached to it, we'll attach
// this image's repo.
if err := appsEnsureRepo(db, app, img.Repository); err != nil {
return nil, err
}
}
// Grab the latest config.
config, err := s.configs.Config(db, app)
if err != nil {
return nil, err
}
// Create a new slug for the docker image.
slug, err := s.slugs.Create(ctx, db, img, opts.Output)
if err != nil {
return nil, err
}
// Create a new release for the Config
// and Slug.
desc := fmt.Sprintf("Deploy %s", img.String())
desc = appendMessageToDescription(desc, opts.User, opts.Message)
r, err := s.releases.Create(ctx, db, &Release{
App: app,
Config: config,
Slug: slug,
Description: desc,
})
return r, err
}
|
go
|
func (s *deployerService) createRelease(ctx context.Context, db *gorm.DB, ss twelvefactor.StatusStream, opts DeployOpts) (*Release, error) {
app, img := opts.App, opts.Image
// If no app is specified, attempt to find the app that relates to this
// images repository, or create it if not found.
if app == nil {
var err error
app, err = appsFindOrCreateByRepo(db, img.Repository)
if err != nil {
return nil, err
}
} else {
// If the app doesn't already have a repo attached to it, we'll attach
// this image's repo.
if err := appsEnsureRepo(db, app, img.Repository); err != nil {
return nil, err
}
}
// Grab the latest config.
config, err := s.configs.Config(db, app)
if err != nil {
return nil, err
}
// Create a new slug for the docker image.
slug, err := s.slugs.Create(ctx, db, img, opts.Output)
if err != nil {
return nil, err
}
// Create a new release for the Config
// and Slug.
desc := fmt.Sprintf("Deploy %s", img.String())
desc = appendMessageToDescription(desc, opts.User, opts.Message)
r, err := s.releases.Create(ctx, db, &Release{
App: app,
Config: config,
Slug: slug,
Description: desc,
})
return r, err
}
|
[
"func",
"(",
"s",
"*",
"deployerService",
")",
"createRelease",
"(",
"ctx",
"context",
".",
"Context",
",",
"db",
"*",
"gorm",
".",
"DB",
",",
"ss",
"twelvefactor",
".",
"StatusStream",
",",
"opts",
"DeployOpts",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"app",
",",
"img",
":=",
"opts",
".",
"App",
",",
"opts",
".",
"Image",
"\n\n",
"// If no app is specified, attempt to find the app that relates to this",
"// images repository, or create it if not found.",
"if",
"app",
"==",
"nil",
"{",
"var",
"err",
"error",
"\n",
"app",
",",
"err",
"=",
"appsFindOrCreateByRepo",
"(",
"db",
",",
"img",
".",
"Repository",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// If the app doesn't already have a repo attached to it, we'll attach",
"// this image's repo.",
"if",
"err",
":=",
"appsEnsureRepo",
"(",
"db",
",",
"app",
",",
"img",
".",
"Repository",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Grab the latest config.",
"config",
",",
"err",
":=",
"s",
".",
"configs",
".",
"Config",
"(",
"db",
",",
"app",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create a new slug for the docker image.",
"slug",
",",
"err",
":=",
"s",
".",
"slugs",
".",
"Create",
"(",
"ctx",
",",
"db",
",",
"img",
",",
"opts",
".",
"Output",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Create a new release for the Config",
"// and Slug.",
"desc",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"img",
".",
"String",
"(",
")",
")",
"\n",
"desc",
"=",
"appendMessageToDescription",
"(",
"desc",
",",
"opts",
".",
"User",
",",
"opts",
".",
"Message",
")",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"releases",
".",
"Create",
"(",
"ctx",
",",
"db",
",",
"&",
"Release",
"{",
"App",
":",
"app",
",",
"Config",
":",
"config",
",",
"Slug",
":",
"slug",
",",
"Description",
":",
"desc",
",",
"}",
")",
"\n",
"return",
"r",
",",
"err",
"\n",
"}"
] |
// createRelease creates a new release that can be deployed
|
[
"createRelease",
"creates",
"a",
"new",
"release",
"that",
"can",
"be",
"deployed"
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/deployments.go#L20-L63
|
train
|
remind101/empire
|
deployments.go
|
Deploy
|
func (s *deployerService) Deploy(ctx context.Context, opts DeployOpts) (*Release, error) {
w := opts.Output
var stream twelvefactor.StatusStream
if opts.Stream {
stream = w
}
r, err := s.createInTransaction(ctx, stream, opts)
if err != nil {
return r, w.Error(err)
}
if err := w.Status(fmt.Sprintf("Created new release v%d for %s", r.Version, r.App.Name)); err != nil {
return r, err
}
if err := s.releases.Release(ctx, r, stream); err != nil {
return r, w.Error(err)
}
return r, w.Status(fmt.Sprintf("Finished processing events for release v%d of %s", r.Version, r.App.Name))
}
|
go
|
func (s *deployerService) Deploy(ctx context.Context, opts DeployOpts) (*Release, error) {
w := opts.Output
var stream twelvefactor.StatusStream
if opts.Stream {
stream = w
}
r, err := s.createInTransaction(ctx, stream, opts)
if err != nil {
return r, w.Error(err)
}
if err := w.Status(fmt.Sprintf("Created new release v%d for %s", r.Version, r.App.Name)); err != nil {
return r, err
}
if err := s.releases.Release(ctx, r, stream); err != nil {
return r, w.Error(err)
}
return r, w.Status(fmt.Sprintf("Finished processing events for release v%d of %s", r.Version, r.App.Name))
}
|
[
"func",
"(",
"s",
"*",
"deployerService",
")",
"Deploy",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"DeployOpts",
")",
"(",
"*",
"Release",
",",
"error",
")",
"{",
"w",
":=",
"opts",
".",
"Output",
"\n\n",
"var",
"stream",
"twelvefactor",
".",
"StatusStream",
"\n",
"if",
"opts",
".",
"Stream",
"{",
"stream",
"=",
"w",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"createInTransaction",
"(",
"ctx",
",",
"stream",
",",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"w",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"w",
".",
"Status",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"Version",
",",
"r",
".",
"App",
".",
"Name",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"releases",
".",
"Release",
"(",
"ctx",
",",
"r",
",",
"stream",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"w",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"r",
",",
"w",
".",
"Status",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"Version",
",",
"r",
".",
"App",
".",
"Name",
")",
")",
"\n",
"}"
] |
// Deploy is a thin wrapper around deploy to that adds the error to the
// jsonmessage stream.
|
[
"Deploy",
"is",
"a",
"thin",
"wrapper",
"around",
"deploy",
"to",
"that",
"adds",
"the",
"error",
"to",
"the",
"jsonmessage",
"stream",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/deployments.go#L77-L99
|
train
|
remind101/empire
|
deployments.go
|
Publish
|
func (w *DeploymentStream) Publish(status twelvefactor.Status) error {
return w.Status(status.Message)
}
|
go
|
func (w *DeploymentStream) Publish(status twelvefactor.Status) error {
return w.Status(status.Message)
}
|
[
"func",
"(",
"w",
"*",
"DeploymentStream",
")",
"Publish",
"(",
"status",
"twelvefactor",
".",
"Status",
")",
"error",
"{",
"return",
"w",
".",
"Status",
"(",
"status",
".",
"Message",
")",
"\n",
"}"
] |
// Publish implements the scheduler.StatusStream interface.
|
[
"Publish",
"implements",
"the",
"scheduler",
".",
"StatusStream",
"interface",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/deployments.go#L113-L115
|
train
|
remind101/empire
|
deployments.go
|
Status
|
func (w *DeploymentStream) Status(message string) error {
m := jsonmessage.JSONMessage{Status: fmt.Sprintf("Status: %s", message)}
return w.Encode(m)
}
|
go
|
func (w *DeploymentStream) Status(message string) error {
m := jsonmessage.JSONMessage{Status: fmt.Sprintf("Status: %s", message)}
return w.Encode(m)
}
|
[
"func",
"(",
"w",
"*",
"DeploymentStream",
")",
"Status",
"(",
"message",
"string",
")",
"error",
"{",
"m",
":=",
"jsonmessage",
".",
"JSONMessage",
"{",
"Status",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"message",
")",
"}",
"\n",
"return",
"w",
".",
"Encode",
"(",
"m",
")",
"\n",
"}"
] |
// Status writes a simple status update to the jsonmessage stream.
|
[
"Status",
"writes",
"a",
"simple",
"status",
"update",
"to",
"the",
"jsonmessage",
"stream",
"."
] |
3daba389f6b07b5d219246bfc7d901fcec664161
|
https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/deployments.go#L118-L121
|
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.