repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
remind101/empire | pkg/heroku/oauth_authorization.go | OAuthAuthorizationCreate | func (c *Client) OAuthAuthorizationCreate(scope []string, options *OAuthAuthorizationCreateOpts) (*OAuthAuthorization, error) {
params := struct {
Scope []string `json:"scope"`
Client *string `json:"client,omitempty"`
Description *string `json:"description,omitempty"`
ExpiresIn *int `json:"e... | go | func (c *Client) OAuthAuthorizationCreate(scope []string, options *OAuthAuthorizationCreateOpts) (*OAuthAuthorization, error) {
params := struct {
Scope []string `json:"scope"`
Client *string `json:"client,omitempty"`
Description *string `json:"description,omitempty"`
ExpiresIn *int `json:"e... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthAuthorizationCreate",
"(",
"scope",
"[",
"]",
"string",
",",
"options",
"*",
"OAuthAuthorizationCreateOpts",
")",
"(",
"*",
"OAuthAuthorization",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Scope",
"[",... | // Create a new OAuth authorization.
//
// scope is the The scope of access OAuth authorization allows. options is the
// struct of optional parameters for this action. | [
"Create",
"a",
"new",
"OAuth",
"authorization",
".",
"scope",
"is",
"the",
"The",
"scope",
"of",
"access",
"OAuth",
"authorization",
"allows",
".",
"options",
"is",
"the",
"struct",
"of",
"optional",
"parameters",
"for",
"this",
"action",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/oauth_authorization.go#L60-L76 | train |
remind101/empire | pkg/heroku/oauth_authorization.go | OAuthAuthorizationInfo | func (c *Client) OAuthAuthorizationInfo(oauthAuthorizationIdentity string) (*OAuthAuthorization, error) {
var oauthAuthorization OAuthAuthorization
return &oauthAuthorization, c.Get(&oauthAuthorization, "/oauth/authorizations/"+oauthAuthorizationIdentity)
} | go | func (c *Client) OAuthAuthorizationInfo(oauthAuthorizationIdentity string) (*OAuthAuthorization, error) {
var oauthAuthorization OAuthAuthorization
return &oauthAuthorization, c.Get(&oauthAuthorization, "/oauth/authorizations/"+oauthAuthorizationIdentity)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthAuthorizationInfo",
"(",
"oauthAuthorizationIdentity",
"string",
")",
"(",
"*",
"OAuthAuthorization",
",",
"error",
")",
"{",
"var",
"oauthAuthorization",
"OAuthAuthorization",
"\n",
"return",
"&",
"oauthAuthorization",
",... | // Info for an OAuth authorization.
//
// oauthAuthorizationIdentity is the unique identifier of the
// OAuthAuthorization. | [
"Info",
"for",
"an",
"OAuth",
"authorization",
".",
"oauthAuthorizationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OAuthAuthorization",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/oauth_authorization.go#L100-L103 | train |
remind101/empire | pkg/heroku/oauth_authorization.go | OAuthAuthorizationList | func (c *Client) OAuthAuthorizationList(lr *ListRange) ([]OAuthAuthorization, error) {
req, err := c.NewRequest("GET", "/oauth/authorizations", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var oauthAuthorizationsRes []OAuthAuthorization
return oauthAuthorizationsRes, c.DoR... | go | func (c *Client) OAuthAuthorizationList(lr *ListRange) ([]OAuthAuthorization, error) {
req, err := c.NewRequest("GET", "/oauth/authorizations", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var oauthAuthorizationsRes []OAuthAuthorization
return oauthAuthorizationsRes, c.DoR... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OAuthAuthorizationList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"OAuthAuthorization",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"... | // List OAuth authorizations.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results. | [
"List",
"OAuth",
"authorizations",
".",
"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_authorization.go#L109-L121 | train |
remind101/empire | server/heroku/authentication.go | ExpiresIn | func (t *AccessToken) ExpiresIn() time.Duration {
if t.ExpiresAt == nil {
return 0
}
return t.ExpiresAt.Sub(time.Now())
} | go | func (t *AccessToken) ExpiresIn() time.Duration {
if t.ExpiresAt == nil {
return 0
}
return t.ExpiresAt.Sub(time.Now())
} | [
"func",
"(",
"t",
"*",
"AccessToken",
")",
"ExpiresIn",
"(",
")",
"time",
".",
"Duration",
"{",
"if",
"t",
".",
"ExpiresAt",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n\n",
"return",
"t",
".",
"ExpiresAt",
".",
"Sub",
"(",
"time",
".",
"Now",
... | // Returns the amount of time before the token expires. | [
"Returns",
"the",
"amount",
"of",
"time",
"before",
"the",
"token",
"expires",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L32-L38 | train |
remind101/empire | server/heroku/authentication.go | IsValid | func (t *AccessToken) IsValid() error {
if err := t.User.IsValid(); err != nil {
return err
}
return nil
} | go | func (t *AccessToken) IsValid() error {
if err := t.User.IsValid(); err != nil {
return err
}
return nil
} | [
"func",
"(",
"t",
"*",
"AccessToken",
")",
"IsValid",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"t",
".",
"User",
".",
"IsValid",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // IsValid returns nil if the AccessToken is valid. | [
"IsValid",
"returns",
"nil",
"if",
"the",
"AccessToken",
"is",
"valid",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L41-L47 | train |
remind101/empire | server/heroku/authentication.go | Authenticate | func (a *accessTokenAuthenticator) Authenticate(_ string, token string, _ string) (*auth.Session, error) {
at, err := a.findAccessToken(token)
if err != nil {
return nil, err
}
if at == nil {
return nil, auth.ErrForbidden
}
session := &auth.Session{
User: at.User,
ExpiresAt: at.ExpiresAt,
}
retu... | go | func (a *accessTokenAuthenticator) Authenticate(_ string, token string, _ string) (*auth.Session, error) {
at, err := a.findAccessToken(token)
if err != nil {
return nil, err
}
if at == nil {
return nil, auth.ErrForbidden
}
session := &auth.Session{
User: at.User,
ExpiresAt: at.ExpiresAt,
}
retu... | [
"func",
"(",
"a",
"*",
"accessTokenAuthenticator",
")",
"Authenticate",
"(",
"_",
"string",
",",
"token",
"string",
",",
"_",
"string",
")",
"(",
"*",
"auth",
".",
"Session",
",",
"error",
")",
"{",
"at",
",",
"err",
":=",
"a",
".",
"findAccessToken",
... | // Authenticate authenticates the access token, which should be provided as the
// password parameter. Username and otp are ignored. | [
"Authenticate",
"authenticates",
"the",
"access",
"token",
"which",
"should",
"be",
"provided",
"as",
"the",
"password",
"parameter",
".",
"Username",
"and",
"otp",
"are",
"ignored",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L143-L159 | train |
remind101/empire | server/heroku/authentication.go | AccessTokensCreate | func (s *Server) AccessTokensCreate(token *AccessToken) (*AccessToken, error) {
signed, err := signToken(s.Secret, token)
if err != nil {
return token, err
}
token.Token = signed
return token, token.IsValid()
} | go | func (s *Server) AccessTokensCreate(token *AccessToken) (*AccessToken, error) {
signed, err := signToken(s.Secret, token)
if err != nil {
return token, err
}
token.Token = signed
return token, token.IsValid()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"AccessTokensCreate",
"(",
"token",
"*",
"AccessToken",
")",
"(",
"*",
"AccessToken",
",",
"error",
")",
"{",
"signed",
",",
"err",
":=",
"signToken",
"(",
"s",
".",
"Secret",
",",
"token",
")",
"\n",
"if",
"err"... | // AccessTokensCreate "creates" the token by jwt signing it and setting the
// Token value. | [
"AccessTokensCreate",
"creates",
"the",
"token",
"by",
"jwt",
"signing",
"it",
"and",
"setting",
"the",
"Token",
"value",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L163-L172 | train |
remind101/empire | server/heroku/authentication.go | signToken | func signToken(secret []byte, token *AccessToken) (string, error) {
t := accessTokenToJwt(token)
return t.SignedString(secret)
} | go | func signToken(secret []byte, token *AccessToken) (string, error) {
t := accessTokenToJwt(token)
return t.SignedString(secret)
} | [
"func",
"signToken",
"(",
"secret",
"[",
"]",
"byte",
",",
"token",
"*",
"AccessToken",
")",
"(",
"string",
",",
"error",
")",
"{",
"t",
":=",
"accessTokenToJwt",
"(",
"token",
")",
"\n",
"return",
"t",
".",
"SignedString",
"(",
"secret",
")",
"\n",
... | // signToken jwt signs the token and adds the signature to the Token field. | [
"signToken",
"jwt",
"signs",
"the",
"token",
"and",
"adds",
"the",
"signature",
"to",
"the",
"Token",
"field",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L193-L196 | train |
remind101/empire | server/heroku/authentication.go | parseToken | func parseToken(secret []byte, token string) (*AccessToken, error) {
t, err := jwtParse(secret, token)
if err != nil {
return nil, err
}
if !t.Valid {
return nil, nil
}
return jwtToAccessToken(t)
} | go | func parseToken(secret []byte, token string) (*AccessToken, error) {
t, err := jwtParse(secret, token)
if err != nil {
return nil, err
}
if !t.Valid {
return nil, nil
}
return jwtToAccessToken(t)
} | [
"func",
"parseToken",
"(",
"secret",
"[",
"]",
"byte",
",",
"token",
"string",
")",
"(",
"*",
"AccessToken",
",",
"error",
")",
"{",
"t",
",",
"err",
":=",
"jwtParse",
"(",
"secret",
",",
"token",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // parseToken parses a string token, verifies it, and returns an AccessToken
// instance. | [
"parseToken",
"parses",
"a",
"string",
"token",
"verifies",
"it",
"and",
"returns",
"an",
"AccessToken",
"instance",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L200-L212 | train |
remind101/empire | server/heroku/authentication.go | jwtToAccessToken | func jwtToAccessToken(t *jwt.Token) (*AccessToken, error) {
var token AccessToken
if t.Claims["exp"] != nil {
exp := time.Unix(int64(t.Claims["exp"].(float64)), 0).UTC()
token.ExpiresAt = &exp
}
if u, ok := t.Claims["User"].(map[string]interface{}); ok {
var user empire.User
if n, ok := u["Name"].(string... | go | func jwtToAccessToken(t *jwt.Token) (*AccessToken, error) {
var token AccessToken
if t.Claims["exp"] != nil {
exp := time.Unix(int64(t.Claims["exp"].(float64)), 0).UTC()
token.ExpiresAt = &exp
}
if u, ok := t.Claims["User"].(map[string]interface{}); ok {
var user empire.User
if n, ok := u["Name"].(string... | [
"func",
"jwtToAccessToken",
"(",
"t",
"*",
"jwt",
".",
"Token",
")",
"(",
"*",
"AccessToken",
",",
"error",
")",
"{",
"var",
"token",
"AccessToken",
"\n\n",
"if",
"t",
".",
"Claims",
"[",
"\"",
"\"",
"]",
"!=",
"nil",
"{",
"exp",
":=",
"time",
".",... | // jwtToAccessTokens maps a jwt.Token to an AccessToken. | [
"jwtToAccessTokens",
"maps",
"a",
"jwt",
".",
"Token",
"to",
"an",
"AccessToken",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/heroku/authentication.go#L231-L260 | train |
remind101/empire | pkg/heroku/domain.go | DomainCreate | func (c *Client) DomainCreate(appIdentity string, hostname string) (*Domain, error) {
params := struct {
Hostname string `json:"hostname"`
}{
Hostname: hostname,
}
var domainRes Domain
return &domainRes, c.Post(&domainRes, "/apps/"+appIdentity+"/domains", params)
} | go | func (c *Client) DomainCreate(appIdentity string, hostname string) (*Domain, error) {
params := struct {
Hostname string `json:"hostname"`
}{
Hostname: hostname,
}
var domainRes Domain
return &domainRes, c.Post(&domainRes, "/apps/"+appIdentity+"/domains", params)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DomainCreate",
"(",
"appIdentity",
"string",
",",
"hostname",
"string",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Hostname",
"string",
"`json:\"hostname\"`",
"\n",
"}",
"{",
"H... | // Create a new domain.
//
// appIdentity is the unique identifier of the Domain's App. hostname is the
// full hostname. | [
"Create",
"a",
"new",
"domain",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Domain",
"s",
"App",
".",
"hostname",
"is",
"the",
"full",
"hostname",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/domain.go#L30-L38 | train |
remind101/empire | pkg/heroku/domain.go | DomainDelete | func (c *Client) DomainDelete(appIdentity string, domainIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/domains/" + domainIdentity)
} | go | func (c *Client) DomainDelete(appIdentity string, domainIdentity string) error {
return c.Delete("/apps/" + appIdentity + "/domains/" + domainIdentity)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DomainDelete",
"(",
"appIdentity",
"string",
",",
"domainIdentity",
"string",
")",
"error",
"{",
"return",
"c",
".",
"Delete",
"(",
"\"",
"\"",
"+",
"appIdentity",
"+",
"\"",
"\"",
"+",
"domainIdentity",
")",
"\n",
... | // Delete an existing domain
//
// appIdentity is the unique identifier of the Domain's App. domainIdentity is
// the unique identifier of the Domain. | [
"Delete",
"an",
"existing",
"domain",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Domain",
"s",
"App",
".",
"domainIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Domain",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/domain.go#L44-L46 | train |
remind101/empire | pkg/heroku/domain.go | DomainInfo | func (c *Client) DomainInfo(appIdentity string, domainIdentity string) (*Domain, error) {
var domain Domain
return &domain, c.Get(&domain, "/apps/"+appIdentity+"/domains/"+domainIdentity)
} | go | func (c *Client) DomainInfo(appIdentity string, domainIdentity string) (*Domain, error) {
var domain Domain
return &domain, c.Get(&domain, "/apps/"+appIdentity+"/domains/"+domainIdentity)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DomainInfo",
"(",
"appIdentity",
"string",
",",
"domainIdentity",
"string",
")",
"(",
"*",
"Domain",
",",
"error",
")",
"{",
"var",
"domain",
"Domain",
"\n",
"return",
"&",
"domain",
",",
"c",
".",
"Get",
"(",
"... | // Info for existing domain.
//
// appIdentity is the unique identifier of the Domain's App. domainIdentity is
// the unique identifier of the Domain. | [
"Info",
"for",
"existing",
"domain",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Domain",
"s",
"App",
".",
"domainIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Domain",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/domain.go#L52-L55 | train |
remind101/empire | pkg/heroku/domain.go | DomainList | func (c *Client) DomainList(appIdentity string, lr *ListRange) ([]Domain, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/domains", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var domainsRes []Domain
return domainsRes, c.DoReq(req, &domainsRes)
} | go | func (c *Client) DomainList(appIdentity string, lr *ListRange) ([]Domain, error) {
req, err := c.NewRequest("GET", "/apps/"+appIdentity+"/domains", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var domainsRes []Domain
return domainsRes, c.DoReq(req, &domainsRes)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DomainList",
"(",
"appIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"Domain",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\""... | // List existing domains.
//
// appIdentity is the unique identifier of the Domain's App. lr is an optional
// ListRange that sets the Range options for the paginated list of results. | [
"List",
"existing",
"domains",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"Domain",
"s",
"App",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginated",
"list",
"of",
"... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/domain.go#L61-L73 | train |
remind101/empire | pkg/stream/http/http.go | StreamingResponseWriter | func StreamingResponseWriter(w http.ResponseWriter) *ResponseWriter {
fw, err := newFlushWriter(w)
if err != nil {
panic(err)
}
return &ResponseWriter{
ResponseWriter: w,
w: fw,
}
} | go | func StreamingResponseWriter(w http.ResponseWriter) *ResponseWriter {
fw, err := newFlushWriter(w)
if err != nil {
panic(err)
}
return &ResponseWriter{
ResponseWriter: w,
w: fw,
}
} | [
"func",
"StreamingResponseWriter",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"*",
"ResponseWriter",
"{",
"fw",
",",
"err",
":=",
"newFlushWriter",
"(",
"w",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"ret... | // StreamingResponseWriter wraps the http.ResponseWriter with unbuffered
// streaming. If the provided ResponseWriter does not implement http.Flusher,
// this function will panic. | [
"StreamingResponseWriter",
"wraps",
"the",
"http",
".",
"ResponseWriter",
"with",
"unbuffered",
"streaming",
".",
"If",
"the",
"provided",
"ResponseWriter",
"does",
"not",
"implement",
"http",
".",
"Flusher",
"this",
"function",
"will",
"panic",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/stream/http/http.go#L23-L33 | train |
remind101/empire | pkg/stream/http/http.go | Write | func (w *ResponseWriter) Write(p []byte) (int, error) {
return w.w.Write(p)
} | go | func (w *ResponseWriter) Write(p []byte) (int, error) {
return w.w.Write(p)
} | [
"func",
"(",
"w",
"*",
"ResponseWriter",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"return",
"w",
".",
"w",
".",
"Write",
"(",
"p",
")",
"\n",
"}"
] | // Write delegates to the underlying flushWriter to perform the write and flush
// it to the connection. | [
"Write",
"delegates",
"to",
"the",
"underlying",
"flushWriter",
"to",
"perform",
"the",
"write",
"and",
"flush",
"it",
"to",
"the",
"connection",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/stream/http/http.go#L37-L39 | train |
remind101/empire | pkg/stream/http/http.go | Heartbeat | func Heartbeat(outStream io.Writer, interval time.Duration) chan struct{} {
stop := make(chan struct{})
t := time.NewTicker(interval)
go func() {
for {
select {
case <-t.C:
fmt.Fprintf(outStream, "\x00")
continue
case <-stop:
t.Stop()
return
}
}
}()
return stop
} | go | func Heartbeat(outStream io.Writer, interval time.Duration) chan struct{} {
stop := make(chan struct{})
t := time.NewTicker(interval)
go func() {
for {
select {
case <-t.C:
fmt.Fprintf(outStream, "\x00")
continue
case <-stop:
t.Stop()
return
}
}
}()
return stop
} | [
"func",
"Heartbeat",
"(",
"outStream",
"io",
".",
"Writer",
",",
"interval",
"time",
".",
"Duration",
")",
"chan",
"struct",
"{",
"}",
"{",
"stop",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"t",
":=",
"time",
".",
"NewTicker",
"(",
... | // Heartbeat sends the null character periodically, to keep the connection alive. | [
"Heartbeat",
"sends",
"the",
"null",
"character",
"periodically",
"to",
"keep",
"the",
"connection",
"alive",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/stream/http/http.go#L67-L85 | train |
remind101/empire | scheduler/cloudformation/template.go | taskDefinitionResourceType | func taskDefinitionResourceType(app *twelvefactor.Manifest) string {
check := []string{
"EMPIRE_X_TASK_DEFINITION_TYPE",
"ECS_TASK_DEFINITION", // For backwards compatibility.
}
for _, n := range check {
if v, ok := app.Env[n]; ok {
if v == "custom" {
return "Custom::ECSTaskDefinition"
}
}
}
//... | go | func taskDefinitionResourceType(app *twelvefactor.Manifest) string {
check := []string{
"EMPIRE_X_TASK_DEFINITION_TYPE",
"ECS_TASK_DEFINITION", // For backwards compatibility.
}
for _, n := range check {
if v, ok := app.Env[n]; ok {
if v == "custom" {
return "Custom::ECSTaskDefinition"
}
}
}
//... | [
"func",
"taskDefinitionResourceType",
"(",
"app",
"*",
"twelvefactor",
".",
"Manifest",
")",
"string",
"{",
"check",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"// For backwards compatibility.",
"}",
"\n\n",
"for",
"_",
",",
"n",
":="... | // Returns the name of the CloudFormation resource that should be used to create
// custom task definitions. | [
"Returns",
"the",
"name",
"of",
"the",
"CloudFormation",
"resource",
"that",
"should",
"be",
"used",
"to",
"create",
"custom",
"task",
"definitions",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L59-L75 | train |
remind101/empire | scheduler/cloudformation/template.go | Validate | func (t *EmpireTemplate) Validate() error {
r := func(n string) error {
return errors.New(fmt.Sprintf("%s is required", n))
}
if t.VpcId == "" {
return r("VpcId")
}
if t.Cluster == "" {
return r("Cluster")
}
if t.ServiceRole == "" {
return r("ServiceRole")
}
if t.HostedZone == nil {
return r("Hosted... | go | func (t *EmpireTemplate) Validate() error {
r := func(n string) error {
return errors.New(fmt.Sprintf("%s is required", n))
}
if t.VpcId == "" {
return r("VpcId")
}
if t.Cluster == "" {
return r("Cluster")
}
if t.ServiceRole == "" {
return r("ServiceRole")
}
if t.HostedZone == nil {
return r("Hosted... | [
"func",
"(",
"t",
"*",
"EmpireTemplate",
")",
"Validate",
"(",
")",
"error",
"{",
"r",
":=",
"func",
"(",
"n",
"string",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"n",
")",
")",
"\n",
"... | // Validate checks that all of the expected values are provided. | [
"Validate",
"checks",
"that",
"all",
"of",
"the",
"expected",
"values",
"are",
"provided",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L150-L184 | train |
remind101/empire | scheduler/cloudformation/template.go | Execute | func (t *EmpireTemplate) Execute(w io.Writer, data interface{}) error {
v, err := t.Build(data.(*TemplateData))
if err != nil {
return err
}
if t.NoCompress {
raw, err := json.MarshalIndent(v, "", " ")
if err != nil {
return err
}
_, err = io.Copy(w, bytes.NewReader(raw))
return err
}
return js... | go | func (t *EmpireTemplate) Execute(w io.Writer, data interface{}) error {
v, err := t.Build(data.(*TemplateData))
if err != nil {
return err
}
if t.NoCompress {
raw, err := json.MarshalIndent(v, "", " ")
if err != nil {
return err
}
_, err = io.Copy(w, bytes.NewReader(raw))
return err
}
return js... | [
"func",
"(",
"t",
"*",
"EmpireTemplate",
")",
"Execute",
"(",
"w",
"io",
".",
"Writer",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"v",
",",
"err",
":=",
"t",
".",
"Build",
"(",
"data",
".",
"(",
"*",
"TemplateData",
")",
")",
"\n",
... | // Execute builds the template, and writes it to w. | [
"Execute",
"builds",
"the",
"template",
"and",
"writes",
"it",
"to",
"w",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L187-L204 | train |
remind101/empire | scheduler/cloudformation/template.go | Build | func (t *EmpireTemplate) Build(data *TemplateData) (*troposphere.Template, error) {
app := data.Manifest
tmpl := troposphere.NewTemplate()
tmpl.Parameters["DNS"] = troposphere.Parameter{
Type: "String",
Description: "When set to `true`, CNAME's will be altered",
Default: "true",
}
tmpl.Parameter... | go | func (t *EmpireTemplate) Build(data *TemplateData) (*troposphere.Template, error) {
app := data.Manifest
tmpl := troposphere.NewTemplate()
tmpl.Parameters["DNS"] = troposphere.Parameter{
Type: "String",
Description: "When set to `true`, CNAME's will be altered",
Default: "true",
}
tmpl.Parameter... | [
"func",
"(",
"t",
"*",
"EmpireTemplate",
")",
"Build",
"(",
"data",
"*",
"TemplateData",
")",
"(",
"*",
"troposphere",
".",
"Template",
",",
"error",
")",
"{",
"app",
":=",
"data",
".",
"Manifest",
"\n\n",
"tmpl",
":=",
"troposphere",
".",
"NewTemplate",... | // Build builds a Go representation of a CloudFormation template for the app. | [
"Build",
"builds",
"a",
"Go",
"representation",
"of",
"a",
"CloudFormation",
"template",
"for",
"the",
"app",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L207-L276 | train |
remind101/empire | scheduler/cloudformation/template.go | serviceRoleArn | func (t *EmpireTemplate) serviceRoleArn() interface{} {
if _, err := arn.Parse(t.ServiceRole); err == nil {
return t.ServiceRole
}
return Join("", "arn:aws:iam::", Ref("AWS::AccountId"), ":role/", t.ServiceRole)
} | go | func (t *EmpireTemplate) serviceRoleArn() interface{} {
if _, err := arn.Parse(t.ServiceRole); err == nil {
return t.ServiceRole
}
return Join("", "arn:aws:iam::", Ref("AWS::AccountId"), ":role/", t.ServiceRole)
} | [
"func",
"(",
"t",
"*",
"EmpireTemplate",
")",
"serviceRoleArn",
"(",
")",
"interface",
"{",
"}",
"{",
"if",
"_",
",",
"err",
":=",
"arn",
".",
"Parse",
"(",
"t",
".",
"ServiceRole",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"t",
".",
"ServiceRol... | // If the ServiceRole option is not an ARN, it will return a CloudFormation
// expression that expands the ServiceRole to an ARN. | [
"If",
"the",
"ServiceRole",
"option",
"is",
"not",
"an",
"ARN",
"it",
"will",
"return",
"a",
"CloudFormation",
"expression",
"that",
"expands",
"the",
"ServiceRole",
"to",
"an",
"ARN",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L738-L743 | train |
remind101/empire | scheduler/cloudformation/template.go | ContainerDefinition | func (t *EmpireTemplate) ContainerDefinition(app *twelvefactor.Manifest, p *twelvefactor.Process) *ecs.ContainerDefinition {
command := []*string{}
for _, s := range p.Command {
ss := s
command = append(command, &ss)
}
labels := make(map[string]*string)
for k, v := range twelvefactor.Labels(app, p) {
labels... | go | func (t *EmpireTemplate) ContainerDefinition(app *twelvefactor.Manifest, p *twelvefactor.Process) *ecs.ContainerDefinition {
command := []*string{}
for _, s := range p.Command {
ss := s
command = append(command, &ss)
}
labels := make(map[string]*string)
for k, v := range twelvefactor.Labels(app, p) {
labels... | [
"func",
"(",
"t",
"*",
"EmpireTemplate",
")",
"ContainerDefinition",
"(",
"app",
"*",
"twelvefactor",
".",
"Manifest",
",",
"p",
"*",
"twelvefactor",
".",
"Process",
")",
"*",
"ecs",
".",
"ContainerDefinition",
"{",
"command",
":=",
"[",
"]",
"*",
"string"... | // ContainerDefinition generates an ECS ContainerDefinition for a process. | [
"ContainerDefinition",
"generates",
"an",
"ECS",
"ContainerDefinition",
"for",
"a",
"process",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L754-L789 | train |
remind101/empire | scheduler/cloudformation/template.go | HostedZone | func HostedZone(config client.ConfigProvider, hostedZoneID string) (*route53.HostedZone, error) {
r := route53.New(config)
zid := fixHostedZoneIDPrefix(hostedZoneID)
out, err := r.GetHostedZone(&route53.GetHostedZoneInput{Id: zid})
if err != nil {
return nil, err
}
return out.HostedZone, nil
} | go | func HostedZone(config client.ConfigProvider, hostedZoneID string) (*route53.HostedZone, error) {
r := route53.New(config)
zid := fixHostedZoneIDPrefix(hostedZoneID)
out, err := r.GetHostedZone(&route53.GetHostedZoneInput{Id: zid})
if err != nil {
return nil, err
}
return out.HostedZone, nil
} | [
"func",
"HostedZone",
"(",
"config",
"client",
".",
"ConfigProvider",
",",
"hostedZoneID",
"string",
")",
"(",
"*",
"route53",
".",
"HostedZone",
",",
"error",
")",
"{",
"r",
":=",
"route53",
".",
"New",
"(",
"config",
")",
"\n",
"zid",
":=",
"fixHostedZ... | // HostedZone returns the HostedZone for the ZoneID. | [
"HostedZone",
"returns",
"the",
"HostedZone",
"for",
"the",
"ZoneID",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L792-L801 | train |
remind101/empire | scheduler/cloudformation/template.go | cloudformationContainerDefinition | func cloudformationContainerDefinition(cd *ecs.ContainerDefinition) *ContainerDefinitionProperties {
labels := make(map[string]interface{})
for k, v := range cd.DockerLabels {
labels[k] = *v
}
c := &ContainerDefinitionProperties{
Name: *cd.Name,
Command: cd.Command,
Cpu: *cd.Cpu,
Im... | go | func cloudformationContainerDefinition(cd *ecs.ContainerDefinition) *ContainerDefinitionProperties {
labels := make(map[string]interface{})
for k, v := range cd.DockerLabels {
labels[k] = *v
}
c := &ContainerDefinitionProperties{
Name: *cd.Name,
Command: cd.Command,
Cpu: *cd.Cpu,
Im... | [
"func",
"cloudformationContainerDefinition",
"(",
"cd",
"*",
"ecs",
".",
"ContainerDefinition",
")",
"*",
"ContainerDefinitionProperties",
"{",
"labels",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"for",
"k",
",",
"v",
":... | // cloudformationContainerDefinition returns the CloudFormation representation
// of a ecs.ContainerDefinition. | [
"cloudformationContainerDefinition",
"returns",
"the",
"CloudFormation",
"representation",
"of",
"a",
"ecs",
".",
"ContainerDefinition",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L830-L851 | train |
remind101/empire | scheduler/cloudformation/template.go | runTaskResource | func runTaskResource(role interface{}) troposphere.Resource {
return troposphere.Resource{
Type: "AWS::Lambda::Function",
Properties: map[string]interface{}{
"Description": fmt.Sprintf("Lambda function to run an ECS task"),
"Handler": "index.handler",
"Role": role,
"Runtime": "python2.7"... | go | func runTaskResource(role interface{}) troposphere.Resource {
return troposphere.Resource{
Type: "AWS::Lambda::Function",
Properties: map[string]interface{}{
"Description": fmt.Sprintf("Lambda function to run an ECS task"),
"Handler": "index.handler",
"Role": role,
"Runtime": "python2.7"... | [
"func",
"runTaskResource",
"(",
"role",
"interface",
"{",
"}",
")",
"troposphere",
".",
"Resource",
"{",
"return",
"troposphere",
".",
"Resource",
"{",
"Type",
":",
"\"",
"\"",
",",
"Properties",
":",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{"... | // runTaskResource returns a troposphere resource that will create a lambda
// function that can be used to run an ECS task. | [
"runTaskResource",
"returns",
"a",
"troposphere",
"resource",
"that",
"will",
"create",
"a",
"lambda",
"function",
"that",
"can",
"be",
"used",
"to",
"run",
"an",
"ECS",
"task",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L885-L898 | train |
remind101/empire | scheduler/cloudformation/template.go | tagsFromLabels | func tagsFromLabels(labels map[string]string) []*cloudformation.Tag {
tags := cloudformationTags{}
for k, v := range labels {
tags = append(tags, &cloudformation.Tag{Key: aws.String(k), Value: aws.String(v)})
}
sort.Sort(tags)
return tags
} | go | func tagsFromLabels(labels map[string]string) []*cloudformation.Tag {
tags := cloudformationTags{}
for k, v := range labels {
tags = append(tags, &cloudformation.Tag{Key: aws.String(k), Value: aws.String(v)})
}
sort.Sort(tags)
return tags
} | [
"func",
"tagsFromLabels",
"(",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"[",
"]",
"*",
"cloudformation",
".",
"Tag",
"{",
"tags",
":=",
"cloudformationTags",
"{",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"labels",
"{",
"tags",
"=",
... | // tagsFromLabels generates a list of CloudFormation tags from the labels, it
// also sorts the tags by key. | [
"tagsFromLabels",
"generates",
"a",
"list",
"of",
"CloudFormation",
"tags",
"from",
"the",
"labels",
"it",
"also",
"sorts",
"the",
"tags",
"by",
"key",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/cloudformation/template.go#L922-L929 | train |
remind101/empire | events.go | AsyncEvents | func AsyncEvents(e EventStream) EventStream {
s := &asyncEventStream{
e: e,
events: make(chan Event, 100),
}
go s.start()
return s
} | go | func AsyncEvents(e EventStream) EventStream {
s := &asyncEventStream{
e: e,
events: make(chan Event, 100),
}
go s.start()
return s
} | [
"func",
"AsyncEvents",
"(",
"e",
"EventStream",
")",
"EventStream",
"{",
"s",
":=",
"&",
"asyncEventStream",
"{",
"e",
":",
"e",
",",
"events",
":",
"make",
"(",
"chan",
"Event",
",",
"100",
")",
",",
"}",
"\n",
"go",
"s",
".",
"start",
"(",
")",
... | // AsyncEvents returns a new AsyncEventStream that will buffer upto 100 events
// before applying backpressure. | [
"AsyncEvents",
"returns",
"a",
"new",
"AsyncEventStream",
"that",
"will",
"buffer",
"upto",
"100",
"events",
"before",
"applying",
"backpressure",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/events.go#L355-L362 | train |
remind101/empire | server/auth/github/client.go | NewClient | func NewClient(config *oauth2.Config) *Client {
return &Client{
Config: config,
backoff: backoff,
}
} | go | func NewClient(config *oauth2.Config) *Client {
return &Client{
Config: config,
backoff: backoff,
}
} | [
"func",
"NewClient",
"(",
"config",
"*",
"oauth2",
".",
"Config",
")",
"*",
"Client",
"{",
"return",
"&",
"Client",
"{",
"Config",
":",
"config",
",",
"backoff",
":",
"backoff",
",",
"}",
"\n",
"}"
] | // NewClient returns a new Client instance that uses the given oauth2 config. | [
"NewClient",
"returns",
"a",
"new",
"Client",
"instance",
"that",
"uses",
"the",
"given",
"oauth2",
"config",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/github/client.go#L80-L85 | train |
remind101/empire | server/auth/github/client.go | IsOrganizationMember | func (c *Client) IsOrganizationMember(organization, token string) (bool, error) {
req, err := c.NewRequest("HEAD", fmt.Sprintf("/user/memberships/orgs/%s", organization), nil)
if err != nil {
return false, err
}
tokenAuth(req, token)
resp, err := c.Do(req, nil)
if err != nil {
if resp != nil && resp.StatusC... | go | func (c *Client) IsOrganizationMember(organization, token string) (bool, error) {
req, err := c.NewRequest("HEAD", fmt.Sprintf("/user/memberships/orgs/%s", organization), nil)
if err != nil {
return false, err
}
tokenAuth(req, token)
resp, err := c.Do(req, nil)
if err != nil {
if resp != nil && resp.StatusC... | [
"func",
"(",
"c",
"*",
"Client",
")",
"IsOrganizationMember",
"(",
"organization",
",",
"token",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
... | // IsOrganizationMember returns true of the authenticated user is a member of the
// organization. | [
"IsOrganizationMember",
"returns",
"true",
"of",
"the",
"authenticated",
"user",
"is",
"a",
"member",
"of",
"the",
"organization",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/github/client.go#L172-L189 | train |
remind101/empire | server/auth/github/client.go | IsTeamMember | func (c *Client) IsTeamMember(teamID, token string) (bool, error) {
u, err := c.GetUser(token)
if err != nil {
return false, err
}
req, err := c.NewRequest("GET", fmt.Sprintf("/teams/%s/memberships/%s", teamID, u.Login), nil)
if err != nil {
return false, err
}
tokenAuth(req, token)
var t TeamMembership
... | go | func (c *Client) IsTeamMember(teamID, token string) (bool, error) {
u, err := c.GetUser(token)
if err != nil {
return false, err
}
req, err := c.NewRequest("GET", fmt.Sprintf("/teams/%s/memberships/%s", teamID, u.Login), nil)
if err != nil {
return false, err
}
tokenAuth(req, token)
var t TeamMembership
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"IsTeamMember",
"(",
"teamID",
",",
"token",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"c",
".",
"GetUser",
"(",
"token",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // IsTeamMember returns true if the given user is a member of the team. | [
"IsTeamMember",
"returns",
"true",
"if",
"the",
"given",
"user",
"is",
"a",
"member",
"of",
"the",
"team",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/server/auth/github/client.go#L192-L216 | train |
remind101/empire | pkg/heroku/organization_app.go | OrganizationAppCreate | func (c *Client) OrganizationAppCreate(options *OrganizationAppCreateOpts, message string) (*OrganizationApp, error) {
rh := RequestHeaders{CommitMessage: message}
var organizationAppRes OrganizationApp
return &organizationAppRes, c.PostWithHeaders(&organizationAppRes, "/organizations/apps", options, rh.Headers())
} | go | func (c *Client) OrganizationAppCreate(options *OrganizationAppCreateOpts, message string) (*OrganizationApp, error) {
rh := RequestHeaders{CommitMessage: message}
var organizationAppRes OrganizationApp
return &organizationAppRes, c.PostWithHeaders(&organizationAppRes, "/organizations/apps", options, rh.Headers())
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppCreate",
"(",
"options",
"*",
"OrganizationAppCreateOpts",
",",
"message",
"string",
")",
"(",
"*",
"OrganizationApp",
",",
"error",
")",
"{",
"rh",
":=",
"RequestHeaders",
"{",
"CommitMessage",
":",
"messa... | // Create a new app in the specified organization, in the default organization
// if unspecified, or in personal account, if default organization is not set.
//
// options is the struct of optional parameters for this action. | [
"Create",
"a",
"new",
"app",
"in",
"the",
"specified",
"organization",
"in",
"the",
"default",
"organization",
"if",
"unspecified",
"or",
"in",
"personal",
"account",
"if",
"default",
"organization",
"is",
"not",
"set",
".",
"options",
"is",
"the",
"struct",
... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app.go#L84-L88 | train |
remind101/empire | pkg/heroku/organization_app.go | OrganizationAppList | func (c *Client) OrganizationAppList(lr *ListRange) ([]OrganizationApp, error) {
req, err := c.NewRequest("GET", "/organizations/apps", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationAppsRes []OrganizationApp
return organizationAppsRes, c.DoReq(req, &organiza... | go | func (c *Client) OrganizationAppList(lr *ListRange) ([]OrganizationApp, error) {
req, err := c.NewRequest("GET", "/organizations/apps", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationAppsRes []OrganizationApp
return organizationAppsRes, c.DoReq(req, &organiza... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppList",
"(",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"OrganizationApp",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
... | // List apps in the default organization, or in personal account, if default
// organization is not set.
//
// lr is an optional ListRange that sets the Range options for the paginated
// list of results. | [
"List",
"apps",
"in",
"the",
"default",
"organization",
"or",
"in",
"personal",
"account",
"if",
"default",
"organization",
"is",
"not",
"set",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"paginate... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app.go#L111-L123 | train |
remind101/empire | pkg/heroku/organization_app.go | OrganizationAppListForOrganization | func (c *Client) OrganizationAppListForOrganization(organizationIdentity string, lr *ListRange) ([]OrganizationApp, error) {
req, err := c.NewRequest("GET", "/organizations/"+organizationIdentity+"/apps", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationAppsRes ... | go | func (c *Client) OrganizationAppListForOrganization(organizationIdentity string, lr *ListRange) ([]OrganizationApp, error) {
req, err := c.NewRequest("GET", "/organizations/"+organizationIdentity+"/apps", nil, nil)
if err != nil {
return nil, err
}
if lr != nil {
lr.SetHeader(req)
}
var organizationAppsRes ... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppListForOrganization",
"(",
"organizationIdentity",
"string",
",",
"lr",
"*",
"ListRange",
")",
"(",
"[",
"]",
"OrganizationApp",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"c",
".",
"NewRequest",
... | // List organization apps.
//
// organizationIdentity is the unique identifier of the OrganizationApp's
// Organization. lr is an optional ListRange that sets the Range options for the
// paginated list of results. | [
"List",
"organization",
"apps",
".",
"organizationIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationApp",
"s",
"Organization",
".",
"lr",
"is",
"an",
"optional",
"ListRange",
"that",
"sets",
"the",
"Range",
"options",
"for",
"the",
"pagin... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app.go#L130-L142 | train |
remind101/empire | pkg/heroku/organization_app.go | OrganizationAppInfo | func (c *Client) OrganizationAppInfo(appIdentity string) (*OrganizationApp, error) {
var organizationApp OrganizationApp
return &organizationApp, c.Get(&organizationApp, "/organizations/apps/"+appIdentity)
} | go | func (c *Client) OrganizationAppInfo(appIdentity string) (*OrganizationApp, error) {
var organizationApp OrganizationApp
return &organizationApp, c.Get(&organizationApp, "/organizations/apps/"+appIdentity)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppInfo",
"(",
"appIdentity",
"string",
")",
"(",
"*",
"OrganizationApp",
",",
"error",
")",
"{",
"var",
"organizationApp",
"OrganizationApp",
"\n",
"return",
"&",
"organizationApp",
",",
"c",
".",
"Get",
"(... | // Info for an organization app.
//
// appIdentity is the unique identifier of the OrganizationApp's App. | [
"Info",
"for",
"an",
"organization",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationApp",
"s",
"App",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app.go#L147-L150 | train |
remind101/empire | pkg/heroku/organization_app.go | OrganizationAppUpdateLocked | func (c *Client) OrganizationAppUpdateLocked(appIdentity string, locked bool) (*OrganizationApp, error) {
params := struct {
Locked bool `json:"locked"`
}{
Locked: locked,
}
var organizationAppRes OrganizationApp
return &organizationAppRes, c.Patch(&organizationAppRes, "/organizations/apps/"+appIdentity, param... | go | func (c *Client) OrganizationAppUpdateLocked(appIdentity string, locked bool) (*OrganizationApp, error) {
params := struct {
Locked bool `json:"locked"`
}{
Locked: locked,
}
var organizationAppRes OrganizationApp
return &organizationAppRes, c.Patch(&organizationAppRes, "/organizations/apps/"+appIdentity, param... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppUpdateLocked",
"(",
"appIdentity",
"string",
",",
"locked",
"bool",
")",
"(",
"*",
"OrganizationApp",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Locked",
"bool",
"`json:\"locked\"`",
"\n",
"}... | // Lock or unlock an organization app.
//
// appIdentity is the unique identifier of the OrganizationApp's App. locked is
// the are other organization members forbidden from joining this app. | [
"Lock",
"or",
"unlock",
"an",
"organization",
"app",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationApp",
"s",
"App",
".",
"locked",
"is",
"the",
"are",
"other",
"organization",
"members",
"forbidden",
"from",
"joining",
"th... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app.go#L156-L164 | train |
remind101/empire | pkg/heroku/organization_app.go | OrganizationAppTransferToOrganization | func (c *Client) OrganizationAppTransferToOrganization(appIdentity string, owner string) (*OrganizationApp, error) {
params := struct {
Owner string `json:"owner"`
}{
Owner: owner,
}
var organizationAppRes OrganizationApp
return &organizationAppRes, c.Patch(&organizationAppRes, "/organizations/apps/"+appIdenti... | go | func (c *Client) OrganizationAppTransferToOrganization(appIdentity string, owner string) (*OrganizationApp, error) {
params := struct {
Owner string `json:"owner"`
}{
Owner: owner,
}
var organizationAppRes OrganizationApp
return &organizationAppRes, c.Patch(&organizationAppRes, "/organizations/apps/"+appIdenti... | [
"func",
"(",
"c",
"*",
"Client",
")",
"OrganizationAppTransferToOrganization",
"(",
"appIdentity",
"string",
",",
"owner",
"string",
")",
"(",
"*",
"OrganizationApp",
",",
"error",
")",
"{",
"params",
":=",
"struct",
"{",
"Owner",
"string",
"`json:\"owner\"`",
... | // Transfer an existing organization app to another organization.
//
// appIdentity is the unique identifier of the OrganizationApp's App. owner is
// the unique name of organization. | [
"Transfer",
"an",
"existing",
"organization",
"app",
"to",
"another",
"organization",
".",
"appIdentity",
"is",
"the",
"unique",
"identifier",
"of",
"the",
"OrganizationApp",
"s",
"App",
".",
"owner",
"is",
"the",
"unique",
"name",
"of",
"organization",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/pkg/heroku/organization_app.go#L184-L192 | train |
remind101/empire | internal/saml/service_provider.go | MakeRedirectAuthenticationRequest | func (sp *ServiceProvider) MakeRedirectAuthenticationRequest(relayState string) (*url.URL, error) {
req, err := sp.MakeAuthenticationRequest(sp.GetSSOBindingLocation(HTTPRedirectBinding))
if err != nil {
return nil, err
}
return req.Redirect(relayState), nil
} | go | func (sp *ServiceProvider) MakeRedirectAuthenticationRequest(relayState string) (*url.URL, error) {
req, err := sp.MakeAuthenticationRequest(sp.GetSSOBindingLocation(HTTPRedirectBinding))
if err != nil {
return nil, err
}
return req.Redirect(relayState), nil
} | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"MakeRedirectAuthenticationRequest",
"(",
"relayState",
"string",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"sp",
".",
"MakeAuthenticationRequest",
"(",
"sp",
".",
"Ge... | // MakeRedirectAuthenticationRequest creates a SAML authentication request using
// the HTTP-Redirect binding. It returns a URL that we will redirect the user to
// in order to start the auth process. | [
"MakeRedirectAuthenticationRequest",
"creates",
"a",
"SAML",
"authentication",
"request",
"using",
"the",
"HTTP",
"-",
"Redirect",
"binding",
".",
"It",
"returns",
"a",
"URL",
"that",
"we",
"will",
"redirect",
"the",
"user",
"to",
"in",
"order",
"to",
"start",
... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/service_provider.go#L104-L110 | train |
remind101/empire | internal/saml/service_provider.go | getIDPSigningCert | func (sp *ServiceProvider) getIDPSigningCert() []byte {
cert := ""
for _, keyDescriptor := range sp.IDPMetadata.IDPSSODescriptor.KeyDescriptor {
if keyDescriptor.Use == "signing" {
cert = keyDescriptor.KeyInfo.Certificate
break
}
}
// If there are no explicitly signing certs, just return the first
// n... | go | func (sp *ServiceProvider) getIDPSigningCert() []byte {
cert := ""
for _, keyDescriptor := range sp.IDPMetadata.IDPSSODescriptor.KeyDescriptor {
if keyDescriptor.Use == "signing" {
cert = keyDescriptor.KeyInfo.Certificate
break
}
}
// If there are no explicitly signing certs, just return the first
// n... | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"getIDPSigningCert",
"(",
")",
"[",
"]",
"byte",
"{",
"cert",
":=",
"\"",
"\"",
"\n\n",
"for",
"_",
",",
"keyDescriptor",
":=",
"range",
"sp",
".",
"IDPMetadata",
".",
"IDPSSODescriptor",
".",
"KeyDescriptor"... | // getIDPSigningCert returns the certificate which we can use to verify things
// signed by the IDP in PEM format, or nil if no such certificate is found. | [
"getIDPSigningCert",
"returns",
"the",
"certificate",
"which",
"we",
"can",
"use",
"to",
"verify",
"things",
"signed",
"by",
"the",
"IDP",
"in",
"PEM",
"format",
"or",
"nil",
"if",
"no",
"such",
"certificate",
"is",
"found",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/service_provider.go#L148-L180 | train |
remind101/empire | internal/saml/service_provider.go | MakePostAuthenticationRequest | func (sp *ServiceProvider) MakePostAuthenticationRequest(relayState string) ([]byte, error) {
req, err := sp.MakeAuthenticationRequest(sp.GetSSOBindingLocation(HTTPPostBinding))
if err != nil {
return nil, err
}
return req.Post(relayState), nil
} | go | func (sp *ServiceProvider) MakePostAuthenticationRequest(relayState string) ([]byte, error) {
req, err := sp.MakeAuthenticationRequest(sp.GetSSOBindingLocation(HTTPPostBinding))
if err != nil {
return nil, err
}
return req.Post(relayState), nil
} | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"MakePostAuthenticationRequest",
"(",
"relayState",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"req",
",",
"err",
":=",
"sp",
".",
"MakeAuthenticationRequest",
"(",
"sp",
".",
"GetSSOBindingL... | // MakePostAuthenticationRequest creates a SAML authentication request using
// the HTTP-POST binding. It returns HTML text representing an HTML form that
// can be sent presented to a browser to initiate the login process. | [
"MakePostAuthenticationRequest",
"creates",
"a",
"SAML",
"authentication",
"request",
"using",
"the",
"HTTP",
"-",
"POST",
"binding",
".",
"It",
"returns",
"HTML",
"text",
"representing",
"an",
"HTML",
"form",
"that",
"can",
"be",
"sent",
"presented",
"to",
"a",... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/service_provider.go#L209-L215 | train |
remind101/empire | internal/saml/service_provider.go | Get | func (aa AssertionAttributes) Get(name string) *AssertionAttribute {
for _, attr := range aa {
if attr.Name == name {
return &attr
}
if attr.FriendlyName == name {
return &attr
}
}
return nil
} | go | func (aa AssertionAttributes) Get(name string) *AssertionAttribute {
for _, attr := range aa {
if attr.Name == name {
return &attr
}
if attr.FriendlyName == name {
return &attr
}
}
return nil
} | [
"func",
"(",
"aa",
"AssertionAttributes",
")",
"Get",
"(",
"name",
"string",
")",
"*",
"AssertionAttribute",
"{",
"for",
"_",
",",
"attr",
":=",
"range",
"aa",
"{",
"if",
"attr",
".",
"Name",
"==",
"name",
"{",
"return",
"&",
"attr",
"\n",
"}",
"\n",... | // Get returns the assertion attribute whose Name or FriendlyName
// matches name, or nil if no matching attribute is found. | [
"Get",
"returns",
"the",
"assertion",
"attribute",
"whose",
"Name",
"or",
"FriendlyName",
"matches",
"name",
"or",
"nil",
"if",
"no",
"matching",
"attribute",
"is",
"found",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/service_provider.go#L255-L265 | train |
remind101/empire | internal/saml/service_provider.go | InitiateLogin | func (sp *ServiceProvider) InitiateLogin(w http.ResponseWriter) error {
acsURL, _ := url.Parse(sp.AcsURL)
binding := HTTPRedirectBinding
bindingLocation := sp.GetSSOBindingLocation(binding)
if bindingLocation == "" {
binding = HTTPPostBinding
bindingLocation = sp.GetSSOBindingLocation(binding)
}
req, err :=... | go | func (sp *ServiceProvider) InitiateLogin(w http.ResponseWriter) error {
acsURL, _ := url.Parse(sp.AcsURL)
binding := HTTPRedirectBinding
bindingLocation := sp.GetSSOBindingLocation(binding)
if bindingLocation == "" {
binding = HTTPPostBinding
bindingLocation = sp.GetSSOBindingLocation(binding)
}
req, err :=... | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"InitiateLogin",
"(",
"w",
"http",
".",
"ResponseWriter",
")",
"error",
"{",
"acsURL",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"sp",
".",
"AcsURL",
")",
"\n\n",
"binding",
":=",
"HTTPRedirectBinding",
"\n... | // Login performs the necessary actions to start an SP initiated login. | [
"Login",
"performs",
"the",
"necessary",
"actions",
"to",
"start",
"an",
"SP",
"initiated",
"login",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/service_provider.go#L443-L494 | train |
remind101/empire | internal/saml/service_provider.go | Parse | func (sp *ServiceProvider) Parse(w http.ResponseWriter, r *http.Request) (*Assertion, error) {
allowIdPInitiated := ""
possibleRequestIDs := []string{allowIdPInitiated}
// Find the request id that relates to this RelayState.
relayState := r.PostFormValue("RelayState")
if sp.cookieSecret() != nil && relayState != ... | go | func (sp *ServiceProvider) Parse(w http.ResponseWriter, r *http.Request) (*Assertion, error) {
allowIdPInitiated := ""
possibleRequestIDs := []string{allowIdPInitiated}
// Find the request id that relates to this RelayState.
relayState := r.PostFormValue("RelayState")
if sp.cookieSecret() != nil && relayState != ... | [
"func",
"(",
"sp",
"*",
"ServiceProvider",
")",
"Parse",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"Assertion",
",",
"error",
")",
"{",
"allowIdPInitiated",
":=",
"\"",
"\"",
"\n",
"possibleRequestIDs"... | // Parse parses the SAMLResponse | [
"Parse",
"parses",
"the",
"SAMLResponse"
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/saml/service_provider.go#L497-L531 | train |
remind101/empire | internal/realip/realip.go | RealIP | func (r *Resolver) RealIP(req *http.Request) string {
var hdrRealIP string
if r.XRealIp {
hdrRealIP = req.Header.Get("X-Real-Ip")
}
var hdrForwardedFor string
if r.XForwardedFor {
hdrForwardedFor = req.Header.Get("X-Forwarded-For")
}
if len(hdrForwardedFor) == 0 && len(hdrRealIP) == 0 {
return ipAddrFrom... | go | func (r *Resolver) RealIP(req *http.Request) string {
var hdrRealIP string
if r.XRealIp {
hdrRealIP = req.Header.Get("X-Real-Ip")
}
var hdrForwardedFor string
if r.XForwardedFor {
hdrForwardedFor = req.Header.Get("X-Forwarded-For")
}
if len(hdrForwardedFor) == 0 && len(hdrRealIP) == 0 {
return ipAddrFrom... | [
"func",
"(",
"r",
"*",
"Resolver",
")",
"RealIP",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"var",
"hdrRealIP",
"string",
"\n",
"if",
"r",
".",
"XRealIp",
"{",
"hdrRealIP",
"=",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
... | // RealIP return client's real public IP address
// from http request headers. | [
"RealIP",
"return",
"client",
"s",
"real",
"public",
"IP",
"address",
"from",
"http",
"request",
"headers",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/realip/realip.go#L67-L123 | train |
remind101/empire | internal/realip/realip.go | Middleware | func Middleware(h http.Handler, r *Resolver) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ip := r.RealIP(req)
h.ServeHTTP(w, req.WithContext(context.WithValue(req.Context(), realIPKey, ip)))
})
} | go | func Middleware(h http.Handler, r *Resolver) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ip := r.RealIP(req)
h.ServeHTTP(w, req.WithContext(context.WithValue(req.Context(), realIPKey, ip)))
})
} | [
"func",
"Middleware",
"(",
"h",
"http",
".",
"Handler",
",",
"r",
"*",
"Resolver",
")",
"http",
".",
"Handler",
"{",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
... | // Middleware is a simple http.Handler middleware that extracts the RealIP from
// the request and set it on the request context. Anything downstream can then
// simply call realip.RealIP to extract the real ip from the request. | [
"Middleware",
"is",
"a",
"simple",
"http",
".",
"Handler",
"middleware",
"that",
"extracts",
"the",
"RealIP",
"from",
"the",
"request",
"and",
"set",
"it",
"on",
"the",
"request",
"context",
".",
"Anything",
"downstream",
"can",
"then",
"simply",
"call",
"re... | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/realip/realip.go#L128-L133 | train |
remind101/empire | internal/realip/realip.go | RealIP | func RealIP(req *http.Request) string {
ip, ok := req.Context().Value(realIPKey).(string)
if !ok {
// Fallback to a secure resolver.
return DefaultResolver.RealIP(req)
}
return ip
} | go | func RealIP(req *http.Request) string {
ip, ok := req.Context().Value(realIPKey).(string)
if !ok {
// Fallback to a secure resolver.
return DefaultResolver.RealIP(req)
}
return ip
} | [
"func",
"RealIP",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"string",
"{",
"ip",
",",
"ok",
":=",
"req",
".",
"Context",
"(",
")",
".",
"Value",
"(",
"realIPKey",
")",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"// Fallback to a secur... | // Extracts the real ip from the request context. | [
"Extracts",
"the",
"real",
"ip",
"from",
"the",
"request",
"context",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/realip/realip.go#L136-L143 | train |
remind101/empire | internal/realip/realip.go | reverse | func reverse(ss []string) {
last := len(ss) - 1
for i := 0; i < len(ss)/2; i++ {
ss[i], ss[last-i] = ss[last-i], ss[i]
}
} | go | func reverse(ss []string) {
last := len(ss) - 1
for i := 0; i < len(ss)/2; i++ {
ss[i], ss[last-i] = ss[last-i], ss[i]
}
} | [
"func",
"reverse",
"(",
"ss",
"[",
"]",
"string",
")",
"{",
"last",
":=",
"len",
"(",
"ss",
")",
"-",
"1",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"ss",
")",
"/",
"2",
";",
"i",
"++",
"{",
"ss",
"[",
"i",
"]",
",",
"ss",... | // reverse reverses a slice of strings. | [
"reverse",
"reverses",
"a",
"slice",
"of",
"strings",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/internal/realip/realip.go#L146-L151 | train |
remind101/empire | stats/statsd.go | NewStatsd | func NewStatsd(addr, prefix string) (*Statsd, error) {
c, err := statsd.NewClient(addr, prefix)
if err != nil {
return nil, err
}
return &Statsd{
client: c,
}, nil
} | go | func NewStatsd(addr, prefix string) (*Statsd, error) {
c, err := statsd.NewClient(addr, prefix)
if err != nil {
return nil, err
}
return &Statsd{
client: c,
}, nil
} | [
"func",
"NewStatsd",
"(",
"addr",
",",
"prefix",
"string",
")",
"(",
"*",
"Statsd",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"statsd",
".",
"NewClient",
"(",
"addr",
",",
"prefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
... | // NewStatsd returns a new Statsd implementation that sends stats to addr. | [
"NewStatsd",
"returns",
"a",
"new",
"Statsd",
"implementation",
"that",
"sends",
"stats",
"to",
"addr",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/stats/statsd.go#L15-L23 | train |
remind101/empire | scheduler/docker/docker.go | RunAttachedWithDocker | func RunAttachedWithDocker(s twelvefactor.Scheduler, client *dockerutil.Client) *AttachedScheduler {
return &AttachedScheduler{
Scheduler: s,
dockerScheduler: NewScheduler(client),
}
} | go | func RunAttachedWithDocker(s twelvefactor.Scheduler, client *dockerutil.Client) *AttachedScheduler {
return &AttachedScheduler{
Scheduler: s,
dockerScheduler: NewScheduler(client),
}
} | [
"func",
"RunAttachedWithDocker",
"(",
"s",
"twelvefactor",
".",
"Scheduler",
",",
"client",
"*",
"dockerutil",
".",
"Client",
")",
"*",
"AttachedScheduler",
"{",
"return",
"&",
"AttachedScheduler",
"{",
"Scheduler",
":",
"s",
",",
"dockerScheduler",
":",
"NewSch... | // RunAttachedWithDocker wraps a Scheduler to run attached Run's using a Docker
// client. | [
"RunAttachedWithDocker",
"wraps",
"a",
"Scheduler",
"to",
"run",
"attached",
"Run",
"s",
"using",
"a",
"Docker",
"client",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L66-L71 | train |
remind101/empire | scheduler/docker/docker.go | Run | func (s *AttachedScheduler) Run(ctx context.Context, app *twelvefactor.Manifest) error {
if len(app.Processes) != 1 {
return fmt.Errorf("docker: cannot run mutliple processes with attached scheduler")
}
p := app.Processes[0]
// Attached means stdout, stdin is attached.
attached := p.Stdin != nil || p.Stdout != ... | go | func (s *AttachedScheduler) Run(ctx context.Context, app *twelvefactor.Manifest) error {
if len(app.Processes) != 1 {
return fmt.Errorf("docker: cannot run mutliple processes with attached scheduler")
}
p := app.Processes[0]
// Attached means stdout, stdin is attached.
attached := p.Stdin != nil || p.Stdout != ... | [
"func",
"(",
"s",
"*",
"AttachedScheduler",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"*",
"twelvefactor",
".",
"Manifest",
")",
"error",
"{",
"if",
"len",
"(",
"app",
".",
"Processes",
")",
"!=",
"1",
"{",
"return",
"fmt",
".",
... | // Run runs attached processes using the docker scheduler, and detached
// processes using the wrapped scheduler. | [
"Run",
"runs",
"attached",
"processes",
"using",
"the",
"docker",
"scheduler",
"and",
"detached",
"processes",
"using",
"the",
"wrapped",
"scheduler",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L75-L89 | train |
remind101/empire | scheduler/docker/docker.go | Tasks | func (s *AttachedScheduler) Tasks(ctx context.Context, app string) ([]*twelvefactor.Task, error) {
if !s.ShowAttached {
return s.Scheduler.Tasks(ctx, app)
}
type instancesResult struct {
instances []*twelvefactor.Task
err error
}
ch := make(chan instancesResult, 1)
go func() {
attachedInstances, e... | go | func (s *AttachedScheduler) Tasks(ctx context.Context, app string) ([]*twelvefactor.Task, error) {
if !s.ShowAttached {
return s.Scheduler.Tasks(ctx, app)
}
type instancesResult struct {
instances []*twelvefactor.Task
err error
}
ch := make(chan instancesResult, 1)
go func() {
attachedInstances, e... | [
"func",
"(",
"s",
"*",
"AttachedScheduler",
")",
"Tasks",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"string",
")",
"(",
"[",
"]",
"*",
"twelvefactor",
".",
"Task",
",",
"error",
")",
"{",
"if",
"!",
"s",
".",
"ShowAttached",
"{",
"return",
... | // Tasks returns a combination of instances from the wrapped scheduler, as
// well as instances from attached runs. | [
"Tasks",
"returns",
"a",
"combination",
"of",
"instances",
"from",
"the",
"wrapped",
"scheduler",
"as",
"well",
"as",
"instances",
"from",
"attached",
"runs",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L93-L120 | train |
remind101/empire | scheduler/docker/docker.go | Stop | func (s *AttachedScheduler) Stop(ctx context.Context, maybeContainerID string) error {
if !s.ShowAttached {
return s.Scheduler.Stop(ctx, maybeContainerID)
}
err := s.dockerScheduler.Stop(ctx, maybeContainerID)
// If there's no container with this ID, delegate to the wrapped
// scheduler.
if _, ok := err.(*doc... | go | func (s *AttachedScheduler) Stop(ctx context.Context, maybeContainerID string) error {
if !s.ShowAttached {
return s.Scheduler.Stop(ctx, maybeContainerID)
}
err := s.dockerScheduler.Stop(ctx, maybeContainerID)
// If there's no container with this ID, delegate to the wrapped
// scheduler.
if _, ok := err.(*doc... | [
"func",
"(",
"s",
"*",
"AttachedScheduler",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
",",
"maybeContainerID",
"string",
")",
"error",
"{",
"if",
"!",
"s",
".",
"ShowAttached",
"{",
"return",
"s",
".",
"Scheduler",
".",
"Stop",
"(",
"ctx",
",... | // Stop checks if there's an attached run matching the given id, and stops that
// container if there is. Otherwise, it delegates to the wrapped Scheduler. | [
"Stop",
"checks",
"if",
"there",
"s",
"an",
"attached",
"run",
"matching",
"the",
"given",
"id",
"and",
"stops",
"that",
"container",
"if",
"there",
"is",
".",
"Otherwise",
"it",
"delegates",
"to",
"the",
"wrapped",
"Scheduler",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L124-L138 | train |
remind101/empire | scheduler/docker/docker.go | InstancesFromAttachedRuns | func (s *Scheduler) InstancesFromAttachedRuns(ctx context.Context, app string) ([]*twelvefactor.Task, error) {
// Filter only docker containers that were started as an attached run.
attached := fmt.Sprintf("%s=%s", runLabel, Attached)
return s.instances(ctx, app, attached)
} | go | func (s *Scheduler) InstancesFromAttachedRuns(ctx context.Context, app string) ([]*twelvefactor.Task, error) {
// Filter only docker containers that were started as an attached run.
attached := fmt.Sprintf("%s=%s", runLabel, Attached)
return s.instances(ctx, app, attached)
} | [
"func",
"(",
"s",
"*",
"Scheduler",
")",
"InstancesFromAttachedRuns",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"string",
")",
"(",
"[",
"]",
"*",
"twelvefactor",
".",
"Task",
",",
"error",
")",
"{",
"// Filter only docker containers that were started a... | // InstancesFromAttachedRuns returns Instances that were started from attached
// runs. | [
"InstancesFromAttachedRuns",
"returns",
"Instances",
"that",
"were",
"started",
"from",
"attached",
"runs",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L234-L238 | train |
remind101/empire | scheduler/docker/docker.go | instances | func (s *Scheduler) instances(ctx context.Context, app string, labels ...string) ([]*twelvefactor.Task, error) {
var instances []*twelvefactor.Task
containers, err := s.docker.ListContainers(docker.ListContainersOptions{
Filters: map[string][]string{
"label": append([]string{
fmt.Sprintf("%s=%s", appLabel, ... | go | func (s *Scheduler) instances(ctx context.Context, app string, labels ...string) ([]*twelvefactor.Task, error) {
var instances []*twelvefactor.Task
containers, err := s.docker.ListContainers(docker.ListContainersOptions{
Filters: map[string][]string{
"label": append([]string{
fmt.Sprintf("%s=%s", appLabel, ... | [
"func",
"(",
"s",
"*",
"Scheduler",
")",
"instances",
"(",
"ctx",
"context",
".",
"Context",
",",
"app",
"string",
",",
"labels",
"...",
"string",
")",
"(",
"[",
"]",
"*",
"twelvefactor",
".",
"Task",
",",
"error",
")",
"{",
"var",
"instances",
"[",
... | // instances returns docker container instances for this app, optionally
// filtered with labels. | [
"instances",
"returns",
"docker",
"container",
"instances",
"for",
"this",
"app",
"optionally",
"filtered",
"with",
"labels",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L242-L279 | train |
remind101/empire | scheduler/docker/docker.go | Stop | func (s *Scheduler) Stop(ctx context.Context, containerID string) error {
container, err := s.docker.InspectContainer(containerID)
if err != nil {
return err
}
// Some extra protection around stopping containers. We don't want to
// allow users to stop containers that may have been started outside of
// Empire... | go | func (s *Scheduler) Stop(ctx context.Context, containerID string) error {
container, err := s.docker.InspectContainer(containerID)
if err != nil {
return err
}
// Some extra protection around stopping containers. We don't want to
// allow users to stop containers that may have been started outside of
// Empire... | [
"func",
"(",
"s",
"*",
"Scheduler",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
",",
"containerID",
"string",
")",
"error",
"{",
"container",
",",
"err",
":=",
"s",
".",
"docker",
".",
"InspectContainer",
"(",
"containerID",
")",
"\n",
"if",
"e... | // Stop stops the given container. | [
"Stop",
"stops",
"the",
"given",
"container",
"."
] | 3daba389f6b07b5d219246bfc7d901fcec664161 | https://github.com/remind101/empire/blob/3daba389f6b07b5d219246bfc7d901fcec664161/scheduler/docker/docker.go#L282-L302 | train |
ory/ladon | condition_cidr.go | Fulfills | func (c *CIDRCondition) Fulfills(value interface{}, _ *Request) bool {
ips, ok := value.(string)
if !ok {
return false
}
_, cidrnet, err := net.ParseCIDR(c.CIDR)
if err != nil {
return false
}
ip := net.ParseIP(ips)
if ip == nil {
return false
}
return cidrnet.Contains(ip)
} | go | func (c *CIDRCondition) Fulfills(value interface{}, _ *Request) bool {
ips, ok := value.(string)
if !ok {
return false
}
_, cidrnet, err := net.ParseCIDR(c.CIDR)
if err != nil {
return false
}
ip := net.ParseIP(ips)
if ip == nil {
return false
}
return cidrnet.Contains(ip)
} | [
"func",
"(",
"c",
"*",
"CIDRCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"_",
"*",
"Request",
")",
"bool",
"{",
"ips",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"false",
"\n... | // Fulfills returns true if the the request is fulfilled by the condition. | [
"Fulfills",
"returns",
"true",
"if",
"the",
"the",
"request",
"is",
"fulfilled",
"by",
"the",
"condition",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_cidr.go#L33-L50 | train |
ory/ladon | condition_boolean.go | Fulfills | func (c *BooleanCondition) Fulfills(value interface{}, _ *Request) bool {
val, ok := value.(bool)
return ok && val == c.BooleanValue
} | go | func (c *BooleanCondition) Fulfills(value interface{}, _ *Request) bool {
val, ok := value.(bool)
return ok && val == c.BooleanValue
} | [
"func",
"(",
"c",
"*",
"BooleanCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"_",
"*",
"Request",
")",
"bool",
"{",
"val",
",",
"ok",
":=",
"value",
".",
"(",
"bool",
")",
"\n\n",
"return",
"ok",
"&&",
"val",
"==",
"c",
"... | // Fulfills determines if the BooleanCondition is fulfilled.
// The BooleanCondition is fulfilled if the provided boolean value matches the conditions boolean value. | [
"Fulfills",
"determines",
"if",
"the",
"BooleanCondition",
"is",
"fulfilled",
".",
"The",
"BooleanCondition",
"is",
"fulfilled",
"if",
"the",
"provided",
"boolean",
"value",
"matches",
"the",
"conditions",
"boolean",
"value",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_boolean.go#L21-L25 | train |
ory/ladon | condition_subject_equal.go | Fulfills | func (c *EqualsSubjectCondition) Fulfills(value interface{}, r *Request) bool {
s, ok := value.(string)
return ok && s == r.Subject
} | go | func (c *EqualsSubjectCondition) Fulfills(value interface{}, r *Request) bool {
s, ok := value.(string)
return ok && s == r.Subject
} | [
"func",
"(",
"c",
"*",
"EqualsSubjectCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"r",
"*",
"Request",
")",
"bool",
"{",
"s",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
"\n\n",
"return",
"ok",
"&&",
"s",
"==",
"r",... | // Fulfills returns true if the request's subject is equal to the given value string | [
"Fulfills",
"returns",
"true",
"if",
"the",
"request",
"s",
"subject",
"is",
"equal",
"to",
"the",
"given",
"value",
"string"
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_subject_equal.go#L27-L31 | train |
ory/ladon | manager/memory/manager_memory.go | Update | func (m *MemoryManager) Update(policy Policy) error {
m.Lock()
defer m.Unlock()
m.Policies[policy.GetID()] = policy
return nil
} | go | func (m *MemoryManager) Update(policy Policy) error {
m.Lock()
defer m.Unlock()
m.Policies[policy.GetID()] = policy
return nil
} | [
"func",
"(",
"m",
"*",
"MemoryManager",
")",
"Update",
"(",
"policy",
"Policy",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"Policies",
"[",
"policy",
".",
"GetID",
"(",
")",
"]",
... | // Update updates an existing policy. | [
"Update",
"updates",
"an",
"existing",
"policy",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/manager/memory/manager_memory.go#L47-L52 | train |
ory/ladon | manager/memory/manager_memory.go | GetAll | func (m *MemoryManager) GetAll(limit, offset int64) (Policies, error) {
keys := make([]string, len(m.Policies))
i := 0
m.RLock()
for key := range m.Policies {
keys[i] = key
i++
}
start, end := pagination.Index(int(limit), int(offset), len(m.Policies))
sort.Strings(keys)
ps := make(Policies, len(keys[start:... | go | func (m *MemoryManager) GetAll(limit, offset int64) (Policies, error) {
keys := make([]string, len(m.Policies))
i := 0
m.RLock()
for key := range m.Policies {
keys[i] = key
i++
}
start, end := pagination.Index(int(limit), int(offset), len(m.Policies))
sort.Strings(keys)
ps := make(Policies, len(keys[start:... | [
"func",
"(",
"m",
"*",
"MemoryManager",
")",
"GetAll",
"(",
"limit",
",",
"offset",
"int64",
")",
"(",
"Policies",
",",
"error",
")",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"m",
".",
"Policies",
")",
")",
"\n",
"i",
... | // GetAll returns all policies. | [
"GetAll",
"returns",
"all",
"policies",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/manager/memory/manager_memory.go#L55-L74 | train |
ory/ladon | manager/memory/manager_memory.go | Create | func (m *MemoryManager) Create(policy Policy) error {
m.Lock()
defer m.Unlock()
if _, found := m.Policies[policy.GetID()]; found {
return errors.New("Policy exists")
}
m.Policies[policy.GetID()] = policy
return nil
} | go | func (m *MemoryManager) Create(policy Policy) error {
m.Lock()
defer m.Unlock()
if _, found := m.Policies[policy.GetID()]; found {
return errors.New("Policy exists")
}
m.Policies[policy.GetID()] = policy
return nil
} | [
"func",
"(",
"m",
"*",
"MemoryManager",
")",
"Create",
"(",
"policy",
"Policy",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"_",
",",
"found",
":=",
"m",
".",
"Policies",
"[",
"policy"... | // Create a new pollicy to MemoryManager. | [
"Create",
"a",
"new",
"pollicy",
"to",
"MemoryManager",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/manager/memory/manager_memory.go#L77-L87 | train |
ory/ladon | manager/memory/manager_memory.go | Get | func (m *MemoryManager) Get(id string) (Policy, error) {
m.RLock()
defer m.RUnlock()
p, ok := m.Policies[id]
if !ok {
return nil, errors.New("Not found")
}
return p, nil
} | go | func (m *MemoryManager) Get(id string) (Policy, error) {
m.RLock()
defer m.RUnlock()
p, ok := m.Policies[id]
if !ok {
return nil, errors.New("Not found")
}
return p, nil
} | [
"func",
"(",
"m",
"*",
"MemoryManager",
")",
"Get",
"(",
"id",
"string",
")",
"(",
"Policy",
",",
"error",
")",
"{",
"m",
".",
"RLock",
"(",
")",
"\n",
"defer",
"m",
".",
"RUnlock",
"(",
")",
"\n",
"p",
",",
"ok",
":=",
"m",
".",
"Policies",
... | // Get retrieves a policy. | [
"Get",
"retrieves",
"a",
"policy",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/manager/memory/manager_memory.go#L90-L99 | train |
ory/ladon | manager/memory/manager_memory.go | Delete | func (m *MemoryManager) Delete(id string) error {
m.Lock()
defer m.Unlock()
delete(m.Policies, id)
return nil
} | go | func (m *MemoryManager) Delete(id string) error {
m.Lock()
defer m.Unlock()
delete(m.Policies, id)
return nil
} | [
"func",
"(",
"m",
"*",
"MemoryManager",
")",
"Delete",
"(",
"id",
"string",
")",
"error",
"{",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"m",
".",
"Policies",
",",
"id",
")",
"\n",
"return",
"... | // Delete removes a policy. | [
"Delete",
"removes",
"a",
"policy",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/manager/memory/manager_memory.go#L102-L107 | train |
ory/ladon | condition_string_pairs_equal.go | Fulfills | func (c *StringPairsEqualCondition) Fulfills(value interface{}, _ *Request) bool {
pairs, PairsOk := value.([]interface{})
if !PairsOk {
return false
}
for _, v := range pairs {
pair, PairOk := v.([]interface{})
if !PairOk || (len(pair) != 2) {
return false
}
a, AOk := pair[0].(string)
b, BOk := pa... | go | func (c *StringPairsEqualCondition) Fulfills(value interface{}, _ *Request) bool {
pairs, PairsOk := value.([]interface{})
if !PairsOk {
return false
}
for _, v := range pairs {
pair, PairOk := v.([]interface{})
if !PairOk || (len(pair) != 2) {
return false
}
a, AOk := pair[0].(string)
b, BOk := pa... | [
"func",
"(",
"c",
"*",
"StringPairsEqualCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"_",
"*",
"Request",
")",
"bool",
"{",
"pairs",
",",
"PairsOk",
":=",
"value",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
... | // Fulfills returns true if the given value is an array of string arrays and
// each string array has exactly two values which are equal | [
"Fulfills",
"returns",
"true",
"if",
"the",
"given",
"value",
"is",
"an",
"array",
"of",
"string",
"arrays",
"and",
"each",
"string",
"array",
"has",
"exactly",
"two",
"values",
"which",
"are",
"equal"
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_string_pairs_equal.go#L30-L51 | train |
ory/ladon | condition_string_match.go | Fulfills | func (c *StringMatchCondition) Fulfills(value interface{}, _ *Request) bool {
s, ok := value.(string)
matches, _ := regexp.MatchString(c.Matches, s)
return ok && matches
} | go | func (c *StringMatchCondition) Fulfills(value interface{}, _ *Request) bool {
s, ok := value.(string)
matches, _ := regexp.MatchString(c.Matches, s)
return ok && matches
} | [
"func",
"(",
"c",
"*",
"StringMatchCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"_",
"*",
"Request",
")",
"bool",
"{",
"s",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
"\n\n",
"matches",
",",
"_",
":=",
"regexp",
".... | // Fulfills returns true if the given value is a string and matches the regex
// pattern in StringMatchCondition.Matches | [
"Fulfills",
"returns",
"true",
"if",
"the",
"given",
"value",
"is",
"a",
"string",
"and",
"matches",
"the",
"regex",
"pattern",
"in",
"StringMatchCondition",
".",
"Matches"
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_string_match.go#L35-L41 | train |
ory/ladon | ladon.go | IsAllowed | func (l *Ladon) IsAllowed(r *Request) (err error) {
policies, err := l.Manager.FindRequestCandidates(r)
if err != nil {
return err
}
// Although the manager is responsible of matching the policies, it might decide to just scan for
// subjects, it might return all policies, or it might have a different pattern m... | go | func (l *Ladon) IsAllowed(r *Request) (err error) {
policies, err := l.Manager.FindRequestCandidates(r)
if err != nil {
return err
}
// Although the manager is responsible of matching the policies, it might decide to just scan for
// subjects, it might return all policies, or it might have a different pattern m... | [
"func",
"(",
"l",
"*",
"Ladon",
")",
"IsAllowed",
"(",
"r",
"*",
"Request",
")",
"(",
"err",
"error",
")",
"{",
"policies",
",",
"err",
":=",
"l",
".",
"Manager",
".",
"FindRequestCandidates",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // IsAllowed returns nil if subject s has permission p on resource r with context c or an error otherwise. | [
"IsAllowed",
"returns",
"nil",
"if",
"subject",
"s",
"has",
"permission",
"p",
"on",
"resource",
"r",
"with",
"context",
"c",
"or",
"an",
"error",
"otherwise",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/ladon.go#L49-L59 | train |
ory/ladon | ladon.go | DoPoliciesAllow | func (l *Ladon) DoPoliciesAllow(r *Request, policies []Policy) (err error) {
var allowed = false
var deciders = Policies{}
// Iterate through all policies
for _, p := range policies {
// Does the action match with one of the policies?
// This is the first check because usually actions are a superset of get|upd... | go | func (l *Ladon) DoPoliciesAllow(r *Request, policies []Policy) (err error) {
var allowed = false
var deciders = Policies{}
// Iterate through all policies
for _, p := range policies {
// Does the action match with one of the policies?
// This is the first check because usually actions are a superset of get|upd... | [
"func",
"(",
"l",
"*",
"Ladon",
")",
"DoPoliciesAllow",
"(",
"r",
"*",
"Request",
",",
"policies",
"[",
"]",
"Policy",
")",
"(",
"err",
"error",
")",
"{",
"var",
"allowed",
"=",
"false",
"\n",
"var",
"deciders",
"=",
"Policies",
"{",
"}",
"\n\n",
"... | // DoPoliciesAllow returns nil if subject s has permission p on resource r with context c for a given policy list or an error otherwise.
// The IsAllowed interface should be preferred since it uses the manager directly. This is a lower level interface for when you don't want to use the ladon manager. | [
"DoPoliciesAllow",
"returns",
"nil",
"if",
"subject",
"s",
"has",
"permission",
"p",
"on",
"resource",
"r",
"with",
"context",
"c",
"for",
"a",
"given",
"policy",
"list",
"or",
"an",
"error",
"otherwise",
".",
"The",
"IsAllowed",
"interface",
"should",
"be",... | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/ladon.go#L63-L122 | train |
ory/ladon | condition_resource_contains.go | Fulfills | func (c *ResourceContainsCondition) Fulfills(value interface{}, r *Request) bool {
filter, ok := value.(map[string]interface{})
if !ok {
return false
}
valueString, ok := filter["value"].(string)
if !ok || len(valueString) < 1 {
return false
}
//If no delimiter provided default to "equals" check
delimite... | go | func (c *ResourceContainsCondition) Fulfills(value interface{}, r *Request) bool {
filter, ok := value.(map[string]interface{})
if !ok {
return false
}
valueString, ok := filter["value"].(string)
if !ok || len(valueString) < 1 {
return false
}
//If no delimiter provided default to "equals" check
delimite... | [
"func",
"(",
"c",
"*",
"ResourceContainsCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"r",
"*",
"Request",
")",
"bool",
"{",
"filter",
",",
"ok",
":=",
"value",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",... | // Fulfills returns true if the request's resouce contains the given value string | [
"Fulfills",
"returns",
"true",
"if",
"the",
"request",
"s",
"resouce",
"contains",
"the",
"given",
"value",
"string"
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_resource_contains.go#L29-L54 | train |
ory/ladon | matcher_regexp.go | Matches | func (m *RegexpMatcher) Matches(p Policy, haystack []string, needle string) (bool, error) {
var reg *regexp.Regexp
var err error
for _, h := range haystack {
// This means that the current haystack item does not contain a regular expression
if strings.Count(h, string(p.GetStartDelimiter())) == 0 {
// If we h... | go | func (m *RegexpMatcher) Matches(p Policy, haystack []string, needle string) (bool, error) {
var reg *regexp.Regexp
var err error
for _, h := range haystack {
// This means that the current haystack item does not contain a regular expression
if strings.Count(h, string(p.GetStartDelimiter())) == 0 {
// If we h... | [
"func",
"(",
"m",
"*",
"RegexpMatcher",
")",
"Matches",
"(",
"p",
"Policy",
",",
"haystack",
"[",
"]",
"string",
",",
"needle",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"reg",
"*",
"regexp",
".",
"Regexp",
"\n",
"var",
"err",
"err... | // Matches a needle with an array of regular expressions and returns true if a match was found. | [
"Matches",
"a",
"needle",
"with",
"an",
"array",
"of",
"regular",
"expressions",
"and",
"returns",
"true",
"if",
"a",
"match",
"was",
"found",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/matcher_regexp.go#L66-L100 | train |
ory/ladon | condition.go | AddCondition | func (cs Conditions) AddCondition(key string, c Condition) {
cs[key] = c
} | go | func (cs Conditions) AddCondition(key string, c Condition) {
cs[key] = c
} | [
"func",
"(",
"cs",
"Conditions",
")",
"AddCondition",
"(",
"key",
"string",
",",
"c",
"Condition",
")",
"{",
"cs",
"[",
"key",
"]",
"=",
"c",
"\n",
"}"
] | // AddCondition adds a condition to the collection. | [
"AddCondition",
"adds",
"a",
"condition",
"to",
"the",
"collection",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition.go#L42-L44 | train |
ory/ladon | condition.go | MarshalJSON | func (cs Conditions) MarshalJSON() ([]byte, error) {
out := make(map[string]*jsonCondition, len(cs))
for k, c := range cs {
raw, err := json.Marshal(c)
if err != nil {
return []byte{}, errors.WithStack(err)
}
out[k] = &jsonCondition{
Type: c.GetName(),
Options: json.RawMessage(raw),
}
}
retu... | go | func (cs Conditions) MarshalJSON() ([]byte, error) {
out := make(map[string]*jsonCondition, len(cs))
for k, c := range cs {
raw, err := json.Marshal(c)
if err != nil {
return []byte{}, errors.WithStack(err)
}
out[k] = &jsonCondition{
Type: c.GetName(),
Options: json.RawMessage(raw),
}
}
retu... | [
"func",
"(",
"cs",
"Conditions",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"out",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"jsonCondition",
",",
"len",
"(",
"cs",
")",
")",
"\n",
"for",
"k",
",",
"c"... | // MarshalJSON marshals a list of conditions to json. | [
"MarshalJSON",
"marshals",
"a",
"list",
"of",
"conditions",
"to",
"json",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition.go#L47-L62 | train |
ory/ladon | condition.go | UnmarshalJSON | func (cs Conditions) UnmarshalJSON(data []byte) error {
if cs == nil {
return errors.New("Can not be nil")
}
var jcs map[string]jsonCondition
var dc Condition
if err := json.Unmarshal(data, &jcs); err != nil {
return errors.WithStack(err)
}
for k, jc := range jcs {
var found bool
for name, c := range ... | go | func (cs Conditions) UnmarshalJSON(data []byte) error {
if cs == nil {
return errors.New("Can not be nil")
}
var jcs map[string]jsonCondition
var dc Condition
if err := json.Unmarshal(data, &jcs); err != nil {
return errors.WithStack(err)
}
for k, jc := range jcs {
var found bool
for name, c := range ... | [
"func",
"(",
"cs",
"Conditions",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"cs",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"jcs",
"map",
"[",
"string",
"]... | // UnmarshalJSON unmarshals a list of conditions from json. | [
"UnmarshalJSON",
"unmarshals",
"a",
"list",
"of",
"conditions",
"from",
"json",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition.go#L65-L104 | train |
ory/ladon | condition_string_equal.go | Fulfills | func (c *StringEqualCondition) Fulfills(value interface{}, _ *Request) bool {
s, ok := value.(string)
return ok && s == c.Equals
} | go | func (c *StringEqualCondition) Fulfills(value interface{}, _ *Request) bool {
s, ok := value.(string)
return ok && s == c.Equals
} | [
"func",
"(",
"c",
"*",
"StringEqualCondition",
")",
"Fulfills",
"(",
"value",
"interface",
"{",
"}",
",",
"_",
"*",
"Request",
")",
"bool",
"{",
"s",
",",
"ok",
":=",
"value",
".",
"(",
"string",
")",
"\n\n",
"return",
"ok",
"&&",
"s",
"==",
"c",
... | // Fulfills returns true if the given value is a string and is the
// same as in StringEqualCondition.Equals | [
"Fulfills",
"returns",
"true",
"if",
"the",
"given",
"value",
"is",
"a",
"string",
"and",
"is",
"the",
"same",
"as",
"in",
"StringEqualCondition",
".",
"Equals"
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/condition_string_equal.go#L31-L35 | train |
ory/ladon | compiler/regex.go | delimiterIndices | func delimiterIndices(s string, delimiterStart, delimiterEnd byte) ([]int, error) {
var level, idx int
idxs := make([]int, 0)
for i := 0; i < len(s); i++ {
switch s[i] {
case delimiterStart:
if level++; level == 1 {
idx = i
}
case delimiterEnd:
if level--; level == 0 {
idxs = append(idxs, idx,... | go | func delimiterIndices(s string, delimiterStart, delimiterEnd byte) ([]int, error) {
var level, idx int
idxs := make([]int, 0)
for i := 0; i < len(s); i++ {
switch s[i] {
case delimiterStart:
if level++; level == 1 {
idx = i
}
case delimiterEnd:
if level--; level == 0 {
idxs = append(idxs, idx,... | [
"func",
"delimiterIndices",
"(",
"s",
"string",
",",
"delimiterStart",
",",
"delimiterEnd",
"byte",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"var",
"level",
",",
"idx",
"int",
"\n",
"idxs",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"0",
")... | // delimiterIndices returns the first level delimiter indices from a string.
// It returns an error in case of unbalanced delimiters. | [
"delimiterIndices",
"returns",
"the",
"first",
"level",
"delimiter",
"indices",
"from",
"a",
"string",
".",
"It",
"returns",
"an",
"error",
"in",
"case",
"of",
"unbalanced",
"delimiters",
"."
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/compiler/regex.go#L75-L98 | train |
ory/ladon | policy.go | UnmarshalJSON | func (p *DefaultPolicy) UnmarshalJSON(data []byte) error {
var pol = struct {
ID string `json:"id" gorethink:"id"`
Description string `json:"description" gorethink:"description"`
Subjects []string `json:"subjects" gorethink:"subjects"`
Effect string `json:"effect" gorethink:"effe... | go | func (p *DefaultPolicy) UnmarshalJSON(data []byte) error {
var pol = struct {
ID string `json:"id" gorethink:"id"`
Description string `json:"description" gorethink:"description"`
Subjects []string `json:"subjects" gorethink:"subjects"`
Effect string `json:"effect" gorethink:"effe... | [
"func",
"(",
"p",
"*",
"DefaultPolicy",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"pol",
"=",
"struct",
"{",
"ID",
"string",
"`json:\"id\" gorethink:\"id\"`",
"\n",
"Description",
"string",
"`json:\"description\" gorethink:\"de... | // UnmarshalJSON overwrite own policy with values of the given in policy in JSON format | [
"UnmarshalJSON",
"overwrite",
"own",
"policy",
"with",
"values",
"of",
"the",
"given",
"in",
"policy",
"in",
"JSON",
"format"
] | 7f1c376a9a46cd4e09f90d3940e81cd963b0d87d | https://github.com/ory/ladon/blob/7f1c376a9a46cd4e09f90d3940e81cd963b0d87d/policy.go#L81-L110 | train |
sajari/docconv | tidy.go | Tidy | func Tidy(r io.Reader, xmlIn bool) ([]byte, error) {
f, err := ioutil.TempFile("/tmp", "sajari-convert-")
if err != nil {
return nil, err
}
defer os.Remove(f.Name())
io.Copy(f, r)
var output []byte
if xmlIn {
output, err = exec.Command("tidy", "-xml", "-numeric", "-asxml", "-quiet", "-utf8", f.Name()).Outpu... | go | func Tidy(r io.Reader, xmlIn bool) ([]byte, error) {
f, err := ioutil.TempFile("/tmp", "sajari-convert-")
if err != nil {
return nil, err
}
defer os.Remove(f.Name())
io.Copy(f, r)
var output []byte
if xmlIn {
output, err = exec.Command("tidy", "-xml", "-numeric", "-asxml", "-quiet", "-utf8", f.Name()).Outpu... | [
"func",
"Tidy",
"(",
"r",
"io",
".",
"Reader",
",",
"xmlIn",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // Tidy attempts to tidy up XML.
// Errors & warnings are deliberately suppressed as underlying tools
// throw warnings very easily. | [
"Tidy",
"attempts",
"to",
"tidy",
"up",
"XML",
".",
"Errors",
"&",
"warnings",
"are",
"deliberately",
"suppressed",
"as",
"underlying",
"tools",
"throw",
"warnings",
"very",
"easily",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/tidy.go#L13-L32 | train |
sajari/docconv | local.go | Done | func (l *LocalFile) Done() {
l.Close()
if l.unlink {
os.Remove(l.Name())
}
} | go | func (l *LocalFile) Done() {
l.Close()
if l.unlink {
os.Remove(l.Name())
}
} | [
"func",
"(",
"l",
"*",
"LocalFile",
")",
"Done",
"(",
")",
"{",
"l",
".",
"Close",
"(",
")",
"\n",
"if",
"l",
".",
"unlink",
"{",
"os",
".",
"Remove",
"(",
"l",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Done cleans up all resources. | [
"Done",
"cleans",
"up",
"all",
"resources",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/local.go#L46-L51 | train |
sajari/docconv | odt.go | ConvertODT | func ConvertODT(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textBody string
b, err := ioutil.ReadAll(r)
if err != nil {
return "", nil, err
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
return "", nil, fmt.Errorf("error unzipping data... | go | func ConvertODT(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textBody string
b, err := ioutil.ReadAll(r)
if err != nil {
return "", nil, err
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
return "", nil, fmt.Errorf("error unzipping data... | [
"func",
"ConvertODT",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"var",
"textBody",
"string",
"\n\n... | // ConvertODT converts a ODT file to text | [
"ConvertODT",
"converts",
"a",
"ODT",
"file",
"to",
"text"
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/odt.go#L13-L69 | train |
sajari/docconv | snappy/decode.go | DecodedLen | func DecodedLen(src []byte) (int, error) {
v, _, err := decodedLen(src)
return v, err
} | go | func DecodedLen(src []byte) (int, error) {
v, _, err := decodedLen(src)
return v, err
} | [
"func",
"DecodedLen",
"(",
"src",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"v",
",",
"_",
",",
"err",
":=",
"decodedLen",
"(",
"src",
")",
"\n",
"return",
"v",
",",
"err",
"\n",
"}"
] | // DecodedLen returns the length of the decoded block. | [
"DecodedLen",
"returns",
"the",
"length",
"of",
"the",
"decoded",
"block",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/snappy/decode.go#L21-L24 | train |
sajari/docconv | snappy/decode.go | Reset | func (r *Reader) Reset(reader io.Reader) {
r.r = reader
r.err = nil
r.i = 0
r.j = 0
r.readHeader = false
} | go | func (r *Reader) Reset(reader io.Reader) {
r.r = reader
r.err = nil
r.i = 0
r.j = 0
r.readHeader = false
} | [
"func",
"(",
"r",
"*",
"Reader",
")",
"Reset",
"(",
"reader",
"io",
".",
"Reader",
")",
"{",
"r",
".",
"r",
"=",
"reader",
"\n",
"r",
".",
"err",
"=",
"nil",
"\n",
"r",
".",
"i",
"=",
"0",
"\n",
"r",
".",
"j",
"=",
"0",
"\n",
"r",
".",
... | // Reset discards any buffered data, resets all state, and switches the Snappy
// reader to read from r. This permits reusing a Reader rather than allocating
// a new one. | [
"Reset",
"discards",
"any",
"buffered",
"data",
"resets",
"all",
"state",
"and",
"switches",
"the",
"Snappy",
"reader",
"to",
"read",
"from",
"r",
".",
"This",
"permits",
"reusing",
"a",
"Reader",
"rather",
"than",
"allocating",
"a",
"new",
"one",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/snappy/decode.go#L156-L162 | train |
sajari/docconv | url.go | ConvertURL | func ConvertURL(input io.Reader, readability bool) (string, map[string]string, error) {
meta := make(map[string]string)
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(input)
if err != nil {
return "", nil, err
}
g := goose.New()
article, err := g.ExtractFromURL(buf.String())
if err != nil {
return "", ni... | go | func ConvertURL(input io.Reader, readability bool) (string, map[string]string, error) {
meta := make(map[string]string)
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(input)
if err != nil {
return "", nil, err
}
g := goose.New()
article, err := g.ExtractFromURL(buf.String())
if err != nil {
return "", ni... | [
"func",
"ConvertURL",
"(",
"input",
"io",
".",
"Reader",
",",
"readability",
"bool",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
... | // ConvertURL fetches the HTML page at the URL given in the io.Reader. | [
"ConvertURL",
"fetches",
"the",
"HTML",
"page",
"at",
"the",
"URL",
"given",
"in",
"the",
"io",
".",
"Reader",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/url.go#L11-L31 | train |
sajari/docconv | rtf.go | ConvertRTF | func ConvertRTF(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
var output string
tmpOutput, err := exec.Command("unrtf", "--nopict", "--text", f.Name()).Outp... | go | func ConvertRTF(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
var output string
tmpOutput, err := exec.Command("unrtf", "--nopict", "--text", f.Name()).Outp... | [
"func",
"ConvertRTF",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"NewLocalFile",
"(",
"r",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err"... | // ConvertRTF converts RTF files to text. | [
"ConvertRTF",
"converts",
"RTF",
"files",
"to",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/rtf.go#L12-L52 | train |
sajari/docconv | docx.go | ConvertDocx | func ConvertDocx(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textHeader, textBody, textFooter string
b, err := ioutil.ReadAll(r)
if err != nil {
return "", nil, err
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
return "", nil, fmt.Err... | go | func ConvertDocx(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textHeader, textBody, textFooter string
b, err := ioutil.ReadAll(r)
if err != nil {
return "", nil, err
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
return "", nil, fmt.Err... | [
"func",
"ConvertDocx",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"var",
"textHeader",
",",
"textBo... | // ConvertDocx converts an MS Word docx file to text. | [
"ConvertDocx",
"converts",
"an",
"MS",
"Word",
"docx",
"file",
"to",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docx.go#L14-L79 | train |
sajari/docconv | docx.go | DocxXMLToText | func DocxXMLToText(r io.Reader) (string, error) {
return XMLToText(r, []string{"br", "p", "tab"}, []string{"instrText", "script"}, true)
} | go | func DocxXMLToText(r io.Reader) (string, error) {
return XMLToText(r, []string{"br", "p", "tab"}, []string{"instrText", "script"}, true)
} | [
"func",
"DocxXMLToText",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"XMLToText",
"(",
"r",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"[",
"]",
"string",
"{",
... | // DocxXMLToText converts Docx XML into plain text. | [
"DocxXMLToText",
"converts",
"Docx",
"XML",
"into",
"plain",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docx.go#L96-L98 | train |
sajari/docconv | html.go | ConvertHTML | func ConvertHTML(r io.Reader, readability bool) (string, map[string]string, error) {
meta := make(map[string]string)
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(r)
if err != nil {
return "", nil, err
}
cleanXML, err := Tidy(buf, false)
if err != nil {
log.Println("Tidy:", err)
// Tidy failed, so we n... | go | func ConvertHTML(r io.Reader, readability bool) (string, map[string]string, error) {
meta := make(map[string]string)
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(r)
if err != nil {
return "", nil, err
}
cleanXML, err := Tidy(buf, false)
if err != nil {
log.Println("Tidy:", err)
// Tidy failed, so we n... | [
"func",
"ConvertHTML",
"(",
"r",
"io",
".",
"Reader",
",",
"readability",
"bool",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n\n",
"bu... | // ConvertHTML converts HTML into text. | [
"ConvertHTML",
"converts",
"HTML",
"into",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/html.go#L17-L40 | train |
sajari/docconv | html.go | acceptedHTMLTag | func acceptedHTMLTag(tagName string) bool {
for _, tag := range acceptedHTMLTags {
if tag == tagName {
return true
}
}
return false
} | go | func acceptedHTMLTag(tagName string) bool {
for _, tag := range acceptedHTMLTags {
if tag == tagName {
return true
}
}
return false
} | [
"func",
"acceptedHTMLTag",
"(",
"tagName",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"tag",
":=",
"range",
"acceptedHTMLTags",
"{",
"if",
"tag",
"==",
"tagName",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Tests for known friendly HTML parameters that tidy is unlikely to choke on | [
"Tests",
"for",
"known",
"friendly",
"HTML",
"parameters",
"that",
"tidy",
"is",
"unlikely",
"to",
"choke",
"on"
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/html.go#L50-L57 | train |
sajari/docconv | html.go | HTMLReadability | func HTMLReadability(r io.Reader) []byte {
jr := justext.NewReader(r)
// TODO: Improve this!
jr.Stoplist = readabilityStopList
jr.LengthLow = HTMLReadabilityOptionsValues.LengthLow
jr.LengthHigh = HTMLReadabilityOptionsValues.LengthHigh
jr.StopwordsLow = HTMLReadabilityOptionsValues.StopwordsLow
jr.StopwordsHig... | go | func HTMLReadability(r io.Reader) []byte {
jr := justext.NewReader(r)
// TODO: Improve this!
jr.Stoplist = readabilityStopList
jr.LengthLow = HTMLReadabilityOptionsValues.LengthLow
jr.LengthHigh = HTMLReadabilityOptionsValues.LengthHigh
jr.StopwordsLow = HTMLReadabilityOptionsValues.StopwordsLow
jr.StopwordsHig... | [
"func",
"HTMLReadability",
"(",
"r",
"io",
".",
"Reader",
")",
"[",
"]",
"byte",
"{",
"jr",
":=",
"justext",
".",
"NewReader",
"(",
"r",
")",
"\n\n",
"// TODO: Improve this!",
"jr",
".",
"Stoplist",
"=",
"readabilityStopList",
"\n",
"jr",
".",
"LengthLow",... | // HTMLReadability extracts the readable text in an HTML document | [
"HTMLReadability",
"extracts",
"the",
"readable",
"text",
"in",
"an",
"HTML",
"document"
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/html.go#L130-L160 | train |
sajari/docconv | html.go | HTMLToText | func HTMLToText(input io.Reader) string {
text, _ := XMLToText(input, []string{"br", "p", "h1", "h2", "h3", "h4"}, []string{}, false)
return text
} | go | func HTMLToText(input io.Reader) string {
text, _ := XMLToText(input, []string{"br", "p", "h1", "h2", "h3", "h4"}, []string{}, false)
return text
} | [
"func",
"HTMLToText",
"(",
"input",
"io",
".",
"Reader",
")",
"string",
"{",
"text",
",",
"_",
":=",
"XMLToText",
"(",
"input",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
... | // HTMLToText converts HTML to plain text. | [
"HTMLToText",
"converts",
"HTML",
"to",
"plain",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/html.go#L163-L166 | train |
sajari/docconv | docconv.go | Convert | func Convert(r io.Reader, mimeType string, readability bool) (*Response, error) {
start := time.Now()
var body string
var meta map[string]string
var err error
switch mimeType {
case "application/msword", "application/vnd.ms-word":
body, meta, err = ConvertDoc(r)
case "application/vnd.openxmlformats-officedoc... | go | func Convert(r io.Reader, mimeType string, readability bool) (*Response, error) {
start := time.Now()
var body string
var meta map[string]string
var err error
switch mimeType {
case "application/msword", "application/vnd.ms-word":
body, meta, err = ConvertDoc(r)
case "application/vnd.openxmlformats-officedoc... | [
"func",
"Convert",
"(",
"r",
"io",
".",
"Reader",
",",
"mimeType",
"string",
",",
"readability",
"bool",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n\n",
"var",
"body",
"string",
"\n",
"var",
"... | // Convert a file to plain text. | [
"Convert",
"a",
"file",
"to",
"plain",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docconv.go#L57-L109 | train |
sajari/docconv | docconv.go | ConvertPath | func ConvertPath(path string) (*Response, error) {
mimeType := MimeTypeByExtension(path)
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return Convert(f, mimeType, true)
} | go | func ConvertPath(path string) (*Response, error) {
mimeType := MimeTypeByExtension(path)
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return Convert(f, mimeType, true)
} | [
"func",
"ConvertPath",
"(",
"path",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"mimeType",
":=",
"MimeTypeByExtension",
"(",
"path",
")",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
... | // ConvertPath converts a local path to text. | [
"ConvertPath",
"converts",
"a",
"local",
"path",
"to",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docconv.go#L112-L122 | train |
sajari/docconv | docconv.go | ConvertPathReadability | func ConvertPathReadability(path string, readability bool) ([]byte, error) {
mimeType := MimeTypeByExtension(path)
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
data, err := Convert(f, mimeType, readability)
if err != nil {
return nil, err
}
return json.Marshal(data)
} | go | func ConvertPathReadability(path string, readability bool) ([]byte, error) {
mimeType := MimeTypeByExtension(path)
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
data, err := Convert(f, mimeType, readability)
if err != nil {
return nil, err
}
return json.Marshal(data)
} | [
"func",
"ConvertPathReadability",
"(",
"path",
"string",
",",
"readability",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"mimeType",
":=",
"MimeTypeByExtension",
"(",
"path",
")",
"\n\n",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"... | // ConvertPathReadability converts a local path to text, with the given readability
// option. | [
"ConvertPathReadability",
"converts",
"a",
"local",
"path",
"to",
"text",
"with",
"the",
"given",
"readability",
"option",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docconv.go#L126-L140 | train |
sajari/docconv | client/client.go | New | func New(opts ...Opt) *Client {
c := &Client{
endpoint: DefaultEndpoint,
protocol: DefaultProtocol,
httpClient: DefaultHTTPClient,
}
for _, opt := range opts {
opt(c)
}
return c
} | go | func New(opts ...Opt) *Client {
c := &Client{
endpoint: DefaultEndpoint,
protocol: DefaultProtocol,
httpClient: DefaultHTTPClient,
}
for _, opt := range opts {
opt(c)
}
return c
} | [
"func",
"New",
"(",
"opts",
"...",
"Opt",
")",
"*",
"Client",
"{",
"c",
":=",
"&",
"Client",
"{",
"endpoint",
":",
"DefaultEndpoint",
",",
"protocol",
":",
"DefaultProtocol",
",",
"httpClient",
":",
"DefaultHTTPClient",
",",
"}",
"\n\n",
"for",
"_",
",",... | // New creates a new docconv client for interacting with a docconv HTTP
// server. | [
"New",
"creates",
"a",
"new",
"docconv",
"client",
"for",
"interacting",
"with",
"a",
"docconv",
"HTTP",
"server",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/client/client.go#L55-L66 | train |
sajari/docconv | client/client.go | Convert | func (c *Client) Convert(r io.Reader, filename string) (*Response, error) {
buf := &bytes.Buffer{}
w := multipart.NewWriter(buf)
part, err := w.CreateFormFile("input", filename)
if err != nil {
return nil, err
}
if _, err := io.Copy(part, r); err != nil {
return nil, err
}
if err := w.Close(); err != nil {
... | go | func (c *Client) Convert(r io.Reader, filename string) (*Response, error) {
buf := &bytes.Buffer{}
w := multipart.NewWriter(buf)
part, err := w.CreateFormFile("input", filename)
if err != nil {
return nil, err
}
if _, err := io.Copy(part, r); err != nil {
return nil, err
}
if err := w.Close(); err != nil {
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Convert",
"(",
"r",
"io",
".",
"Reader",
",",
"filename",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"w",
":=",
"multipart",
".",
... | // Convert a file from a local path using the http client | [
"Convert",
"a",
"file",
"from",
"a",
"local",
"path",
"using",
"the",
"http",
"client"
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/client/client.go#L85-L116 | train |
sajari/docconv | client/client.go | ConvertPath | func ConvertPath(c *Client, path string) (*Response, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return c.Convert(f, f.Name())
} | go | func ConvertPath(c *Client, path string) (*Response, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
return c.Convert(f, f.Name())
} | [
"func",
"ConvertPath",
"(",
"c",
"*",
"Client",
",",
"path",
"string",
")",
"(",
"*",
"Response",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"er... | // ConvertPath uses the docconv Client to convert the local file
// found at path. | [
"ConvertPath",
"uses",
"the",
"docconv",
"Client",
"to",
"convert",
"the",
"local",
"file",
"found",
"at",
"path",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/client/client.go#L120-L128 | train |
sajari/docconv | doc.go | ConvertDoc | func ConvertDoc(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
// Meta data
mc := make(chan map[string]string, 1)
go func() {
meta := make(map[string]stri... | go | func ConvertDoc(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
// Meta data
mc := make(chan map[string]string, 1)
go func() {
meta := make(map[string]stri... | [
"func",
"ConvertDoc",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"NewLocalFile",
"(",
"r",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err"... | // ConvertDoc converts an MS Word .doc to text. | [
"ConvertDoc",
"converts",
"an",
"MS",
"Word",
".",
"doc",
"to",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/doc.go#L16-L94 | train |
sajari/docconv | image_ocr.go | ConvertImage | func ConvertImage(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
meta := make(map[string]string)
out := make(chan string, 1)
// TODO: Why is this done in a... | go | func ConvertImage(r io.Reader) (string, map[string]string, error) {
f, err := NewLocalFile(r, "/tmp", "sajari-convert-")
if err != nil {
return "", nil, fmt.Errorf("error creating local file: %v", err)
}
defer f.Done()
meta := make(map[string]string)
out := make(chan string, 1)
// TODO: Why is this done in a... | [
"func",
"ConvertImage",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"NewLocalFile",
"(",
"r",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"er... | // ConvertImage converts images to text.
// Requires gosseract. | [
"ConvertImage",
"converts",
"images",
"to",
"text",
".",
"Requires",
"gosseract",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/image_ocr.go#L20-L39 | train |
sajari/docconv | image_ocr.go | SetImageLanguages | func SetImageLanguages(l string) {
langs.Lock()
langs.lang = l
langs.Unlock()
} | go | func SetImageLanguages(l string) {
langs.Lock()
langs.lang = l
langs.Unlock()
} | [
"func",
"SetImageLanguages",
"(",
"l",
"string",
")",
"{",
"langs",
".",
"Lock",
"(",
")",
"\n",
"langs",
".",
"lang",
"=",
"l",
"\n",
"langs",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetImageLanguages sets the languages parameter passed to gosseract. | [
"SetImageLanguages",
"sets",
"the",
"languages",
"parameter",
"passed",
"to",
"gosseract",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/image_ocr.go#L42-L46 | train |
sajari/docconv | pages.go | ConvertPages | func ConvertPages(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textBody string
b, err := ioutil.ReadAll(r)
if err != nil {
return "", nil, fmt.Errorf("error reading data: %v", err)
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
return ... | go | func ConvertPages(r io.Reader) (string, map[string]string, error) {
meta := make(map[string]string)
var textBody string
b, err := ioutil.ReadAll(r)
if err != nil {
return "", nil, fmt.Errorf("error reading data: %v", err)
}
zr, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
if err != nil {
return ... | [
"func",
"ConvertPages",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"string",
",",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"meta",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"var",
"textBody",
"string",
"\n... | // ConvertPages converts a Pages file to text. | [
"ConvertPages",
"converts",
"a",
"Pages",
"file",
"to",
"text",
"."
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/pages.go#L20-L60 | train |
sajari/docconv | docd/main.go | convertPath | func convertPath(path string, readability bool) ([]byte, error) {
mimeType := docconv.MimeTypeByExtension(path)
if *logLevel >= 1 {
log.Println("Converting file: " + path + " (" + mimeType + ")")
}
// Open file
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
data, err := docconv... | go | func convertPath(path string, readability bool) ([]byte, error) {
mimeType := docconv.MimeTypeByExtension(path)
if *logLevel >= 1 {
log.Println("Converting file: " + path + " (" + mimeType + ")")
}
// Open file
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
data, err := docconv... | [
"func",
"convertPath",
"(",
"path",
"string",
",",
"readability",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"mimeType",
":=",
"docconv",
".",
"MimeTypeByExtension",
"(",
"path",
")",
"\n",
"if",
"*",
"logLevel",
">=",
"1",
"{",
"log",... | // Convert a file given a path | [
"Convert",
"a",
"file",
"given",
"a",
"path"
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docd/main.go#L53-L78 | train |
sajari/docconv | docd/main.go | serve | func serve() {
http.HandleFunc("/convert", func(w http.ResponseWriter, r *http.Request) {
// Readability flag. Currently only used for HTML
var readability bool
if r.FormValue("readability") == "1" {
readability = true
if *logLevel >= 2 {
log.Println("Readability is on")
}
}
path := r.FormValue... | go | func serve() {
http.HandleFunc("/convert", func(w http.ResponseWriter, r *http.Request) {
// Readability flag. Currently only used for HTML
var readability bool
if r.FormValue("readability") == "1" {
readability = true
if *logLevel >= 2 {
log.Println("Readability is on")
}
}
path := r.FormValue... | [
"func",
"serve",
"(",
")",
"{",
"http",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"// Readability flag. Currently only used for HTML",
"var",
"readability",
"boo... | // Start the conversion web service | [
"Start",
"the",
"conversion",
"web",
"service"
] | eedabc494f8e97c31f94c70453273f16dbecbc6f | https://github.com/sajari/docconv/blob/eedabc494f8e97c31f94c70453273f16dbecbc6f/docd/main.go#L81-L146 | 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.