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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
inverse-inc/packetfence | go/caddy/caddy/caddyhttp/httpserver/graceful.go | Close | func (c gracefulConn) Close() error {
err := c.Conn.Close()
if err != nil {
return err
}
// close can fail on http2 connections (as of Oct. 2015, before http2 in std lib)
// so don't decrement count unless close succeeds
c.connWg.Done()
return nil
} | go | func (c gracefulConn) Close() error {
err := c.Conn.Close()
if err != nil {
return err
}
// close can fail on http2 connections (as of Oct. 2015, before http2 in std lib)
// so don't decrement count unless close succeeds
c.connWg.Done()
return nil
} | [
"func",
"(",
"c",
"gracefulConn",
")",
"Close",
"(",
")",
"error",
"{",
"err",
":=",
"c",
".",
"Conn",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// close can fail on http2 connections (as of Oct. 2015, ... | // Close closes c's underlying connection while updating the wg count. | [
"Close",
"closes",
"c",
"s",
"underlying",
"connection",
"while",
"updating",
"the",
"wg",
"count",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddyhttp/httpserver/graceful.go#L71-L80 | train |
inverse-inc/packetfence | go/caddy/caddy/controller.go | OnRestart | func (c *Controller) OnRestart(fn func() error) {
c.instance.onRestart = append(c.instance.onRestart, fn)
} | go | func (c *Controller) OnRestart(fn func() error) {
c.instance.onRestart = append(c.instance.onRestart, fn)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"OnRestart",
"(",
"fn",
"func",
"(",
")",
"error",
")",
"{",
"c",
".",
"instance",
".",
"onRestart",
"=",
"append",
"(",
"c",
".",
"instance",
".",
"onRestart",
",",
"fn",
")",
"\n",
"}"
] | // OnRestart adds fn to the list of callback functions to execute
// when the server is about to be restarted. | [
"OnRestart",
"adds",
"fn",
"to",
"the",
"list",
"of",
"callback",
"functions",
"to",
"execute",
"when",
"the",
"server",
"is",
"about",
"to",
"be",
"restarted",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/controller.go#L71-L73 | train |
inverse-inc/packetfence | go/caddy/caddy/controller.go | OnFinalShutdown | func (c *Controller) OnFinalShutdown(fn func() error) {
c.instance.onFinalShutdown = append(c.instance.onFinalShutdown, fn)
} | go | func (c *Controller) OnFinalShutdown(fn func() error) {
c.instance.onFinalShutdown = append(c.instance.onFinalShutdown, fn)
} | [
"func",
"(",
"c",
"*",
"Controller",
")",
"OnFinalShutdown",
"(",
"fn",
"func",
"(",
")",
"error",
")",
"{",
"c",
".",
"instance",
".",
"onFinalShutdown",
"=",
"append",
"(",
"c",
".",
"instance",
".",
"onFinalShutdown",
",",
"fn",
")",
"\n",
"}"
] | // OnFinalShutdown adds fn to the list of callback functions to execute
// when the server is about to be shut down NOT as part of a restart. | [
"OnFinalShutdown",
"adds",
"fn",
"to",
"the",
"list",
"of",
"callback",
"functions",
"to",
"execute",
"when",
"the",
"server",
"is",
"about",
"to",
"be",
"shut",
"down",
"NOT",
"as",
"part",
"of",
"a",
"restart",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/controller.go#L83-L85 | train |
inverse-inc/packetfence | go/coredns/plugin/hosts/hostsfile.go | parse | func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap {
hmap := newHostsMap()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Bytes()
if i := bytes.Index(line, []byte{'#'}); i >= 0 {
// Discard comments.
line = line[0:i]
}
f := bytes.Fields(line)
if len(f) < 2 {
... | go | func (h *Hostsfile) parse(r io.Reader, override *hostsMap) *hostsMap {
hmap := newHostsMap()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Bytes()
if i := bytes.Index(line, []byte{'#'}); i >= 0 {
// Discard comments.
line = line[0:i]
}
f := bytes.Fields(line)
if len(f) < 2 {
... | [
"func",
"(",
"h",
"*",
"Hostsfile",
")",
"parse",
"(",
"r",
"io",
".",
"Reader",
",",
"override",
"*",
"hostsMap",
")",
"*",
"hostsMap",
"{",
"hmap",
":=",
"newHostsMap",
"(",
")",
"\n\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
... | // Parse reads the hostsfile and populates the byName and byAddr maps. | [
"Parse",
"reads",
"the",
"hostsfile",
"and",
"populates",
"the",
"byName",
"and",
"byAddr",
"maps",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/hosts/hostsfile.go#L117-L169 | train |
inverse-inc/packetfence | go/coredns/plugin/hosts/hostsfile.go | LookupStaticAddr | func (h *Hostsfile) LookupStaticAddr(addr string) []string {
h.RLock()
defer h.RUnlock()
addr = parseLiteralIP(addr).String()
if addr == "" {
return nil
}
if len(h.hmap.byAddr) != 0 {
if hosts, ok := h.hmap.byAddr[addr]; ok {
hostsCp := make([]string, len(hosts))
copy(hostsCp, hosts)
return hostsCp
... | go | func (h *Hostsfile) LookupStaticAddr(addr string) []string {
h.RLock()
defer h.RUnlock()
addr = parseLiteralIP(addr).String()
if addr == "" {
return nil
}
if len(h.hmap.byAddr) != 0 {
if hosts, ok := h.hmap.byAddr[addr]; ok {
hostsCp := make([]string, len(hosts))
copy(hostsCp, hosts)
return hostsCp
... | [
"func",
"(",
"h",
"*",
"Hostsfile",
")",
"LookupStaticAddr",
"(",
"addr",
"string",
")",
"[",
"]",
"string",
"{",
"h",
".",
"RLock",
"(",
")",
"\n",
"defer",
"h",
".",
"RUnlock",
"(",
")",
"\n",
"addr",
"=",
"parseLiteralIP",
"(",
"addr",
")",
".",... | // LookupStaticAddr looks up the hosts for the given address from the hosts file. | [
"LookupStaticAddr",
"looks",
"up",
"the",
"hosts",
"for",
"the",
"given",
"address",
"from",
"the",
"hosts",
"file",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/hosts/hostsfile.go#L213-L228 | train |
inverse-inc/packetfence | go/coredns/plugin/cache/cache.go | key | func key(m *dns.Msg, t response.Type, do bool) int {
// We don't store truncated responses.
if m.Truncated {
return -1
}
// Nor errors or Meta or Update
if t == response.OtherError || t == response.Meta || t == response.Update {
return -1
}
return int(hash(m.Question[0].Name, m.Question[0].Qtype, do))
} | go | func key(m *dns.Msg, t response.Type, do bool) int {
// We don't store truncated responses.
if m.Truncated {
return -1
}
// Nor errors or Meta or Update
if t == response.OtherError || t == response.Meta || t == response.Update {
return -1
}
return int(hash(m.Question[0].Name, m.Question[0].Qtype, do))
} | [
"func",
"key",
"(",
"m",
"*",
"dns",
".",
"Msg",
",",
"t",
"response",
".",
"Type",
",",
"do",
"bool",
")",
"int",
"{",
"// We don't store truncated responses.",
"if",
"m",
".",
"Truncated",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"// Nor errors or Met... | // Return key under which we store the item, -1 will be returned if we don't store the
// message.
// Currently we do not cache Truncated, errors zone transfers or dynamic update messages. | [
"Return",
"key",
"under",
"which",
"we",
"store",
"the",
"item",
"-",
"1",
"will",
"be",
"returned",
"if",
"we",
"don",
"t",
"store",
"the",
"message",
".",
"Currently",
"we",
"do",
"not",
"cache",
"Truncated",
"errors",
"zone",
"transfers",
"or",
"dynam... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/cache/cache.go#L40-L51 | train |
inverse-inc/packetfence | go/caddy/caddy/startupshutdown/startupshutdown.go | registerCallback | func registerCallback(c *caddy.Controller, registerFunc func(func() error)) error {
var funcs []func() error
for c.Next() {
args := c.RemainingArgs()
if len(args) == 0 {
return c.ArgErr()
}
nonblock := false
if len(args) > 1 && args[len(args)-1] == "&" {
// Run command in background; non-blocking
... | go | func registerCallback(c *caddy.Controller, registerFunc func(func() error)) error {
var funcs []func() error
for c.Next() {
args := c.RemainingArgs()
if len(args) == 0 {
return c.ArgErr()
}
nonblock := false
if len(args) > 1 && args[len(args)-1] == "&" {
// Run command in background; non-blocking
... | [
"func",
"registerCallback",
"(",
"c",
"*",
"caddy",
".",
"Controller",
",",
"registerFunc",
"func",
"(",
"func",
"(",
")",
"error",
")",
")",
"error",
"{",
"var",
"funcs",
"[",
"]",
"func",
"(",
")",
"error",
"\n\n",
"for",
"c",
".",
"Next",
"(",
"... | // registerCallback registers a callback function to execute by
// using c to parse the directive. It registers the callback
// to be executed using registerFunc. | [
"registerCallback",
"registers",
"a",
"callback",
"function",
"to",
"execute",
"by",
"using",
"c",
"to",
"parse",
"the",
"directive",
".",
"It",
"registers",
"the",
"callback",
"to",
"be",
"executed",
"using",
"registerFunc",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/startupshutdown/startupshutdown.go#L30-L73 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/msg/msg.go | AddrMsg | func (b *Builder) AddrMsg(a net.Addr, m *dns.Msg) (err error) {
err = b.RemoteAddr(a)
if err != nil {
return
}
return b.Msg(m)
} | go | func (b *Builder) AddrMsg(a net.Addr, m *dns.Msg) (err error) {
err = b.RemoteAddr(a)
if err != nil {
return
}
return b.Msg(m)
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"AddrMsg",
"(",
"a",
"net",
".",
"Addr",
",",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"b",
".",
"RemoteAddr",
"(",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // AddrMsg parses the info of net.Addr and dns.Msg. | [
"AddrMsg",
"parses",
"the",
"info",
"of",
"net",
".",
"Addr",
"and",
"dns",
".",
"Msg",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/msg/msg.go#L20-L26 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/msg/msg.go | Msg | func (b *Builder) Msg(m *dns.Msg) (err error) {
if b.Full {
err = b.Pack(m)
}
return
} | go | func (b *Builder) Msg(m *dns.Msg) (err error) {
if b.Full {
err = b.Pack(m)
}
return
} | [
"func",
"(",
"b",
"*",
"Builder",
")",
"Msg",
"(",
"m",
"*",
"dns",
".",
"Msg",
")",
"(",
"err",
"error",
")",
"{",
"if",
"b",
".",
"Full",
"{",
"err",
"=",
"b",
".",
"Pack",
"(",
"m",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Msg parses the info of dns.Msg. | [
"Msg",
"parses",
"the",
"info",
"of",
"dns",
".",
"Msg",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/msg/msg.go#L29-L34 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/msg/msg.go | HostPort | func (d *Data) HostPort(addr string) error {
ip, port, err := net.SplitHostPort(addr)
if err != nil {
return err
}
p, err := strconv.ParseUint(port, 10, 32)
if err != nil {
return err
}
d.Port = uint32(p)
if ip := net.ParseIP(ip); ip != nil {
d.Address = []byte(ip)
if ip := ip.To4(); ip != nil {
d.S... | go | func (d *Data) HostPort(addr string) error {
ip, port, err := net.SplitHostPort(addr)
if err != nil {
return err
}
p, err := strconv.ParseUint(port, 10, 32)
if err != nil {
return err
}
d.Port = uint32(p)
if ip := net.ParseIP(ip); ip != nil {
d.Address = []byte(ip)
if ip := ip.To4(); ip != nil {
d.S... | [
"func",
"(",
"d",
"*",
"Data",
")",
"HostPort",
"(",
"addr",
"string",
")",
"error",
"{",
"ip",
",",
"port",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
... | // HostPort decodes into Data any string returned by dnsutil.ParseHostPortOrFile. | [
"HostPort",
"decodes",
"into",
"Data",
"any",
"string",
"returned",
"by",
"dnsutil",
".",
"ParseHostPortOrFile",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/msg/msg.go#L48-L69 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/msg/msg.go | RemoteAddr | func (d *Data) RemoteAddr(remote net.Addr) error {
switch addr := remote.(type) {
case *net.TCPAddr:
d.Address = addr.IP
d.Port = uint32(addr.Port)
d.SocketProto = tap.SocketProtocol_TCP
case *net.UDPAddr:
d.Address = addr.IP
d.Port = uint32(addr.Port)
d.SocketProto = tap.SocketProtocol_UDP
default:
r... | go | func (d *Data) RemoteAddr(remote net.Addr) error {
switch addr := remote.(type) {
case *net.TCPAddr:
d.Address = addr.IP
d.Port = uint32(addr.Port)
d.SocketProto = tap.SocketProtocol_TCP
case *net.UDPAddr:
d.Address = addr.IP
d.Port = uint32(addr.Port)
d.SocketProto = tap.SocketProtocol_UDP
default:
r... | [
"func",
"(",
"d",
"*",
"Data",
")",
"RemoteAddr",
"(",
"remote",
"net",
".",
"Addr",
")",
"error",
"{",
"switch",
"addr",
":=",
"remote",
".",
"(",
"type",
")",
"{",
"case",
"*",
"net",
".",
"TCPAddr",
":",
"d",
".",
"Address",
"=",
"addr",
".",
... | // RemoteAddr parses the information about the remote address into Data. | [
"RemoteAddr",
"parses",
"the",
"information",
"about",
"the",
"remote",
"address",
"into",
"Data",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/msg/msg.go#L72-L93 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/msg/msg.go | Pack | func (d *Data) Pack(m *dns.Msg) error {
packed, err := m.Pack()
if err != nil {
return err
}
d.Packed = packed
return nil
} | go | func (d *Data) Pack(m *dns.Msg) error {
packed, err := m.Pack()
if err != nil {
return err
}
d.Packed = packed
return nil
} | [
"func",
"(",
"d",
"*",
"Data",
")",
"Pack",
"(",
"m",
"*",
"dns",
".",
"Msg",
")",
"error",
"{",
"packed",
",",
"err",
":=",
"m",
".",
"Pack",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"d",
".",
"Packe... | // Pack encodes the DNS message into Data. | [
"Pack",
"encodes",
"the",
"DNS",
"message",
"into",
"Data",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/msg/msg.go#L96-L103 | train |
inverse-inc/packetfence | go/coredns/plugin/proxy/google.go | newUpstream | func newUpstream(hosts []string, old *staticUpstream) Upstream {
upstream := &staticUpstream{
from: old.from,
HealthCheck: healthcheck.HealthCheck{
FailTimeout: 5 * time.Second,
MaxFails: 3,
},
ex: old.ex,
IgnoredSubDomains: old.IgnoredSubDomains,
}
upstream.Hosts = make([]*healthc... | go | func newUpstream(hosts []string, old *staticUpstream) Upstream {
upstream := &staticUpstream{
from: old.from,
HealthCheck: healthcheck.HealthCheck{
FailTimeout: 5 * time.Second,
MaxFails: 3,
},
ex: old.ex,
IgnoredSubDomains: old.IgnoredSubDomains,
}
upstream.Hosts = make([]*healthc... | [
"func",
"newUpstream",
"(",
"hosts",
"[",
"]",
"string",
",",
"old",
"*",
"staticUpstream",
")",
"Upstream",
"{",
"upstream",
":=",
"&",
"staticUpstream",
"{",
"from",
":",
"old",
".",
"from",
",",
"HealthCheck",
":",
"healthcheck",
".",
"HealthCheck",
"{"... | // newUpstream returns an upstream initialized with hosts. | [
"newUpstream",
"returns",
"an",
"upstream",
"initialized",
"with",
"hosts",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/proxy/google.go#L191-L214 | train |
inverse-inc/packetfence | go/caddy/caddy/caddyfile/parse.go | replaceEnvReferences | func replaceEnvReferences(s, refStart, refEnd string) string {
index := strings.Index(s, refStart)
for index != -1 {
endIndex := strings.Index(s, refEnd)
if endIndex != -1 {
ref := s[index : endIndex+len(refEnd)]
s = strings.Replace(s, ref, os.Getenv(ref[len(refStart):len(ref)-len(refEnd)]), -1)
} else {
... | go | func replaceEnvReferences(s, refStart, refEnd string) string {
index := strings.Index(s, refStart)
for index != -1 {
endIndex := strings.Index(s, refEnd)
if endIndex != -1 {
ref := s[index : endIndex+len(refEnd)]
s = strings.Replace(s, ref, os.Getenv(ref[len(refStart):len(ref)-len(refEnd)]), -1)
} else {
... | [
"func",
"replaceEnvReferences",
"(",
"s",
",",
"refStart",
",",
"refEnd",
"string",
")",
"string",
"{",
"index",
":=",
"strings",
".",
"Index",
"(",
"s",
",",
"refStart",
")",
"\n",
"for",
"index",
"!=",
"-",
"1",
"{",
"endIndex",
":=",
"strings",
".",... | // replaceEnvReferences performs the actual replacement of env variables
// in s, given the placeholder start and placeholder end strings. | [
"replaceEnvReferences",
"performs",
"the",
"actual",
"replacement",
"of",
"env",
"variables",
"in",
"s",
"given",
"the",
"placeholder",
"start",
"and",
"placeholder",
"end",
"strings",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddyfile/parse.go#L396-L409 | train |
inverse-inc/packetfence | go/caddy/caddy/caddyhttp/httpserver/https.go | redirPlaintextHost | func redirPlaintextHost(cfg *SiteConfig) *SiteConfig {
redirPort := cfg.Addr.Port
if redirPort == "443" {
// default port is redundant
redirPort = ""
}
redirMiddleware := func(next Handler) Handler {
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
toURL := "https://" + r.Host... | go | func redirPlaintextHost(cfg *SiteConfig) *SiteConfig {
redirPort := cfg.Addr.Port
if redirPort == "443" {
// default port is redundant
redirPort = ""
}
redirMiddleware := func(next Handler) Handler {
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) (int, error) {
toURL := "https://" + r.Host... | [
"func",
"redirPlaintextHost",
"(",
"cfg",
"*",
"SiteConfig",
")",
"*",
"SiteConfig",
"{",
"redirPort",
":=",
"cfg",
".",
"Addr",
".",
"Port",
"\n",
"if",
"redirPort",
"==",
"\"",
"\"",
"{",
"// default port is redundant",
"redirPort",
"=",
"\"",
"\"",
"\n",
... | // redirPlaintextHost returns a new plaintext HTTP configuration for
// a virtualHost that simply redirects to cfg, which is assumed to
// be the HTTPS configuration. The returned configuration is set
// to listen on port 80. The TLS field of cfg must not be nil. | [
"redirPlaintextHost",
"returns",
"a",
"new",
"plaintext",
"HTTP",
"configuration",
"for",
"a",
"virtualHost",
"that",
"simply",
"redirects",
"to",
"cfg",
"which",
"is",
"assumed",
"to",
"be",
"the",
"HTTPS",
"configuration",
".",
"The",
"returned",
"configuration"... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddyhttp/httpserver/https.go#L139-L166 | train |
inverse-inc/packetfence | go/coredns/plugin/metrics/vars/report.go | Report | func Report(req request.Request, zone, rcode string, size int, start time.Time) {
// Proto and Family.
net := req.Proto()
fam := "1"
if req.Family() == 2 {
fam = "2"
}
typ := req.QType()
RequestCount.WithLabelValues(zone, net, fam).Inc()
RequestDuration.WithLabelValues(zone).Observe(float64(time.Since(start... | go | func Report(req request.Request, zone, rcode string, size int, start time.Time) {
// Proto and Family.
net := req.Proto()
fam := "1"
if req.Family() == 2 {
fam = "2"
}
typ := req.QType()
RequestCount.WithLabelValues(zone, net, fam).Inc()
RequestDuration.WithLabelValues(zone).Observe(float64(time.Since(start... | [
"func",
"Report",
"(",
"req",
"request",
".",
"Request",
",",
"zone",
",",
"rcode",
"string",
",",
"size",
"int",
",",
"start",
"time",
".",
"Time",
")",
"{",
"// Proto and Family.",
"net",
":=",
"req",
".",
"Proto",
"(",
")",
"\n",
"fam",
":=",
"\""... | // Report reports the metrics data associcated with request. | [
"Report",
"reports",
"the",
"metrics",
"data",
"associcated",
"with",
"request",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/metrics/vars/report.go#L12-L39 | train |
inverse-inc/packetfence | go/caddy/api-aaa/api-aaa.go | setup | func setup(c *caddy.Controller) error {
ctx := log.LoggerNewContext(context.Background())
apiAAA, err := buildApiAAAHandler(ctx)
if err != nil {
return err
}
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
apiAAA.Next = next
return apiAAA
})
return nil
} | go | func setup(c *caddy.Controller) error {
ctx := log.LoggerNewContext(context.Background())
apiAAA, err := buildApiAAAHandler(ctx)
if err != nil {
return err
}
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
apiAAA.Next = next
return apiAAA
})
return nil
} | [
"func",
"setup",
"(",
"c",
"*",
"caddy",
".",
"Controller",
")",
"error",
"{",
"ctx",
":=",
"log",
".",
"LoggerNewContext",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n\n",
"apiAAA",
",",
"err",
":=",
"buildApiAAAHandler",
"(",
"ctx",
")",
"\n... | // Setup the api-aaa middleware
// Also loads the pfconfig resources and registers them in the pool | [
"Setup",
"the",
"api",
"-",
"aaa",
"middleware",
"Also",
"loads",
"the",
"pfconfig",
"resources",
"and",
"registers",
"them",
"in",
"the",
"pool"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/api-aaa/api-aaa.go#L50-L65 | train |
inverse-inc/packetfence | go/caddy/api-aaa/api-aaa.go | buildApiAAAHandler | func buildApiAAAHandler(ctx context.Context) (ApiAAAHandler, error) {
apiAAA := ApiAAAHandler{}
pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.PfConf.Webservices)
pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.UnifiedApiSystemUser)
pfconfigdriver.PfconfigPool.AddStruct(ctx, &... | go | func buildApiAAAHandler(ctx context.Context) (ApiAAAHandler, error) {
apiAAA := ApiAAAHandler{}
pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.PfConf.Webservices)
pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.UnifiedApiSystemUser)
pfconfigdriver.PfconfigPool.AddStruct(ctx, &... | [
"func",
"buildApiAAAHandler",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"ApiAAAHandler",
",",
"error",
")",
"{",
"apiAAA",
":=",
"ApiAAAHandler",
"{",
"}",
"\n\n",
"pfconfigdriver",
".",
"PfconfigPool",
".",
"AddStruct",
"(",
"ctx",
",",
"&",
"pfconfi... | // Build the ApiAAAHandler which will initialize the cache and instantiate the router along with its routes | [
"Build",
"the",
"ApiAAAHandler",
"which",
"will",
"initialize",
"the",
"cache",
"and",
"instantiate",
"the",
"router",
"along",
"with",
"its",
"routes"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/api-aaa/api-aaa.go#L68-L113 | train |
inverse-inc/packetfence | go/caddy/api-aaa/api-aaa.go | handleLogin | func (h ApiAAAHandler) handleLogin(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("api-aaa.login")
var loginParams struct {
Username string
Password string
}
err := json.NewDecoder(r.Body).Decode(&loginParams)
if err != nil {
msg :... | go | func (h ApiAAAHandler) handleLogin(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("api-aaa.login")
var loginParams struct {
Username string
Password string
}
err := json.NewDecoder(r.Body).Decode(&loginParams)
if err != nil {
msg :... | [
"func",
"(",
"h",
"ApiAAAHandler",
")",
"handleLogin",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"p",
"httprouter",
".",
"Params",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"defer",
"statsd... | // Handle an API login | [
"Handle",
"an",
"API",
"login"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/api-aaa/api-aaa.go#L116-L149 | train |
inverse-inc/packetfence | go/caddy/api-aaa/api-aaa.go | handleTokenInfo | func (h ApiAAAHandler) handleTokenInfo(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("api-aaa.token_info")
info, expiration := h.authorization.GetTokenInfoFromBearerRequest(ctx, r)
if info != nil {
// We'll want to render the roles as an... | go | func (h ApiAAAHandler) handleTokenInfo(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("api-aaa.token_info")
info, expiration := h.authorization.GetTokenInfoFromBearerRequest(ctx, r)
if info != nil {
// We'll want to render the roles as an... | [
"func",
"(",
"h",
"ApiAAAHandler",
")",
"handleTokenInfo",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"p",
"httprouter",
".",
"Params",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"defer",
"st... | // Handle getting the token info | [
"Handle",
"getting",
"the",
"token",
"info"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/api-aaa/api-aaa.go#L152-L192 | train |
inverse-inc/packetfence | go/coredns/core/dnsserver/server-grpc.go | NewServergRPC | func NewServergRPC(addr string, group []*Config) (*ServergRPC, error) {
s, err := NewServer(addr, group)
if err != nil {
return nil, err
}
gs := &ServergRPC{Server: s}
return gs, nil
} | go | func NewServergRPC(addr string, group []*Config) (*ServergRPC, error) {
s, err := NewServer(addr, group)
if err != nil {
return nil, err
}
gs := &ServergRPC{Server: s}
return gs, nil
} | [
"func",
"NewServergRPC",
"(",
"addr",
"string",
",",
"group",
"[",
"]",
"*",
"Config",
")",
"(",
"*",
"ServergRPC",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"NewServer",
"(",
"addr",
",",
"group",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // NewServergRPC returns a new CoreDNS GRPC server and compiles all plugin in to it. | [
"NewServergRPC",
"returns",
"a",
"new",
"CoreDNS",
"GRPC",
"server",
"and",
"compiles",
"all",
"plugin",
"in",
"to",
"it",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/core/dnsserver/server-grpc.go#L28-L36 | train |
inverse-inc/packetfence | go/coredns/core/dnsserver/server-grpc.go | Query | func (s *ServergRPC) Query(ctx context.Context, in *pb.DnsPacket) (*pb.DnsPacket, error) {
msg := new(dns.Msg)
err := msg.Unpack(in.Msg)
if err != nil {
return nil, err
}
p, ok := peer.FromContext(ctx)
if !ok {
return nil, errors.New("no peer in gRPC context")
}
a, ok := p.Addr.(*net.TCPAddr)
if !ok {
... | go | func (s *ServergRPC) Query(ctx context.Context, in *pb.DnsPacket) (*pb.DnsPacket, error) {
msg := new(dns.Msg)
err := msg.Unpack(in.Msg)
if err != nil {
return nil, err
}
p, ok := peer.FromContext(ctx)
if !ok {
return nil, errors.New("no peer in gRPC context")
}
a, ok := p.Addr.(*net.TCPAddr)
if !ok {
... | [
"func",
"(",
"s",
"*",
"ServergRPC",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"in",
"*",
"pb",
".",
"DnsPacket",
")",
"(",
"*",
"pb",
".",
"DnsPacket",
",",
"error",
")",
"{",
"msg",
":=",
"new",
"(",
"dns",
".",
"Msg",
")",
"\... | // Query is the main entry-point into the gRPC server. From here we call ServeDNS like
// any normal server. We use a custom responseWriter to pick up the bytes we need to write
// back to the client as a protobuf. | [
"Query",
"is",
"the",
"main",
"entry",
"-",
"point",
"into",
"the",
"gRPC",
"server",
".",
"From",
"here",
"we",
"call",
"ServeDNS",
"like",
"any",
"normal",
"server",
".",
"We",
"use",
"a",
"custom",
"responseWriter",
"to",
"pick",
"up",
"the",
"bytes",... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/core/dnsserver/server-grpc.go#L119-L147 | train |
inverse-inc/packetfence | go/coredns/core/dnsserver/server.go | DefaultErrorFunc | func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rc int) {
state := request.Request{W: w, Req: r}
answer := new(dns.Msg)
answer.SetRcode(r, rc)
state.SizeAndDo(answer)
vars.Report(state, vars.Dropped, rcode.ToString(rc), answer.Len(), time.Now())
w.WriteMsg(answer)
} | go | func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rc int) {
state := request.Request{W: w, Req: r}
answer := new(dns.Msg)
answer.SetRcode(r, rc)
state.SizeAndDo(answer)
vars.Report(state, vars.Dropped, rcode.ToString(rc), answer.Len(), time.Now())
w.WriteMsg(answer)
} | [
"func",
"DefaultErrorFunc",
"(",
"w",
"dns",
".",
"ResponseWriter",
",",
"r",
"*",
"dns",
".",
"Msg",
",",
"rc",
"int",
")",
"{",
"state",
":=",
"request",
".",
"Request",
"{",
"W",
":",
"w",
",",
"Req",
":",
"r",
"}",
"\n\n",
"answer",
":=",
"ne... | // DefaultErrorFunc responds to an DNS request with an error. | [
"DefaultErrorFunc",
"responds",
"to",
"an",
"DNS",
"request",
"with",
"an",
"error",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/core/dnsserver/server.go#L304-L315 | train |
inverse-inc/packetfence | go/coredns/plugin/file/reload.go | Reload | func (z *Zone) Reload() error {
if z.NoReload {
return nil
}
tick := time.NewTicker(TickTime)
go func() {
for {
select {
case <-tick.C:
reader, err := os.Open(z.file)
if err != nil {
log.Printf("[ERROR] Failed to open zone %q in %q: %v", z.origin, z.file, err)
continue
}
ser... | go | func (z *Zone) Reload() error {
if z.NoReload {
return nil
}
tick := time.NewTicker(TickTime)
go func() {
for {
select {
case <-tick.C:
reader, err := os.Open(z.file)
if err != nil {
log.Printf("[ERROR] Failed to open zone %q in %q: %v", z.origin, z.file, err)
continue
}
ser... | [
"func",
"(",
"z",
"*",
"Zone",
")",
"Reload",
"(",
")",
"error",
"{",
"if",
"z",
".",
"NoReload",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"tick",
":=",
"time",
".",
"NewTicker",
"(",
"TickTime",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
... | // Reload reloads a zone when it is changed on disk. If z.NoRoload is true, no reloading will be done. | [
"Reload",
"reloads",
"a",
"zone",
"when",
"it",
"is",
"changed",
"on",
"disk",
".",
"If",
"z",
".",
"NoRoload",
"is",
"true",
"no",
"reloading",
"will",
"be",
"done",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/file/reload.go#L13-L57 | train |
inverse-inc/packetfence | go/caddy/caddy/caddyhttp/proxy/upstream.go | NewStaticUpstreams | func NewStaticUpstreams(c caddyfile.Dispenser) ([]Upstream, error) {
var upstreams []Upstream
for c.Next() {
upstream := &staticUpstream{
from: "",
upstreamHeaders: make(http.Header),
downstreamHeaders: make(http.Header),
Hosts: nil,
Policy: &Random{},
MaxFail... | go | func NewStaticUpstreams(c caddyfile.Dispenser) ([]Upstream, error) {
var upstreams []Upstream
for c.Next() {
upstream := &staticUpstream{
from: "",
upstreamHeaders: make(http.Header),
downstreamHeaders: make(http.Header),
Hosts: nil,
Policy: &Random{},
MaxFail... | [
"func",
"NewStaticUpstreams",
"(",
"c",
"caddyfile",
".",
"Dispenser",
")",
"(",
"[",
"]",
"Upstream",
",",
"error",
")",
"{",
"var",
"upstreams",
"[",
"]",
"Upstream",
"\n",
"for",
"c",
".",
"Next",
"(",
")",
"{",
"upstream",
":=",
"&",
"staticUpstrea... | // NewStaticUpstreams parses the configuration input and sets up
// static upstreams for the proxy middleware. | [
"NewStaticUpstreams",
"parses",
"the",
"configuration",
"input",
"and",
"sets",
"up",
"static",
"upstreams",
"for",
"the",
"proxy",
"middleware",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddyhttp/proxy/upstream.go#L48-L117 | train |
inverse-inc/packetfence | go/coredns/plugin/pfdns/pfdns.go | WebservicesInit | func (pf *pfdns) WebservicesInit() error {
var ctx = context.Background()
var webservices pfconfigdriver.PfConfWebservices
webservices.PfconfigNS = "config::Pf"
webservices.PfconfigMethod = "hash_element"
webservices.PfconfigHashNS = "webservices"
pfconfigdriver.FetchDecodeSocket(ctx, &webservices)
pf.Webservic... | go | func (pf *pfdns) WebservicesInit() error {
var ctx = context.Background()
var webservices pfconfigdriver.PfConfWebservices
webservices.PfconfigNS = "config::Pf"
webservices.PfconfigMethod = "hash_element"
webservices.PfconfigHashNS = "webservices"
pfconfigdriver.FetchDecodeSocket(ctx, &webservices)
pf.Webservic... | [
"func",
"(",
"pf",
"*",
"pfdns",
")",
"WebservicesInit",
"(",
")",
"error",
"{",
"var",
"ctx",
"=",
"context",
".",
"Background",
"(",
")",
"\n",
"var",
"webservices",
"pfconfigdriver",
".",
"PfConfWebservices",
"\n",
"webservices",
".",
"PfconfigNS",
"=",
... | // WebservicesInit read pfconfig webservices configuration | [
"WebservicesInit",
"read",
"pfconfig",
"webservices",
"configuration"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/pfdns/pfdns.go#L509-L520 | train |
inverse-inc/packetfence | go/coredns/plugin/pfdns/pfdns.go | addDetectionMechanismsToList | func (pf *pfdns) addDetectionMechanismsToList(ctx context.Context, r string) error {
rgx, err := regexp.Compile(r)
if err == nil {
pf.mutex.Lock()
pf.detectionMechanisms = append(pf.detectionMechanisms, rgx)
pf.mutex.Unlock()
} else {
log.LoggerWContext(ctx).Error(fmt.Sprintf("Not able to compile the regexp ... | go | func (pf *pfdns) addDetectionMechanismsToList(ctx context.Context, r string) error {
rgx, err := regexp.Compile(r)
if err == nil {
pf.mutex.Lock()
pf.detectionMechanisms = append(pf.detectionMechanisms, rgx)
pf.mutex.Unlock()
} else {
log.LoggerWContext(ctx).Error(fmt.Sprintf("Not able to compile the regexp ... | [
"func",
"(",
"pf",
"*",
"pfdns",
")",
"addDetectionMechanismsToList",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"string",
")",
"error",
"{",
"rgx",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"r",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",... | // addDetectionMechanismsToList add all detection mechanisms in a list | [
"addDetectionMechanismsToList",
"add",
"all",
"detection",
"mechanisms",
"in",
"a",
"list"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/pfdns/pfdns.go#L736-L746 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/user.go | newUser | func newUser(email string) (User, error) {
user := User{Email: email}
privateKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
if err != nil {
return user, errors.New("error generating private key: " + err.Error())
}
user.key = privateKey
return user, nil
} | go | func newUser(email string) (User, error) {
user := User{Email: email}
privateKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
if err != nil {
return user, errors.New("error generating private key: " + err.Error())
}
user.key = privateKey
return user, nil
} | [
"func",
"newUser",
"(",
"email",
"string",
")",
"(",
"User",
",",
"error",
")",
"{",
"user",
":=",
"User",
"{",
"Email",
":",
"email",
"}",
"\n",
"privateKey",
",",
"err",
":=",
"ecdsa",
".",
"GenerateKey",
"(",
"elliptic",
".",
"P384",
"(",
")",
"... | // newUser creates a new User for the given email address
// with a new private key. This function does NOT save the
// user to disk or register it via ACME. If you want to use
// a user account that might already exist, call getUser
// instead. It does NOT prompt the user. | [
"newUser",
"creates",
"a",
"new",
"User",
"for",
"the",
"given",
"email",
"address",
"with",
"a",
"new",
"private",
"key",
".",
"This",
"function",
"does",
"NOT",
"save",
"the",
"user",
"to",
"disk",
"or",
"register",
"it",
"via",
"ACME",
".",
"If",
"y... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/user.go#L46-L54 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/user.go | getUser | func getUser(storage Storage, email string) (User, error) {
var user User
// open user reg
userData, err := storage.LoadUser(email)
if err != nil {
if _, ok := err.(ErrNotExist); ok {
// create a new user
return newUser(email)
}
return user, err
}
// load user information
err = json.Unmarshal(userD... | go | func getUser(storage Storage, email string) (User, error) {
var user User
// open user reg
userData, err := storage.LoadUser(email)
if err != nil {
if _, ok := err.(ErrNotExist); ok {
// create a new user
return newUser(email)
}
return user, err
}
// load user information
err = json.Unmarshal(userD... | [
"func",
"getUser",
"(",
"storage",
"Storage",
",",
"email",
"string",
")",
"(",
"User",
",",
"error",
")",
"{",
"var",
"user",
"User",
"\n\n",
"// open user reg",
"userData",
",",
"err",
":=",
"storage",
".",
"LoadUser",
"(",
"email",
")",
"\n",
"if",
... | // getUser loads the user with the given email from disk
// using the provided storage. If the user does not exist,
// it will create a new one, but it does NOT save new
// users to the disk or register them via ACME. It does
// NOT prompt the user. | [
"getUser",
"loads",
"the",
"user",
"with",
"the",
"given",
"email",
"from",
"disk",
"using",
"the",
"provided",
"storage",
".",
"If",
"the",
"user",
"does",
"not",
"exist",
"it",
"will",
"create",
"a",
"new",
"one",
"but",
"it",
"does",
"NOT",
"save",
... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/user.go#L100-L122 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/user.go | saveUser | func saveUser(storage Storage, user User) error {
// Save the private key and registration
userData := new(UserData)
var err error
userData.Key, err = savePrivateKey(user.key)
if err == nil {
userData.Reg, err = json.MarshalIndent(&user, "", "\t")
}
if err == nil {
err = storage.StoreUser(user.Email, userDat... | go | func saveUser(storage Storage, user User) error {
// Save the private key and registration
userData := new(UserData)
var err error
userData.Key, err = savePrivateKey(user.key)
if err == nil {
userData.Reg, err = json.MarshalIndent(&user, "", "\t")
}
if err == nil {
err = storage.StoreUser(user.Email, userDat... | [
"func",
"saveUser",
"(",
"storage",
"Storage",
",",
"user",
"User",
")",
"error",
"{",
"// Save the private key and registration",
"userData",
":=",
"new",
"(",
"UserData",
")",
"\n",
"var",
"err",
"error",
"\n",
"userData",
".",
"Key",
",",
"err",
"=",
"sav... | // saveUser persists a user's key and account registration
// to the file system. It does NOT register the user via ACME
// or prompt the user. You must also pass in the storage
// wherein the user should be saved. It should be the storage
// for the CA with which user has an account. | [
"saveUser",
"persists",
"a",
"user",
"s",
"key",
"and",
"account",
"registration",
"to",
"the",
"file",
"system",
".",
"It",
"does",
"NOT",
"register",
"the",
"user",
"via",
"ACME",
"or",
"prompt",
"the",
"user",
".",
"You",
"must",
"also",
"pass",
"in",... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/user.go#L129-L141 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/user.go | promptUserAgreement | func promptUserAgreement(agreementURL string, changed bool) bool {
if changed {
fmt.Printf("The Let's Encrypt Subscriber Agreement has changed:\n %s\n", agreementURL)
fmt.Print("Do you agree to the new terms? (y/n): ")
} else {
fmt.Printf("To continue, you must agree to the Let's Encrypt Subscriber Agreement:\... | go | func promptUserAgreement(agreementURL string, changed bool) bool {
if changed {
fmt.Printf("The Let's Encrypt Subscriber Agreement has changed:\n %s\n", agreementURL)
fmt.Print("Do you agree to the new terms? (y/n): ")
} else {
fmt.Printf("To continue, you must agree to the Let's Encrypt Subscriber Agreement:\... | [
"func",
"promptUserAgreement",
"(",
"agreementURL",
"string",
",",
"changed",
"bool",
")",
"bool",
"{",
"if",
"changed",
"{",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"agreementURL",
")",
"\n",
"fmt",
".",
"Print",
"(",
"\"",
"\"",
")"... | // promptUserAgreement prompts the user to agree to the agreement
// at agreementURL via stdin. If the agreement has changed, then pass
// true as the second argument. If this is the user's first time
// agreeing, pass false. It returns whether the user agreed or not. | [
"promptUserAgreement",
"prompts",
"the",
"user",
"to",
"agree",
"to",
"the",
"agreement",
"at",
"agreementURL",
"via",
"stdin",
".",
"If",
"the",
"agreement",
"has",
"changed",
"then",
"pass",
"true",
"as",
"the",
"second",
"argument",
".",
"If",
"this",
"is... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/user.go#L147-L164 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/out/socket.go | NewSocket | func NewSocket(path string) (s *Socket, err error) {
s = &Socket{path: path}
if err = openSocket(s); err != nil {
err = fmt.Errorf("open socket: %s", err)
s.err = err
return
}
return
} | go | func NewSocket(path string) (s *Socket, err error) {
s = &Socket{path: path}
if err = openSocket(s); err != nil {
err = fmt.Errorf("open socket: %s", err)
s.err = err
return
}
return
} | [
"func",
"NewSocket",
"(",
"path",
"string",
")",
"(",
"s",
"*",
"Socket",
",",
"err",
"error",
")",
"{",
"s",
"=",
"&",
"Socket",
"{",
"path",
":",
"path",
"}",
"\n",
"if",
"err",
"=",
"openSocket",
"(",
"s",
")",
";",
"err",
"!=",
"nil",
"{",
... | // NewSocket will always return a new Socket.
// err if nothing is listening to it, it will attempt to reconnect on the next Write. | [
"NewSocket",
"will",
"always",
"return",
"a",
"new",
"Socket",
".",
"err",
"if",
"nothing",
"is",
"listening",
"to",
"it",
"it",
"will",
"attempt",
"to",
"reconnect",
"on",
"the",
"next",
"Write",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/out/socket.go#L40-L48 | train |
inverse-inc/packetfence | go/coredns/plugin/dnstap/out/socket.go | Close | func (s *Socket) Close() error {
if s.err != nil {
// nothing to close
return nil
}
defer s.conn.Close()
if err := s.enc.Flush(); err != nil {
return fmt.Errorf("flush: %s", err)
}
return s.enc.Close()
} | go | func (s *Socket) Close() error {
if s.err != nil {
// nothing to close
return nil
}
defer s.conn.Close()
if err := s.enc.Flush(); err != nil {
return fmt.Errorf("flush: %s", err)
}
return s.enc.Close()
} | [
"func",
"(",
"s",
"*",
"Socket",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"s",
".",
"err",
"!=",
"nil",
"{",
"// nothing to close",
"return",
"nil",
"\n",
"}",
"\n\n",
"defer",
"s",
".",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
":=... | // Close the socket and flush the remaining frames. | [
"Close",
"the",
"socket",
"and",
"flush",
"the",
"remaining",
"frames",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/dnstap/out/socket.go#L70-L82 | train |
inverse-inc/packetfence | go/caddy/caddy/caddyhttp/fastcgi/fcgiclient.go | DialTimeout | func DialTimeout(network string, address string, timeout time.Duration) (fcgi *FCGIClient, err error) {
conn, err := net.DialTimeout(network, address, timeout)
if err != nil {
return
}
fcgi = &FCGIClient{conn: conn, keepAlive: false, reqID: 1}
return fcgi, nil
} | go | func DialTimeout(network string, address string, timeout time.Duration) (fcgi *FCGIClient, err error) {
conn, err := net.DialTimeout(network, address, timeout)
if err != nil {
return
}
fcgi = &FCGIClient{conn: conn, keepAlive: false, reqID: 1}
return fcgi, nil
} | [
"func",
"DialTimeout",
"(",
"network",
"string",
",",
"address",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"fcgi",
"*",
"FCGIClient",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"network",
... | // DialTimeout connects to the fcgi responder at the specified network address, using default net.Dialer.
// See func net.Dial for a description of the network and address parameters. | [
"DialTimeout",
"connects",
"to",
"the",
"fcgi",
"responder",
"at",
"the",
"specified",
"network",
"address",
"using",
"default",
"net",
".",
"Dialer",
".",
"See",
"func",
"net",
".",
"Dial",
"for",
"a",
"description",
"of",
"the",
"network",
"and",
"address"... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddyhttp/fastcgi/fcgiclient.go#L188-L197 | train |
inverse-inc/packetfence | go/requesthistory/request_history.go | UuidIndex | func (rh *RequestHistory) UuidIndex(uuid string) int {
rh.lock.RLock()
defer rh.lock.RUnlock()
return rh.uuidIndexNoLock(uuid)
} | go | func (rh *RequestHistory) UuidIndex(uuid string) int {
rh.lock.RLock()
defer rh.lock.RUnlock()
return rh.uuidIndexNoLock(uuid)
} | [
"func",
"(",
"rh",
"*",
"RequestHistory",
")",
"UuidIndex",
"(",
"uuid",
"string",
")",
"int",
"{",
"rh",
".",
"lock",
".",
"RLock",
"(",
")",
"\n",
"defer",
"rh",
".",
"lock",
".",
"RUnlock",
"(",
")",
"\n\n",
"return",
"rh",
".",
"uuidIndexNoLock",... | // Returns the index at which to find the request for the UUID
// Returns -1 if the UUID is unknown | [
"Returns",
"the",
"index",
"at",
"which",
"to",
"find",
"the",
"request",
"for",
"the",
"UUID",
"Returns",
"-",
"1",
"if",
"the",
"UUID",
"is",
"unknown"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/requesthistory/request_history.go#L74-L79 | train |
inverse-inc/packetfence | go/dhcp/utils.go | connectDB | func connectDB(configDatabase pfconfigdriver.PfConfDatabase) {
db, err := db.DbFromConfig(ctx)
sharedutils.CheckError(err)
MySQLdatabase = db
} | go | func connectDB(configDatabase pfconfigdriver.PfConfDatabase) {
db, err := db.DbFromConfig(ctx)
sharedutils.CheckError(err)
MySQLdatabase = db
} | [
"func",
"connectDB",
"(",
"configDatabase",
"pfconfigdriver",
".",
"PfConfDatabase",
")",
"{",
"db",
",",
"err",
":=",
"db",
".",
"DbFromConfig",
"(",
"ctx",
")",
"\n",
"sharedutils",
".",
"CheckError",
"(",
"err",
")",
"\n",
"MySQLdatabase",
"=",
"db",
"\... | // connectDB connect to the database | [
"connectDB",
"connect",
"to",
"the",
"database"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/dhcp/utils.go#L30-L34 | train |
inverse-inc/packetfence | go/dhcp/utils.go | initiaLease | func initiaLease(dhcpHandler *DHCPHandler, ConfNet pfconfigdriver.RessourseNetworkConf) {
// Need to calculate the end ip because of the ip per role feature
now := time.Now()
endip := binary.BigEndian.Uint32(dhcpHandler.start.To4()) + uint32(dhcpHandler.leaseRange) - uint32(1)
a := make([]byte, 4)
binary.BigEndian... | go | func initiaLease(dhcpHandler *DHCPHandler, ConfNet pfconfigdriver.RessourseNetworkConf) {
// Need to calculate the end ip because of the ip per role feature
now := time.Now()
endip := binary.BigEndian.Uint32(dhcpHandler.start.To4()) + uint32(dhcpHandler.leaseRange) - uint32(1)
a := make([]byte, 4)
binary.BigEndian... | [
"func",
"initiaLease",
"(",
"dhcpHandler",
"*",
"DHCPHandler",
",",
"ConfNet",
"pfconfigdriver",
".",
"RessourseNetworkConf",
")",
"{",
"// Need to calculate the end ip because of the ip per role feature",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"endip",
":=",
... | // initiaLease fetch the database to remove already assigned ip addresses | [
"initiaLease",
"fetch",
"the",
"database",
"to",
"remove",
"already",
"assigned",
"ip",
"addresses"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/dhcp/utils.go#L37-L96 | train |
inverse-inc/packetfence | go/dhcp/utils.go | ExcludeIP | func ExcludeIP(dhcpHandler *DHCPHandler, ipRange string) []net.IP {
excludeIPs, _ := IPsFromRange(ipRange)
for _, excludeIP := range excludeIPs {
if excludeIP != nil {
// Calculate the position for the dhcp pool
position := uint32(binary.BigEndian.Uint32(excludeIP.To4())) - uint32(binary.BigEndian.Uint32(dhc... | go | func ExcludeIP(dhcpHandler *DHCPHandler, ipRange string) []net.IP {
excludeIPs, _ := IPsFromRange(ipRange)
for _, excludeIP := range excludeIPs {
if excludeIP != nil {
// Calculate the position for the dhcp pool
position := uint32(binary.BigEndian.Uint32(excludeIP.To4())) - uint32(binary.BigEndian.Uint32(dhc... | [
"func",
"ExcludeIP",
"(",
"dhcpHandler",
"*",
"DHCPHandler",
",",
"ipRange",
"string",
")",
"[",
"]",
"net",
".",
"IP",
"{",
"excludeIPs",
",",
"_",
":=",
"IPsFromRange",
"(",
"ipRange",
")",
"\n\n",
"for",
"_",
",",
"excludeIP",
":=",
"range",
"excludeI... | // ExcludeIP remove IP from the pool | [
"ExcludeIP",
"remove",
"IP",
"from",
"the",
"pool"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/dhcp/utils.go#L293-L305 | train |
inverse-inc/packetfence | go/dhcp/utils.go | AssignIP | func AssignIP(dhcpHandler *DHCPHandler, ipRange string) (map[string]uint32, []net.IP) {
couple := make(map[string]uint32)
var iplist []net.IP
if ipRange != "" {
rgx, _ := regexp.Compile("((?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}):((?:[0-9]{1,3}.){3}(?:[0-9]{1,3}))")
ipRangeArray := strings.Split(ipRange, ",")
if l... | go | func AssignIP(dhcpHandler *DHCPHandler, ipRange string) (map[string]uint32, []net.IP) {
couple := make(map[string]uint32)
var iplist []net.IP
if ipRange != "" {
rgx, _ := regexp.Compile("((?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}):((?:[0-9]{1,3}.){3}(?:[0-9]{1,3}))")
ipRangeArray := strings.Split(ipRange, ",")
if l... | [
"func",
"AssignIP",
"(",
"dhcpHandler",
"*",
"DHCPHandler",
",",
"ipRange",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"uint32",
",",
"[",
"]",
"net",
".",
"IP",
")",
"{",
"couple",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"uint32",
")",
"... | // Assign static IP address to a mac address and remove it from the pool | [
"Assign",
"static",
"IP",
"address",
"to",
"a",
"mac",
"address",
"and",
"remove",
"it",
"from",
"the",
"pool"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/dhcp/utils.go#L308-L326 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/handshake.go | GetCertificate | func (cg configGroup) GetCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
cert, err := cg.getCertDuringHandshake(strings.ToLower(clientHello.ServerName), true, true)
return &cert.Certificate, err
} | go | func (cg configGroup) GetCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
cert, err := cg.getCertDuringHandshake(strings.ToLower(clientHello.ServerName), true, true)
return &cert.Certificate, err
} | [
"func",
"(",
"cg",
"configGroup",
")",
"GetCertificate",
"(",
"clientHello",
"*",
"tls",
".",
"ClientHelloInfo",
")",
"(",
"*",
"tls",
".",
"Certificate",
",",
"error",
")",
"{",
"cert",
",",
"err",
":=",
"cg",
".",
"getCertDuringHandshake",
"(",
"strings"... | // GetCertificate gets a certificate to satisfy clientHello. In getting
// the certificate, it abides the rules and settings defined in the
// Config that matches clientHello.ServerName. It first checks the in-
// memory cache, then, if the config enables "OnDemand", it accesses
// disk, then accesses the network if it... | [
"GetCertificate",
"gets",
"a",
"certificate",
"to",
"satisfy",
"clientHello",
".",
"In",
"getting",
"the",
"certificate",
"it",
"abides",
"the",
"rules",
"and",
"settings",
"defined",
"in",
"the",
"Config",
"that",
"matches",
"clientHello",
".",
"ServerName",
".... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/handshake.go#L61-L64 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/handshake.go | checkLimitsForObtainingNewCerts | func (cg configGroup) checkLimitsForObtainingNewCerts(name string, cfg *Config) error {
// User can set hard limit for number of certs for the process to issue
if cfg.OnDemandState.MaxObtain > 0 &&
atomic.LoadInt32(&cfg.OnDemandState.ObtainedCount) >= cfg.OnDemandState.MaxObtain {
return fmt.Errorf("%s: maximum c... | go | func (cg configGroup) checkLimitsForObtainingNewCerts(name string, cfg *Config) error {
// User can set hard limit for number of certs for the process to issue
if cfg.OnDemandState.MaxObtain > 0 &&
atomic.LoadInt32(&cfg.OnDemandState.ObtainedCount) >= cfg.OnDemandState.MaxObtain {
return fmt.Errorf("%s: maximum c... | [
"func",
"(",
"cg",
"configGroup",
")",
"checkLimitsForObtainingNewCerts",
"(",
"name",
"string",
",",
"cfg",
"*",
"Config",
")",
"error",
"{",
"// User can set hard limit for number of certs for the process to issue",
"if",
"cfg",
".",
"OnDemandState",
".",
"MaxObtain",
... | // checkLimitsForObtainingNewCerts checks to see if name can be issued right
// now according to mitigating factors we keep track of and preferences the
// user has set. If a non-nil error is returned, do not issue a new certificate
// for name. | [
"checkLimitsForObtainingNewCerts",
"checks",
"to",
"see",
"if",
"name",
"can",
"be",
"issued",
"right",
"now",
"according",
"to",
"mitigating",
"factors",
"we",
"keep",
"track",
"of",
"and",
"preferences",
"the",
"user",
"has",
"set",
".",
"If",
"a",
"non",
... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/handshake.go#L130-L156 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/handshake.go | obtainOnDemandCertificate | func (cg configGroup) obtainOnDemandCertificate(name string, cfg *Config) (Certificate, error) {
// We must protect this process from happening concurrently, so synchronize.
obtainCertWaitChansMu.Lock()
wait, ok := obtainCertWaitChans[name]
if ok {
// lucky us -- another goroutine is already obtaining the certifi... | go | func (cg configGroup) obtainOnDemandCertificate(name string, cfg *Config) (Certificate, error) {
// We must protect this process from happening concurrently, so synchronize.
obtainCertWaitChansMu.Lock()
wait, ok := obtainCertWaitChans[name]
if ok {
// lucky us -- another goroutine is already obtaining the certifi... | [
"func",
"(",
"cg",
"configGroup",
")",
"obtainOnDemandCertificate",
"(",
"name",
"string",
",",
"cfg",
"*",
"Config",
")",
"(",
"Certificate",
",",
"error",
")",
"{",
"// We must protect this process from happening concurrently, so synchronize.",
"obtainCertWaitChansMu",
... | // obtainOnDemandCertificate obtains a certificate for name for the given
// name. If another goroutine has already started obtaining a cert for
// name, it will wait and use what the other goroutine obtained.
//
// This function is safe for use by multiple concurrent goroutines. | [
"obtainOnDemandCertificate",
"obtains",
"a",
"certificate",
"for",
"name",
"for",
"the",
"given",
"name",
".",
"If",
"another",
"goroutine",
"has",
"already",
"started",
"obtaining",
"a",
"cert",
"for",
"name",
"it",
"will",
"wait",
"and",
"use",
"what",
"the"... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/handshake.go#L163-L216 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/handshake.go | handshakeMaintenance | func (cg configGroup) handshakeMaintenance(name string, cert Certificate) (Certificate, error) {
// Check cert expiration
timeLeft := cert.NotAfter.Sub(time.Now().UTC())
if timeLeft < RenewDurationBefore {
log.Printf("[INFO] Certificate for %v expires in %v; attempting renewal", cert.Names, timeLeft)
return cg.r... | go | func (cg configGroup) handshakeMaintenance(name string, cert Certificate) (Certificate, error) {
// Check cert expiration
timeLeft := cert.NotAfter.Sub(time.Now().UTC())
if timeLeft < RenewDurationBefore {
log.Printf("[INFO] Certificate for %v expires in %v; attempting renewal", cert.Names, timeLeft)
return cg.r... | [
"func",
"(",
"cg",
"configGroup",
")",
"handshakeMaintenance",
"(",
"name",
"string",
",",
"cert",
"Certificate",
")",
"(",
"Certificate",
",",
"error",
")",
"{",
"// Check cert expiration",
"timeLeft",
":=",
"cert",
".",
"NotAfter",
".",
"Sub",
"(",
"time",
... | // handshakeMaintenance performs a check on cert for expiration and OCSP
// validity.
//
// This function is safe for use by multiple concurrent goroutines. | [
"handshakeMaintenance",
"performs",
"a",
"check",
"on",
"cert",
"for",
"expiration",
"and",
"OCSP",
"validity",
".",
"This",
"function",
"is",
"safe",
"for",
"use",
"by",
"multiple",
"concurrent",
"goroutines",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/handshake.go#L222-L247 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/handshake.go | renewDynamicCertificate | func (cg configGroup) renewDynamicCertificate(name string, cfg *Config) (Certificate, error) {
obtainCertWaitChansMu.Lock()
wait, ok := obtainCertWaitChans[name]
if ok {
// lucky us -- another goroutine is already renewing the certificate.
// wait for it to finish, then we'll use the new one.
obtainCertWaitCha... | go | func (cg configGroup) renewDynamicCertificate(name string, cfg *Config) (Certificate, error) {
obtainCertWaitChansMu.Lock()
wait, ok := obtainCertWaitChans[name]
if ok {
// lucky us -- another goroutine is already renewing the certificate.
// wait for it to finish, then we'll use the new one.
obtainCertWaitCha... | [
"func",
"(",
"cg",
"configGroup",
")",
"renewDynamicCertificate",
"(",
"name",
"string",
",",
"cfg",
"*",
"Config",
")",
"(",
"Certificate",
",",
"error",
")",
"{",
"obtainCertWaitChansMu",
".",
"Lock",
"(",
")",
"\n",
"wait",
",",
"ok",
":=",
"obtainCertW... | // renewDynamicCertificate renews the certificate for name using cfg. It returns the
// certificate to use and an error, if any. currentCert may be returned even if an
// error occurs, since we perform renewals before they expire and it may still be
// usable. name should already be lower-cased before calling this func... | [
"renewDynamicCertificate",
"renews",
"the",
"certificate",
"for",
"name",
"using",
"cfg",
".",
"It",
"returns",
"the",
"certificate",
"to",
"use",
"and",
"an",
"error",
"if",
"any",
".",
"currentCert",
"may",
"be",
"returned",
"even",
"if",
"an",
"error",
"o... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/handshake.go#L255-L288 | train |
inverse-inc/packetfence | go/dhcp/rawClient.go | NewRawClient | func NewRawClient(ifi *net.Interface) (*RawClient, error) {
// Open raw socket to send Wake-on-LAN magic packets
var cfg raw.Config
p, err := raw.ListenPacket(ifi, 0x0806, &cfg)
if err != nil {
return nil, err
}
return &RawClient{
ifi: ifi,
p: p,
}, nil
} | go | func NewRawClient(ifi *net.Interface) (*RawClient, error) {
// Open raw socket to send Wake-on-LAN magic packets
var cfg raw.Config
p, err := raw.ListenPacket(ifi, 0x0806, &cfg)
if err != nil {
return nil, err
}
return &RawClient{
ifi: ifi,
p: p,
}, nil
} | [
"func",
"NewRawClient",
"(",
"ifi",
"*",
"net",
".",
"Interface",
")",
"(",
"*",
"RawClient",
",",
"error",
")",
"{",
"// Open raw socket to send Wake-on-LAN magic packets",
"var",
"cfg",
"raw",
".",
"Config",
"\n\n",
"p",
",",
"err",
":=",
"raw",
".",
"List... | // NewRawClient creates a new RawClient using the specified network interface.
//
// Note that raw sockets typically require elevated user privileges, such as
// the 'root' user on Linux, or the 'SET_CAP_RAW' capability.
//
// For this reason, it is typically recommended to use the regular Client type
// instead, which... | [
"NewRawClient",
"creates",
"a",
"new",
"RawClient",
"using",
"the",
"specified",
"network",
"interface",
".",
"Note",
"that",
"raw",
"sockets",
"typically",
"require",
"elevated",
"user",
"privileges",
"such",
"as",
"the",
"root",
"user",
"on",
"Linux",
"or",
... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/dhcp/rawClient.go#L62-L75 | train |
inverse-inc/packetfence | go/dhcp/rawClient.go | sendDHCP | func (c *RawClient) sendDHCP(target net.HardwareAddr, dhcp []byte, dstIP net.IP, srcIP net.IP) error {
proto := 17
udpsrc := uint(67)
udpdst := uint(68)
udp := udphdr{
src: uint16(udpsrc),
dst: uint16(udpdst),
}
udplen := 8 + len(dhcp)
ip := iphdr{
vhl: 0x45,
tos: 0,
id: 0x0000, // the kern... | go | func (c *RawClient) sendDHCP(target net.HardwareAddr, dhcp []byte, dstIP net.IP, srcIP net.IP) error {
proto := 17
udpsrc := uint(67)
udpdst := uint(68)
udp := udphdr{
src: uint16(udpsrc),
dst: uint16(udpdst),
}
udplen := 8 + len(dhcp)
ip := iphdr{
vhl: 0x45,
tos: 0,
id: 0x0000, // the kern... | [
"func",
"(",
"c",
"*",
"RawClient",
")",
"sendDHCP",
"(",
"target",
"net",
".",
"HardwareAddr",
",",
"dhcp",
"[",
"]",
"byte",
",",
"dstIP",
"net",
".",
"IP",
",",
"srcIP",
"net",
".",
"IP",
")",
"error",
"{",
"proto",
":=",
"17",
"\n\n",
"udpsrc",... | // sendDHCP create a udp packet and stores it in an
// Ethernet frame, and sends the frame over a raw socket to attempt to wake
// a machine. | [
"sendDHCP",
"create",
"a",
"udp",
"packet",
"and",
"stores",
"it",
"in",
"an",
"Ethernet",
"frame",
"and",
"sends",
"the",
"frame",
"over",
"a",
"raw",
"socket",
"to",
"attempt",
"to",
"wake",
"a",
"machine",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/dhcp/rawClient.go#L85-L153 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | setupEdns0Opt | func setupEdns0Opt(r *dns.Msg) *dns.OPT {
o := r.IsEdns0()
if o == nil {
r.SetEdns0(4096, true)
o = r.IsEdns0()
}
return o
} | go | func setupEdns0Opt(r *dns.Msg) *dns.OPT {
o := r.IsEdns0()
if o == nil {
r.SetEdns0(4096, true)
o = r.IsEdns0()
}
return o
} | [
"func",
"setupEdns0Opt",
"(",
"r",
"*",
"dns",
".",
"Msg",
")",
"*",
"dns",
".",
"OPT",
"{",
"o",
":=",
"r",
".",
"IsEdns0",
"(",
")",
"\n",
"if",
"o",
"==",
"nil",
"{",
"r",
".",
"SetEdns0",
"(",
"4096",
",",
"true",
")",
"\n",
"o",
"=",
"... | // setupEdns0Opt will retrieve the EDNS0 OPT or create it if it does not exist | [
"setupEdns0Opt",
"will",
"retrieve",
"the",
"EDNS0",
"OPT",
"or",
"create",
"it",
"if",
"it",
"does",
"not",
"exist"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L39-L46 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | Rewrite | func (rule *edns0LocalRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
result := RewriteIgnored
o := setupEdns0Opt(r)
found := false
for _, s := range o.Option {
switch e := s.(type) {
case *dns.EDNS0_LOCAL:
if rule.code == e.Code {
if rule.action == Replace || rule.action == Set {
e.Data = ... | go | func (rule *edns0LocalRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
result := RewriteIgnored
o := setupEdns0Opt(r)
found := false
for _, s := range o.Option {
switch e := s.(type) {
case *dns.EDNS0_LOCAL:
if rule.code == e.Code {
if rule.action == Replace || rule.action == Set {
e.Data = ... | [
"func",
"(",
"rule",
"*",
"edns0LocalRule",
")",
"Rewrite",
"(",
"w",
"dns",
".",
"ResponseWriter",
",",
"r",
"*",
"dns",
".",
"Msg",
")",
"Result",
"{",
"result",
":=",
"RewriteIgnored",
"\n",
"o",
":=",
"setupEdns0Opt",
"(",
"r",
")",
"\n",
"found",
... | // Rewrite will alter the request EDNS0 local options | [
"Rewrite",
"will",
"alter",
"the",
"request",
"EDNS0",
"local",
"options"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L82-L111 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | newEdns0Rule | func newEdns0Rule(mode string, args ...string) (Rule, error) {
if len(args) < 2 {
return nil, fmt.Errorf("too few arguments for an EDNS0 rule")
}
ruleType := strings.ToLower(args[0])
action := strings.ToLower(args[1])
switch action {
case Append:
case Replace:
case Set:
default:
return nil, fmt.Errorf("in... | go | func newEdns0Rule(mode string, args ...string) (Rule, error) {
if len(args) < 2 {
return nil, fmt.Errorf("too few arguments for an EDNS0 rule")
}
ruleType := strings.ToLower(args[0])
action := strings.ToLower(args[1])
switch action {
case Append:
case Replace:
case Set:
default:
return nil, fmt.Errorf("in... | [
"func",
"newEdns0Rule",
"(",
"mode",
"string",
",",
"args",
"...",
"string",
")",
"(",
"Rule",
",",
"error",
")",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\... | // newEdns0Rule creates an EDNS0 rule of the appropriate type based on the args | [
"newEdns0Rule",
"creates",
"an",
"EDNS0",
"rule",
"of",
"the",
"appropriate",
"type",
"based",
"on",
"the",
"args"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L119-L157 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | newEdns0VariableRule | func newEdns0VariableRule(mode, action, code, variable string) (*edns0VariableRule, error) {
c, err := strconv.ParseUint(code, 0, 16)
if err != nil {
return nil, err
}
//Validate
if !isValidVariable(variable) {
return nil, fmt.Errorf("unsupported variable name %q", variable)
}
return &edns0VariableRule{mode:... | go | func newEdns0VariableRule(mode, action, code, variable string) (*edns0VariableRule, error) {
c, err := strconv.ParseUint(code, 0, 16)
if err != nil {
return nil, err
}
//Validate
if !isValidVariable(variable) {
return nil, fmt.Errorf("unsupported variable name %q", variable)
}
return &edns0VariableRule{mode:... | [
"func",
"newEdns0VariableRule",
"(",
"mode",
",",
"action",
",",
"code",
",",
"variable",
"string",
")",
"(",
"*",
"edns0VariableRule",
",",
"error",
")",
"{",
"c",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"code",
",",
"0",
",",
"16",
")",
... | // newEdns0VariableRule creates an EDNS0 rule that handles variable substitution | [
"newEdns0VariableRule",
"creates",
"an",
"EDNS0",
"rule",
"that",
"handles",
"variable",
"substitution"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L176-L186 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | ruleData | func (rule *edns0VariableRule) ruleData(w dns.ResponseWriter, r *dns.Msg) ([]byte, error) {
req := request.Request{W: w, Req: r}
switch rule.variable {
case queryName:
//Query name is written as ascii string
return []byte(req.QName()), nil
case queryType:
return rule.uint16ToWire(req.QType()), nil
case cl... | go | func (rule *edns0VariableRule) ruleData(w dns.ResponseWriter, r *dns.Msg) ([]byte, error) {
req := request.Request{W: w, Req: r}
switch rule.variable {
case queryName:
//Query name is written as ascii string
return []byte(req.QName()), nil
case queryType:
return rule.uint16ToWire(req.QType()), nil
case cl... | [
"func",
"(",
"rule",
"*",
"edns0VariableRule",
")",
"ruleData",
"(",
"w",
"dns",
".",
"ResponseWriter",
",",
"r",
"*",
"dns",
".",
"Msg",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"req",
":=",
"request",
".",
"Request",
"{",
"W",
":",
"... | // ruleData returns the data specified by the variable | [
"ruleData",
"returns",
"the",
"data",
"specified",
"by",
"the",
"variable"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L233-L270 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | fillEcsData | func (rule *edns0SubnetRule) fillEcsData(w dns.ResponseWriter, r *dns.Msg,
ecs *dns.EDNS0_SUBNET) error {
req := request.Request{W: w, Req: r}
family := req.Family()
if (family != 1) && (family != 2) {
return fmt.Errorf("unable to fill data for EDNS0 subnet due to invalid IP family")
}
ecs.Family = uint16(fam... | go | func (rule *edns0SubnetRule) fillEcsData(w dns.ResponseWriter, r *dns.Msg,
ecs *dns.EDNS0_SUBNET) error {
req := request.Request{W: w, Req: r}
family := req.Family()
if (family != 1) && (family != 2) {
return fmt.Errorf("unable to fill data for EDNS0 subnet due to invalid IP family")
}
ecs.Family = uint16(fam... | [
"func",
"(",
"rule",
"*",
"edns0SubnetRule",
")",
"fillEcsData",
"(",
"w",
"dns",
".",
"ResponseWriter",
",",
"r",
"*",
"dns",
".",
"Msg",
",",
"ecs",
"*",
"dns",
".",
"EDNS0_SUBNET",
")",
"error",
"{",
"req",
":=",
"request",
".",
"Request",
"{",
"W... | // fillEcsData sets the subnet data into the ecs option | [
"fillEcsData",
"sets",
"the",
"subnet",
"data",
"into",
"the",
"ecs",
"option"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L362-L388 | train |
inverse-inc/packetfence | go/coredns/plugin/rewrite/edns0.go | Rewrite | func (rule *edns0SubnetRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
result := RewriteIgnored
o := setupEdns0Opt(r)
found := false
for _, s := range o.Option {
switch e := s.(type) {
case *dns.EDNS0_SUBNET:
if rule.action == Replace || rule.action == Set {
if rule.fillEcsData(w, r, e) == nil {... | go | func (rule *edns0SubnetRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
result := RewriteIgnored
o := setupEdns0Opt(r)
found := false
for _, s := range o.Option {
switch e := s.(type) {
case *dns.EDNS0_SUBNET:
if rule.action == Replace || rule.action == Set {
if rule.fillEcsData(w, r, e) == nil {... | [
"func",
"(",
"rule",
"*",
"edns0SubnetRule",
")",
"Rewrite",
"(",
"w",
"dns",
".",
"ResponseWriter",
",",
"r",
"*",
"dns",
".",
"Msg",
")",
"Result",
"{",
"result",
":=",
"RewriteIgnored",
"\n",
"o",
":=",
"setupEdns0Opt",
"(",
"r",
")",
"\n",
"found",... | // Rewrite will alter the request EDNS0 subnet option | [
"Rewrite",
"will",
"alter",
"the",
"request",
"EDNS0",
"subnet",
"option"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/rewrite/edns0.go#L391-L419 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | setup | func setup(c *caddy.Controller) error {
ctx := log.LoggerNewContext(context.Background())
pfsso, err := buildPfssoHandler(ctx)
if err != nil {
return err
}
// Declare all pfconfig resources that will be necessary
pfconfigdriver.PfconfigPool.AddRefreshable(ctx, &firewallsso.Firewalls)
pfconfigdriver.Pfconfig... | go | func setup(c *caddy.Controller) error {
ctx := log.LoggerNewContext(context.Background())
pfsso, err := buildPfssoHandler(ctx)
if err != nil {
return err
}
// Declare all pfconfig resources that will be necessary
pfconfigdriver.PfconfigPool.AddRefreshable(ctx, &firewallsso.Firewalls)
pfconfigdriver.Pfconfig... | [
"func",
"setup",
"(",
"c",
"*",
"caddy",
".",
"Controller",
")",
"error",
"{",
"ctx",
":=",
"log",
".",
"LoggerNewContext",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n\n",
"pfsso",
",",
"err",
":=",
"buildPfssoHandler",
"(",
"ctx",
")",
"\n\n... | // Setup the pfsso middleware
// Also loads the pfconfig resources and registers them in the pool | [
"Setup",
"the",
"pfsso",
"middleware",
"Also",
"loads",
"the",
"pfconfig",
"resources",
"and",
"registers",
"them",
"in",
"the",
"pool"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L41-L60 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | buildPfssoHandler | func buildPfssoHandler(ctx context.Context) (PfssoHandler, error) {
pfsso := PfssoHandler{}
pfsso.updateCache = cache.New(1*time.Hour, 30*time.Second)
router := httprouter.New()
router.POST("/api/v1/firewall_sso/update", pfsso.handleUpdate)
router.POST("/api/v1/firewall_sso/start", pfsso.handleStart)
router.PO... | go | func buildPfssoHandler(ctx context.Context) (PfssoHandler, error) {
pfsso := PfssoHandler{}
pfsso.updateCache = cache.New(1*time.Hour, 30*time.Second)
router := httprouter.New()
router.POST("/api/v1/firewall_sso/update", pfsso.handleUpdate)
router.POST("/api/v1/firewall_sso/start", pfsso.handleStart)
router.PO... | [
"func",
"buildPfssoHandler",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"PfssoHandler",
",",
"error",
")",
"{",
"pfsso",
":=",
"PfssoHandler",
"{",
"}",
"\n\n",
"pfsso",
".",
"updateCache",
"=",
"cache",
".",
"New",
"(",
"1",
"*",
"time",
".",
"H... | // Build the PfssoHandler which will initialize the cache and instantiate the router along with its routes | [
"Build",
"the",
"PfssoHandler",
"which",
"will",
"initialize",
"the",
"cache",
"and",
"instantiate",
"the",
"router",
"along",
"with",
"its",
"routes"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L63-L77 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | validateInfo | func (h PfssoHandler) validateInfo(ctx context.Context, info map[string]string) error {
required := []string{"ip", "mac", "username", "role"}
for _, k := range required {
if _, ok := info[k]; !ok {
return errors.New(fmt.Sprintf("Missing %s in request", k))
}
}
return nil
} | go | func (h PfssoHandler) validateInfo(ctx context.Context, info map[string]string) error {
required := []string{"ip", "mac", "username", "role"}
for _, k := range required {
if _, ok := info[k]; !ok {
return errors.New(fmt.Sprintf("Missing %s in request", k))
}
}
return nil
} | [
"func",
"(",
"h",
"PfssoHandler",
")",
"validateInfo",
"(",
"ctx",
"context",
".",
"Context",
",",
"info",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"required",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\... | // Validate that all the required fields are there in the request | [
"Validate",
"that",
"all",
"the",
"required",
"fields",
"are",
"there",
"in",
"the",
"request"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L110-L118 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | spawnSso | func (h PfssoHandler) spawnSso(ctx context.Context, firewall firewallsso.FirewallSSOInt, info map[string]string, f func(info map[string]string) (bool, error)) {
// Perform a copy of the information hash before spawning the goroutine
infoCopy := map[string]string{}
for k, v := range info {
infoCopy[k] = v
}
go f... | go | func (h PfssoHandler) spawnSso(ctx context.Context, firewall firewallsso.FirewallSSOInt, info map[string]string, f func(info map[string]string) (bool, error)) {
// Perform a copy of the information hash before spawning the goroutine
infoCopy := map[string]string{}
for k, v := range info {
infoCopy[k] = v
}
go f... | [
"func",
"(",
"h",
"PfssoHandler",
")",
"spawnSso",
"(",
"ctx",
"context",
".",
"Context",
",",
"firewall",
"firewallsso",
".",
"FirewallSSOInt",
",",
"info",
"map",
"[",
"string",
"]",
"string",
",",
"f",
"func",
"(",
"info",
"map",
"[",
"string",
"]",
... | // Spawn an async SSO request for a specific firewall | [
"Spawn",
"an",
"async",
"SSO",
"request",
"for",
"a",
"specific",
"firewall"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L121-L141 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | addInfoToContext | func (h PfssoHandler) addInfoToContext(ctx context.Context, info map[string]string) context.Context {
return log.AddToLogContext(ctx, "username", info["username"], "ip", info["ip"], "mac", info["mac"], "role", info["role"])
} | go | func (h PfssoHandler) addInfoToContext(ctx context.Context, info map[string]string) context.Context {
return log.AddToLogContext(ctx, "username", info["username"], "ip", info["ip"], "mac", info["mac"], "role", info["role"])
} | [
"func",
"(",
"h",
"PfssoHandler",
")",
"addInfoToContext",
"(",
"ctx",
"context",
".",
"Context",
",",
"info",
"map",
"[",
"string",
"]",
"string",
")",
"context",
".",
"Context",
"{",
"return",
"log",
".",
"AddToLogContext",
"(",
"ctx",
",",
"\"",
"\"",... | // Add the info in the request to the log context | [
"Add",
"the",
"info",
"in",
"the",
"request",
"to",
"the",
"log",
"context"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L144-L146 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | handleUpdate | func (h PfssoHandler) handleUpdate(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("PfssoHandler.handleUpdate")
info, timeout, err := h.parseSsoRequest(ctx, r.Body)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
ret... | go | func (h PfssoHandler) handleUpdate(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("PfssoHandler.handleUpdate")
info, timeout, err := h.parseSsoRequest(ctx, r.Body)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
ret... | [
"func",
"(",
"h",
"PfssoHandler",
")",
"handleUpdate",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"p",
"httprouter",
".",
"Params",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"defer",
"statsd... | // Handle an update action for pfsso
// If the firewall has cached updates enabled, it will handle it here
// The cache is in-memory so that means that a restart of the process will clear the cached updates cache | [
"Handle",
"an",
"update",
"action",
"for",
"pfsso",
"If",
"the",
"firewall",
"has",
"cached",
"updates",
"enabled",
"it",
"will",
"handle",
"it",
"here",
"The",
"cache",
"is",
"in",
"-",
"memory",
"so",
"that",
"means",
"that",
"a",
"restart",
"of",
"the... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L151-L207 | train |
inverse-inc/packetfence | go/caddy/pfsso/pfsso.go | handleStop | func (h PfssoHandler) handleStop(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("PfssoHandler.handleStop")
info, _, err := h.parseSsoRequest(ctx, r.Body)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
return
}
c... | go | func (h PfssoHandler) handleStop(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ctx := r.Context()
defer statsd.NewStatsDTiming(ctx).Send("PfssoHandler.handleStop")
info, _, err := h.parseSsoRequest(ctx, r.Body)
if err != nil {
http.Error(w, fmt.Sprint(err), http.StatusBadRequest)
return
}
c... | [
"func",
"(",
"h",
"PfssoHandler",
")",
"handleStop",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
",",
"p",
"httprouter",
".",
"Params",
")",
"{",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"defer",
"statsd",... | // Handle an SSO stop | [
"Handle",
"an",
"SSO",
"stop"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfsso/pfsso.go#L234-L255 | train |
inverse-inc/packetfence | go/coredns/plugin/hosts/hosts.go | a | func a(zone string, ips []net.IP) []dns.RR {
answers := []dns.RR{}
for _, ip := range ips {
r := new(dns.A)
r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypeA,
Class: dns.ClassINET, Ttl: 3600}
r.A = ip
answers = append(answers, r)
}
return answers
} | go | func a(zone string, ips []net.IP) []dns.RR {
answers := []dns.RR{}
for _, ip := range ips {
r := new(dns.A)
r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypeA,
Class: dns.ClassINET, Ttl: 3600}
r.A = ip
answers = append(answers, r)
}
return answers
} | [
"func",
"a",
"(",
"zone",
"string",
",",
"ips",
"[",
"]",
"net",
".",
"IP",
")",
"[",
"]",
"dns",
".",
"RR",
"{",
"answers",
":=",
"[",
"]",
"dns",
".",
"RR",
"{",
"}",
"\n",
"for",
"_",
",",
"ip",
":=",
"range",
"ips",
"{",
"r",
":=",
"n... | // a takes a slice of net.IPs and returns a slice of A RRs. | [
"a",
"takes",
"a",
"slice",
"of",
"net",
".",
"IPs",
"and",
"returns",
"a",
"slice",
"of",
"A",
"RRs",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/hosts/hosts.go#L100-L110 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | NewFileStorage | func NewFileStorage(caURL *url.URL) (Storage, error) {
return &FileStorage{
Path: filepath.Join(storageBasePath, caURL.Host),
nameLocks: make(map[string]*sync.WaitGroup),
}, nil
} | go | func NewFileStorage(caURL *url.URL) (Storage, error) {
return &FileStorage{
Path: filepath.Join(storageBasePath, caURL.Host),
nameLocks: make(map[string]*sync.WaitGroup),
}, nil
} | [
"func",
"NewFileStorage",
"(",
"caURL",
"*",
"url",
".",
"URL",
")",
"(",
"Storage",
",",
"error",
")",
"{",
"return",
"&",
"FileStorage",
"{",
"Path",
":",
"filepath",
".",
"Join",
"(",
"storageBasePath",
",",
"caURL",
".",
"Host",
")",
",",
"nameLock... | // NewFileStorage is a StorageConstructor function that creates a new
// Storage instance backed by the local disk. The resulting Storage
// instance is guaranteed to be non-nil if there is no error. | [
"NewFileStorage",
"is",
"a",
"StorageConstructor",
"function",
"that",
"creates",
"a",
"new",
"Storage",
"instance",
"backed",
"by",
"the",
"local",
"disk",
".",
"The",
"resulting",
"Storage",
"instance",
"is",
"guaranteed",
"to",
"be",
"non",
"-",
"nil",
"if"... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L26-L31 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | site | func (s *FileStorage) site(domain string) string {
domain = strings.ToLower(domain)
return filepath.Join(s.sites(), domain)
} | go | func (s *FileStorage) site(domain string) string {
domain = strings.ToLower(domain)
return filepath.Join(s.sites(), domain)
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"site",
"(",
"domain",
"string",
")",
"string",
"{",
"domain",
"=",
"strings",
".",
"ToLower",
"(",
"domain",
")",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"s",
".",
"sites",
"(",
")",
",",
"domain",
... | // site returns the path to the folder containing assets for domain. | [
"site",
"returns",
"the",
"path",
"to",
"the",
"folder",
"containing",
"assets",
"for",
"domain",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L48-L51 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | user | func (s *FileStorage) user(email string) string {
if email == "" {
email = emptyEmail
}
email = strings.ToLower(email)
return filepath.Join(s.users(), email)
} | go | func (s *FileStorage) user(email string) string {
if email == "" {
email = emptyEmail
}
email = strings.ToLower(email)
return filepath.Join(s.users(), email)
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"user",
"(",
"email",
"string",
")",
"string",
"{",
"if",
"email",
"==",
"\"",
"\"",
"{",
"email",
"=",
"emptyEmail",
"\n",
"}",
"\n",
"email",
"=",
"strings",
".",
"ToLower",
"(",
"email",
")",
"\n",
"ret... | // user gets the account folder for the user with email | [
"user",
"gets",
"the",
"account",
"folder",
"for",
"the",
"user",
"with",
"email"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L77-L83 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | emailUsername | func emailUsername(email string) string {
at := strings.Index(email, "@")
if at == -1 {
return email
} else if at == 0 {
return email[1:]
}
return email[:at]
} | go | func emailUsername(email string) string {
at := strings.Index(email, "@")
if at == -1 {
return email
} else if at == 0 {
return email[1:]
}
return email[:at]
} | [
"func",
"emailUsername",
"(",
"email",
"string",
")",
"string",
"{",
"at",
":=",
"strings",
".",
"Index",
"(",
"email",
",",
"\"",
"\"",
")",
"\n",
"if",
"at",
"==",
"-",
"1",
"{",
"return",
"email",
"\n",
"}",
"else",
"if",
"at",
"==",
"0",
"{",... | // emailUsername returns the username portion of an email address (part before
// '@') or the original input if it can't find the "@" symbol. | [
"emailUsername",
"returns",
"the",
"username",
"portion",
"of",
"an",
"email",
"address",
"(",
"part",
"before"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L87-L95 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | userRegFile | func (s *FileStorage) userRegFile(email string) string {
if email == "" {
email = emptyEmail
}
email = strings.ToLower(email)
fileName := emailUsername(email)
if fileName == "" {
fileName = "registration"
}
return filepath.Join(s.user(email), fileName+".json")
} | go | func (s *FileStorage) userRegFile(email string) string {
if email == "" {
email = emptyEmail
}
email = strings.ToLower(email)
fileName := emailUsername(email)
if fileName == "" {
fileName = "registration"
}
return filepath.Join(s.user(email), fileName+".json")
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"userRegFile",
"(",
"email",
"string",
")",
"string",
"{",
"if",
"email",
"==",
"\"",
"\"",
"{",
"email",
"=",
"emptyEmail",
"\n",
"}",
"\n",
"email",
"=",
"strings",
".",
"ToLower",
"(",
"email",
")",
"\n",... | // userRegFile gets the path to the registration file for the user with the
// given email address. | [
"userRegFile",
"gets",
"the",
"path",
"to",
"the",
"registration",
"file",
"for",
"the",
"user",
"with",
"the",
"given",
"email",
"address",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L99-L109 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | readFile | func (s *FileStorage) readFile(file string) ([]byte, error) {
b, err := ioutil.ReadFile(file)
if os.IsNotExist(err) {
return nil, ErrNotExist(err)
}
return b, err
} | go | func (s *FileStorage) readFile(file string) ([]byte, error) {
b, err := ioutil.ReadFile(file)
if os.IsNotExist(err) {
return nil, ErrNotExist(err)
}
return b, err
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"readFile",
"(",
"file",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"file",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",... | // readFile abstracts a simple ioutil.ReadFile, making sure to return an
// ErrNotExist instance when the file is not found. | [
"readFile",
"abstracts",
"a",
"simple",
"ioutil",
".",
"ReadFile",
"making",
"sure",
"to",
"return",
"an",
"ErrNotExist",
"instance",
"when",
"the",
"file",
"is",
"not",
"found",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L127-L133 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | SiteExists | func (s *FileStorage) SiteExists(domain string) (bool, error) {
_, err := os.Stat(s.siteCertFile(domain))
if os.IsNotExist(err) {
return false, nil
} else if err != nil {
return false, err
}
_, err = os.Stat(s.siteKeyFile(domain))
if err != nil {
return false, err
}
return true, nil
} | go | func (s *FileStorage) SiteExists(domain string) (bool, error) {
_, err := os.Stat(s.siteCertFile(domain))
if os.IsNotExist(err) {
return false, nil
} else if err != nil {
return false, err
}
_, err = os.Stat(s.siteKeyFile(domain))
if err != nil {
return false, err
}
return true, nil
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"SiteExists",
"(",
"domain",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"s",
".",
"siteCertFile",
"(",
"domain",
")",
")",
"\n",
"if",
"os",
".",
... | // SiteExists implements Storage.SiteExists by checking for the presence of
// cert and key files. | [
"SiteExists",
"implements",
"Storage",
".",
"SiteExists",
"by",
"checking",
"for",
"the",
"presence",
"of",
"cert",
"and",
"key",
"files",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L137-L150 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | LoadSite | func (s *FileStorage) LoadSite(domain string) (*SiteData, error) {
var err error
siteData := new(SiteData)
siteData.Cert, err = s.readFile(s.siteCertFile(domain))
if err != nil {
return nil, err
}
siteData.Key, err = s.readFile(s.siteKeyFile(domain))
if err != nil {
return nil, err
}
siteData.Meta, err = s... | go | func (s *FileStorage) LoadSite(domain string) (*SiteData, error) {
var err error
siteData := new(SiteData)
siteData.Cert, err = s.readFile(s.siteCertFile(domain))
if err != nil {
return nil, err
}
siteData.Key, err = s.readFile(s.siteKeyFile(domain))
if err != nil {
return nil, err
}
siteData.Meta, err = s... | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"LoadSite",
"(",
"domain",
"string",
")",
"(",
"*",
"SiteData",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"siteData",
":=",
"new",
"(",
"SiteData",
")",
"\n",
"siteData",
".",
"Cert",
",",
"err",
... | // LoadSite implements Storage.LoadSite by loading it from disk. If it is not
// present, an instance of ErrNotExist is returned. | [
"LoadSite",
"implements",
"Storage",
".",
"LoadSite",
"by",
"loading",
"it",
"from",
"disk",
".",
"If",
"it",
"is",
"not",
"present",
"an",
"instance",
"of",
"ErrNotExist",
"is",
"returned",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L154-L170 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | StoreSite | func (s *FileStorage) StoreSite(domain string, data *SiteData) error {
err := os.MkdirAll(s.site(domain), 0700)
if err != nil {
return fmt.Errorf("making site directory: %v", err)
}
err = ioutil.WriteFile(s.siteCertFile(domain), data.Cert, 0600)
if err != nil {
return fmt.Errorf("writing certificate file: %v",... | go | func (s *FileStorage) StoreSite(domain string, data *SiteData) error {
err := os.MkdirAll(s.site(domain), 0700)
if err != nil {
return fmt.Errorf("making site directory: %v", err)
}
err = ioutil.WriteFile(s.siteCertFile(domain), data.Cert, 0600)
if err != nil {
return fmt.Errorf("writing certificate file: %v",... | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"StoreSite",
"(",
"domain",
"string",
",",
"data",
"*",
"SiteData",
")",
"error",
"{",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"s",
".",
"site",
"(",
"domain",
")",
",",
"0700",
")",
"\n",
"if",
"err",
... | // StoreSite implements Storage.StoreSite by writing it to disk. The base
// directories needed for the file are automatically created as needed. | [
"StoreSite",
"implements",
"Storage",
".",
"StoreSite",
"by",
"writing",
"it",
"to",
"disk",
".",
"The",
"base",
"directories",
"needed",
"for",
"the",
"file",
"are",
"automatically",
"created",
"as",
"needed",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L174-L192 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | DeleteSite | func (s *FileStorage) DeleteSite(domain string) error {
err := os.Remove(s.siteCertFile(domain))
if err != nil {
if os.IsNotExist(err) {
return ErrNotExist(err)
}
return err
}
return nil
} | go | func (s *FileStorage) DeleteSite(domain string) error {
err := os.Remove(s.siteCertFile(domain))
if err != nil {
if os.IsNotExist(err) {
return ErrNotExist(err)
}
return err
}
return nil
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"DeleteSite",
"(",
"domain",
"string",
")",
"error",
"{",
"err",
":=",
"os",
".",
"Remove",
"(",
"s",
".",
"siteCertFile",
"(",
"domain",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"... | // DeleteSite implements Storage.DeleteSite by deleting just the cert from
// disk. If it is not present, an instance of ErrNotExist is returned. | [
"DeleteSite",
"implements",
"Storage",
".",
"DeleteSite",
"by",
"deleting",
"just",
"the",
"cert",
"from",
"disk",
".",
"If",
"it",
"is",
"not",
"present",
"an",
"instance",
"of",
"ErrNotExist",
"is",
"returned",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L196-L205 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | LoadUser | func (s *FileStorage) LoadUser(email string) (*UserData, error) {
var err error
userData := new(UserData)
userData.Reg, err = s.readFile(s.userRegFile(email))
if err != nil {
return nil, err
}
userData.Key, err = s.readFile(s.userKeyFile(email))
if err != nil {
return nil, err
}
return userData, nil
} | go | func (s *FileStorage) LoadUser(email string) (*UserData, error) {
var err error
userData := new(UserData)
userData.Reg, err = s.readFile(s.userRegFile(email))
if err != nil {
return nil, err
}
userData.Key, err = s.readFile(s.userKeyFile(email))
if err != nil {
return nil, err
}
return userData, nil
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"LoadUser",
"(",
"email",
"string",
")",
"(",
"*",
"UserData",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"userData",
":=",
"new",
"(",
"UserData",
")",
"\n",
"userData",
".",
"Reg",
",",
"err",
... | // LoadUser implements Storage.LoadUser by loading it from disk. If it is not
// present, an instance of ErrNotExist is returned. | [
"LoadUser",
"implements",
"Storage",
".",
"LoadUser",
"by",
"loading",
"it",
"from",
"disk",
".",
"If",
"it",
"is",
"not",
"present",
"an",
"instance",
"of",
"ErrNotExist",
"is",
"returned",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L209-L221 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | StoreUser | func (s *FileStorage) StoreUser(email string, data *UserData) error {
err := os.MkdirAll(s.user(email), 0700)
if err != nil {
return fmt.Errorf("making user directory: %v", err)
}
err = ioutil.WriteFile(s.userRegFile(email), data.Reg, 0600)
if err != nil {
return fmt.Errorf("writing user registration file: %v"... | go | func (s *FileStorage) StoreUser(email string, data *UserData) error {
err := os.MkdirAll(s.user(email), 0700)
if err != nil {
return fmt.Errorf("making user directory: %v", err)
}
err = ioutil.WriteFile(s.userRegFile(email), data.Reg, 0600)
if err != nil {
return fmt.Errorf("writing user registration file: %v"... | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"StoreUser",
"(",
"email",
"string",
",",
"data",
"*",
"UserData",
")",
"error",
"{",
"err",
":=",
"os",
".",
"MkdirAll",
"(",
"s",
".",
"user",
"(",
"email",
")",
",",
"0700",
")",
"\n",
"if",
"err",
"!... | // StoreUser implements Storage.StoreUser by writing it to disk. The base
// directories needed for the file are automatically created as needed. | [
"StoreUser",
"implements",
"Storage",
".",
"StoreUser",
"by",
"writing",
"it",
"to",
"disk",
".",
"The",
"base",
"directories",
"needed",
"for",
"the",
"file",
"are",
"automatically",
"created",
"as",
"needed",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L225-L239 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | TryLock | func (s *FileStorage) TryLock(name string) (Waiter, error) {
s.nameLocksMu.Lock()
defer s.nameLocksMu.Unlock()
wg, ok := s.nameLocks[name]
if ok {
// lock already obtained, let caller wait on it
return wg, nil
}
// caller gets lock
wg = new(sync.WaitGroup)
wg.Add(1)
s.nameLocks[name] = wg
return nil, nil
... | go | func (s *FileStorage) TryLock(name string) (Waiter, error) {
s.nameLocksMu.Lock()
defer s.nameLocksMu.Unlock()
wg, ok := s.nameLocks[name]
if ok {
// lock already obtained, let caller wait on it
return wg, nil
}
// caller gets lock
wg = new(sync.WaitGroup)
wg.Add(1)
s.nameLocks[name] = wg
return nil, nil
... | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"TryLock",
"(",
"name",
"string",
")",
"(",
"Waiter",
",",
"error",
")",
"{",
"s",
".",
"nameLocksMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"nameLocksMu",
".",
"Unlock",
"(",
")",
"\n",
"wg",
... | // TryLock attempts to get a lock for name, otherwise it returns
// a Waiter value to wait until the other process is finished. | [
"TryLock",
"attempts",
"to",
"get",
"a",
"lock",
"for",
"name",
"otherwise",
"it",
"returns",
"a",
"Waiter",
"value",
"to",
"wait",
"until",
"the",
"other",
"process",
"is",
"finished",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L243-L256 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | Unlock | func (s *FileStorage) Unlock(name string) error {
s.nameLocksMu.Lock()
defer s.nameLocksMu.Unlock()
wg, ok := s.nameLocks[name]
if !ok {
return fmt.Errorf("FileStorage: no lock to release for %s", name)
}
wg.Done()
delete(s.nameLocks, name)
return nil
} | go | func (s *FileStorage) Unlock(name string) error {
s.nameLocksMu.Lock()
defer s.nameLocksMu.Unlock()
wg, ok := s.nameLocks[name]
if !ok {
return fmt.Errorf("FileStorage: no lock to release for %s", name)
}
wg.Done()
delete(s.nameLocks, name)
return nil
} | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"Unlock",
"(",
"name",
"string",
")",
"error",
"{",
"s",
".",
"nameLocksMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"nameLocksMu",
".",
"Unlock",
"(",
")",
"\n",
"wg",
",",
"ok",
":=",
"s",
".",... | // Unlock unlocks name. | [
"Unlock",
"unlocks",
"name",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L259-L269 | train |
inverse-inc/packetfence | go/caddy/caddy/caddytls/filestorage.go | MostRecentUserEmail | func (s *FileStorage) MostRecentUserEmail() string {
userDirs, err := ioutil.ReadDir(s.users())
if err != nil {
return ""
}
var mostRecent os.FileInfo
for _, dir := range userDirs {
if !dir.IsDir() {
continue
}
if mostRecent == nil || dir.ModTime().After(mostRecent.ModTime()) {
mostRecent = dir
}
... | go | func (s *FileStorage) MostRecentUserEmail() string {
userDirs, err := ioutil.ReadDir(s.users())
if err != nil {
return ""
}
var mostRecent os.FileInfo
for _, dir := range userDirs {
if !dir.IsDir() {
continue
}
if mostRecent == nil || dir.ModTime().After(mostRecent.ModTime()) {
mostRecent = dir
}
... | [
"func",
"(",
"s",
"*",
"FileStorage",
")",
"MostRecentUserEmail",
"(",
")",
"string",
"{",
"userDirs",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"s",
".",
"users",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n... | // MostRecentUserEmail implements Storage.MostRecentUserEmail by finding the
// most recently written sub directory in the users' directory. It is named
// after the email address. This corresponds to the most recent call to
// StoreUser. | [
"MostRecentUserEmail",
"implements",
"Storage",
".",
"MostRecentUserEmail",
"by",
"finding",
"the",
"most",
"recently",
"written",
"sub",
"directory",
"in",
"the",
"users",
"directory",
".",
"It",
"is",
"named",
"after",
"the",
"email",
"address",
".",
"This",
"... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddytls/filestorage.go#L275-L293 | train |
inverse-inc/packetfence | go/caddy/pfipset/pfipset.go | setup | func setup(c *caddy.Controller) error {
ctx := log.LoggerNewContext(context.Background())
pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.Cluster.HostsIp)
pfipset, err := buildPfipsetHandler(ctx)
if err != nil {
return err
}
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handle... | go | func setup(c *caddy.Controller) error {
ctx := log.LoggerNewContext(context.Background())
pfconfigdriver.PfconfigPool.AddStruct(ctx, &pfconfigdriver.Config.Cluster.HostsIp)
pfipset, err := buildPfipsetHandler(ctx)
if err != nil {
return err
}
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handle... | [
"func",
"setup",
"(",
"c",
"*",
"caddy",
".",
"Controller",
")",
"error",
"{",
"ctx",
":=",
"log",
".",
"LoggerNewContext",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n\n",
"pfconfigdriver",
".",
"PfconfigPool",
".",
"AddStruct",
"(",
"ctx",
","... | // Setup the pfipset middleware
// Also loads the pfconfig resources and registers them in the pool | [
"Setup",
"the",
"pfipset",
"middleware",
"Also",
"loads",
"the",
"pfconfig",
"resources",
"and",
"registers",
"them",
"in",
"the",
"pool"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/pfipset/pfipset.go#L44-L61 | train |
inverse-inc/packetfence | go/caddy/caddy/caddyhttp/extensions/ext.go | resourceExists | func resourceExists(root, path string) bool {
_, err := os.Stat(root + path)
// technically we should use os.IsNotExist(err)
// but we don't handle any other kinds of errors anyway
return err == nil
} | go | func resourceExists(root, path string) bool {
_, err := os.Stat(root + path)
// technically we should use os.IsNotExist(err)
// but we don't handle any other kinds of errors anyway
return err == nil
} | [
"func",
"resourceExists",
"(",
"root",
",",
"path",
"string",
")",
"bool",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"root",
"+",
"path",
")",
"\n",
"// technically we should use os.IsNotExist(err)",
"// but we don't handle any other kinds of errors anyway",... | // resourceExists returns true if the file specified at
// root + path exists; false otherwise. | [
"resourceExists",
"returns",
"true",
"if",
"the",
"file",
"specified",
"at",
"root",
"+",
"path",
"exists",
";",
"false",
"otherwise",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/caddy/caddy/caddyhttp/extensions/ext.go#L47-L52 | train |
inverse-inc/packetfence | go/firewallsso/firewalls.go | Refresh | func (f *FirewallsContainer) Refresh(ctx context.Context) {
reload := false
f.ids.PfconfigNS = "config::Firewall_SSO"
// If ids changed, we want to reload
if !pfconfigdriver.IsValid(ctx, &f.ids) {
reload = true
}
pfconfigdriver.FetchDecodeSocketCache(ctx, &f.ids)
fssoFactory := NewFactory(ctx)
if f.Struc... | go | func (f *FirewallsContainer) Refresh(ctx context.Context) {
reload := false
f.ids.PfconfigNS = "config::Firewall_SSO"
// If ids changed, we want to reload
if !pfconfigdriver.IsValid(ctx, &f.ids) {
reload = true
}
pfconfigdriver.FetchDecodeSocketCache(ctx, &f.ids)
fssoFactory := NewFactory(ctx)
if f.Struc... | [
"func",
"(",
"f",
"*",
"FirewallsContainer",
")",
"Refresh",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"reload",
":=",
"false",
"\n\n",
"f",
".",
"ids",
".",
"PfconfigNS",
"=",
"\"",
"\"",
"\n\n",
"// If ids changed, we want to reload",
"if",
"!",
"... | // Refresh the FirewallsContainer struct
// Will first check if the IDs have changed in pfconfig and reload if they did
// Then it will check if all the IDs in pfconfig are loaded and valid and reload otherwise | [
"Refresh",
"the",
"FirewallsContainer",
"struct",
"Will",
"first",
"check",
"if",
"the",
"IDs",
"have",
"changed",
"in",
"pfconfig",
"and",
"reload",
"if",
"they",
"did",
"Then",
"it",
"will",
"check",
"if",
"all",
"the",
"IDs",
"in",
"pfconfig",
"are",
"l... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/firewallsso/firewalls.go#L24-L72 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | getPfconfigSocketPath | func getPfconfigSocketPath() string {
if pfconfigSocketPathCache != "" {
// Do nothing, cache is populated, will be returned below
} else if sharedutils.EnvOrDefault("PFCONFIG_TESTING", "") == "" {
pfconfigSocketPathCache = pfconfigSocketPath
} else {
fmt.Println("Test flag is on. Using pfconfig test socket pa... | go | func getPfconfigSocketPath() string {
if pfconfigSocketPathCache != "" {
// Do nothing, cache is populated, will be returned below
} else if sharedutils.EnvOrDefault("PFCONFIG_TESTING", "") == "" {
pfconfigSocketPathCache = pfconfigSocketPath
} else {
fmt.Println("Test flag is on. Using pfconfig test socket pa... | [
"func",
"getPfconfigSocketPath",
"(",
")",
"string",
"{",
"if",
"pfconfigSocketPathCache",
"!=",
"\"",
"\"",
"{",
"// Do nothing, cache is populated, will be returned below",
"}",
"else",
"if",
"sharedutils",
".",
"EnvOrDefault",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")... | // Get the pfconfig socket path depending on whether or not we're in testing
// Since the environment is not bound to change at runtime, the socket path is computed once and cached in pfconfigSocketPathCache
// If the socket should be re-computed, empty out pfconfigSocketPathCache and run this function | [
"Get",
"the",
"pfconfig",
"socket",
"path",
"depending",
"on",
"whether",
"or",
"not",
"we",
"re",
"in",
"testing",
"Since",
"the",
"environment",
"is",
"not",
"bound",
"to",
"change",
"at",
"runtime",
"the",
"socket",
"path",
"is",
"computed",
"once",
"an... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L50-L60 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | GetPayload | func (q *Query) GetPayload() string {
j, err := json.Marshal(struct {
Encoding string `json:"encoding"`
Method string `json:"method"`
NS string `json:"key"`
}{
Encoding: q.encoding,
Method: q.method,
NS: q.ns,
})
sharedutils.CheckError(err)
return string(j) + "\n"
} | go | func (q *Query) GetPayload() string {
j, err := json.Marshal(struct {
Encoding string `json:"encoding"`
Method string `json:"method"`
NS string `json:"key"`
}{
Encoding: q.encoding,
Method: q.method,
NS: q.ns,
})
sharedutils.CheckError(err)
return string(j) + "\n"
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"GetPayload",
"(",
")",
"string",
"{",
"j",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"struct",
"{",
"Encoding",
"string",
"`json:\"encoding\"`",
"\n",
"Method",
"string",
"`json:\"method\"`",
"\n",
"NS",
"string",... | // Get the payload to send to pfconfig based on the Query attributes
// Also sets the payload attribute at the same time | [
"Get",
"the",
"payload",
"to",
"send",
"to",
"pfconfig",
"based",
"on",
"the",
"Query",
"attributes",
"Also",
"sets",
"the",
"payload",
"attribute",
"at",
"the",
"same",
"time"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L71-L83 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | GetIdentifier | func (q *Query) GetIdentifier() string {
return fmt.Sprintf("%s|%s", q.method, q.ns)
} | go | func (q *Query) GetIdentifier() string {
return fmt.Sprintf("%s|%s", q.method, q.ns)
} | [
"func",
"(",
"q",
"*",
"Query",
")",
"GetIdentifier",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"q",
".",
"method",
",",
"q",
".",
"ns",
")",
"\n",
"}"
] | // Get a string identifier of the query | [
"Get",
"a",
"string",
"identifier",
"of",
"the",
"query"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L86-L88 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | connectSocket | func connectSocket(ctx context.Context) net.Conn {
timeoutChan := time.After(SocketTimeout)
var c net.Conn
err := errors.New("Not yet connected")
for err != nil {
select {
case <-timeoutChan:
panic("Can't connect to pfconfig socket")
default:
// We try to connect to the pfconfig socket
// If we fai... | go | func connectSocket(ctx context.Context) net.Conn {
timeoutChan := time.After(SocketTimeout)
var c net.Conn
err := errors.New("Not yet connected")
for err != nil {
select {
case <-timeoutChan:
panic("Can't connect to pfconfig socket")
default:
// We try to connect to the pfconfig socket
// If we fai... | [
"func",
"connectSocket",
"(",
"ctx",
"context",
".",
"Context",
")",
"net",
".",
"Conn",
"{",
"timeoutChan",
":=",
"time",
".",
"After",
"(",
"SocketTimeout",
")",
"\n\n",
"var",
"c",
"net",
".",
"Conn",
"\n",
"err",
":=",
"errors",
".",
"New",
"(",
... | // Connect to the pfconfig socket
// If it fails to connect, it will try it every second up to the time defined in SocketTimeout
// After SocketTimeout is reached, this will panic | [
"Connect",
"to",
"the",
"pfconfig",
"socket",
"If",
"it",
"fails",
"to",
"connect",
"it",
"will",
"try",
"it",
"every",
"second",
"up",
"to",
"the",
"time",
"defined",
"in",
"SocketTimeout",
"After",
"SocketTimeout",
"is",
"reached",
"this",
"will",
"panic"
... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L93-L116 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | FetchSocket | func FetchSocket(ctx context.Context, payload string) []byte {
c := connectSocket(ctx)
// Send our query in the socket
fmt.Fprintf(c, payload)
var buf bytes.Buffer
buf.ReadFrom(c)
// First 4 bytes are a little-endian representing the length of the payload
var length uint32
binary.Read(&buf, binary.LittleEndi... | go | func FetchSocket(ctx context.Context, payload string) []byte {
c := connectSocket(ctx)
// Send our query in the socket
fmt.Fprintf(c, payload)
var buf bytes.Buffer
buf.ReadFrom(c)
// First 4 bytes are a little-endian representing the length of the payload
var length uint32
binary.Read(&buf, binary.LittleEndi... | [
"func",
"FetchSocket",
"(",
"ctx",
"context",
".",
"Context",
",",
"payload",
"string",
")",
"[",
"]",
"byte",
"{",
"c",
":=",
"connectSocket",
"(",
"ctx",
")",
"\n\n",
"// Send our query in the socket",
"fmt",
".",
"Fprintf",
"(",
"c",
",",
"payload",
")"... | // Fetch data from the pfconfig socket for a string payload
// Returns the bytes received from the socket | [
"Fetch",
"data",
"from",
"the",
"pfconfig",
"socket",
"for",
"a",
"string",
"payload",
"Returns",
"the",
"bytes",
"received",
"from",
"the",
"socket"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L120-L143 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | metadataFromField | func metadataFromField(ctx context.Context, param interface{}, fieldName string) string {
var ov reflect.Value
ov = reflect.ValueOf(param)
for ov.Kind() == reflect.Ptr || ov.Kind() == reflect.Interface {
ov = ov.Elem()
}
// We check if the field was set to a value as this will overide the value in the tag
// ... | go | func metadataFromField(ctx context.Context, param interface{}, fieldName string) string {
var ov reflect.Value
ov = reflect.ValueOf(param)
for ov.Kind() == reflect.Ptr || ov.Kind() == reflect.Interface {
ov = ov.Elem()
}
// We check if the field was set to a value as this will overide the value in the tag
// ... | [
"func",
"metadataFromField",
"(",
"ctx",
"context",
".",
"Context",
",",
"param",
"interface",
"{",
"}",
",",
"fieldName",
"string",
")",
"string",
"{",
"var",
"ov",
"reflect",
".",
"Value",
"\n\n",
"ov",
"=",
"reflect",
".",
"ValueOf",
"(",
"param",
")"... | // Lookup the pfconfig metadata for a specific field
// If there is a non-zero value in the field, it will be taken
// Otherwise it will take the value in the val tag of the field | [
"Lookup",
"the",
"pfconfig",
"metadata",
"for",
"a",
"specific",
"field",
"If",
"there",
"is",
"a",
"non",
"-",
"zero",
"value",
"in",
"the",
"field",
"it",
"will",
"be",
"taken",
"Otherwise",
"it",
"will",
"take",
"the",
"value",
"in",
"the",
"val",
"... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L148-L181 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | decodeInterface | func decodeInterface(ctx context.Context, encoding string, b []byte, o interface{}) {
switch encoding {
case "json":
decodeJsonInterface(ctx, b, o)
default:
panic(fmt.Sprintf("Unknown encoding %s", encoding))
}
} | go | func decodeInterface(ctx context.Context, encoding string, b []byte, o interface{}) {
switch encoding {
case "json":
decodeJsonInterface(ctx, b, o)
default:
panic(fmt.Sprintf("Unknown encoding %s", encoding))
}
} | [
"func",
"decodeInterface",
"(",
"ctx",
"context",
".",
"Context",
",",
"encoding",
"string",
",",
"b",
"[",
"]",
"byte",
",",
"o",
"interface",
"{",
"}",
")",
"{",
"switch",
"encoding",
"{",
"case",
"\"",
"\"",
":",
"decodeJsonInterface",
"(",
"ctx",
"... | // Decode the struct from bytes given an encoding
// For now only JSON is supported | [
"Decode",
"the",
"struct",
"from",
"bytes",
"given",
"an",
"encoding",
"For",
"now",
"only",
"JSON",
"is",
"supported"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L194-L201 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | decodeJsonInterface | func decodeJsonInterface(ctx context.Context, b []byte, o interface{}) {
decoder := json.NewDecoder(bytes.NewReader(b))
for {
if err := decoder.Decode(&o); err == io.EOF {
break
} else if err != nil {
panic(err)
}
}
} | go | func decodeJsonInterface(ctx context.Context, b []byte, o interface{}) {
decoder := json.NewDecoder(bytes.NewReader(b))
for {
if err := decoder.Decode(&o); err == io.EOF {
break
} else if err != nil {
panic(err)
}
}
} | [
"func",
"decodeJsonInterface",
"(",
"ctx",
"context",
".",
"Context",
",",
"b",
"[",
"]",
"byte",
",",
"o",
"interface",
"{",
"}",
")",
"{",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"bytes",
".",
"NewReader",
"(",
"b",
")",
")",
"\n",
"for",
... | // Decode an array of bytes representing a json string into interface
// Panics if there is an error decoding the JSON data | [
"Decode",
"an",
"array",
"of",
"bytes",
"representing",
"a",
"json",
"string",
"into",
"interface",
"Panics",
"if",
"there",
"is",
"an",
"error",
"decoding",
"the",
"JSON",
"data"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L205-L214 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | FetchDecodeSocketCache | func FetchDecodeSocketCache(ctx context.Context, o PfconfigObject) (bool, error) {
query := createQuery(ctx, o)
ctx = log.AddToLogContext(ctx, "PfconfigObject", query.GetIdentifier())
// If the resource is still valid and is already loaded
if IsValid(ctx, o) {
return false, nil
}
err := FetchDecodeSocket(ctx,... | go | func FetchDecodeSocketCache(ctx context.Context, o PfconfigObject) (bool, error) {
query := createQuery(ctx, o)
ctx = log.AddToLogContext(ctx, "PfconfigObject", query.GetIdentifier())
// If the resource is still valid and is already loaded
if IsValid(ctx, o) {
return false, nil
}
err := FetchDecodeSocket(ctx,... | [
"func",
"FetchDecodeSocketCache",
"(",
"ctx",
"context",
".",
"Context",
",",
"o",
"PfconfigObject",
")",
"(",
"bool",
",",
"error",
")",
"{",
"query",
":=",
"createQuery",
"(",
"ctx",
",",
"o",
")",
"\n",
"ctx",
"=",
"log",
".",
"AddToLogContext",
"(",
... | // Fetch and decode from the socket but only if the PfconfigObject is not valid anymore | [
"Fetch",
"and",
"decode",
"from",
"the",
"socket",
"but",
"only",
"if",
"the",
"PfconfigObject",
"is",
"not",
"valid",
"anymore"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L335-L346 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | FetchKeys | func FetchKeys(ctx context.Context, name string) ([]string, error) {
keys := PfconfigKeys{PfconfigNS: name}
err := FetchDecodeSocket(ctx, &keys)
if err != nil {
return nil, err
}
return keys.Keys, nil
} | go | func FetchKeys(ctx context.Context, name string) ([]string, error) {
keys := PfconfigKeys{PfconfigNS: name}
err := FetchDecodeSocket(ctx, &keys)
if err != nil {
return nil, err
}
return keys.Keys, nil
} | [
"func",
"FetchKeys",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"keys",
":=",
"PfconfigKeys",
"{",
"PfconfigNS",
":",
"name",
"}",
"\n",
"err",
":=",
"FetchDecodeSocket",
"(",
"ct... | // Fetch the keys of a namespace | [
"Fetch",
"the",
"keys",
"of",
"a",
"namespace"
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L349-L357 | train |
inverse-inc/packetfence | go/pfconfigdriver/fetch.go | FetchDecodeSocket | func FetchDecodeSocket(ctx context.Context, o PfconfigObject) error {
ptrT := reflect.TypeOf(o)
new := reflect.New(ptrT.Elem())
newo := new.Interface().(PfconfigObject)
transferMetadata(ctx, &o, &newo)
reflect.ValueOf(o).Elem().Set(reflect.ValueOf(newo).Elem())
query := createQuery(ctx, o)
jsonResponse := Fe... | go | func FetchDecodeSocket(ctx context.Context, o PfconfigObject) error {
ptrT := reflect.TypeOf(o)
new := reflect.New(ptrT.Elem())
newo := new.Interface().(PfconfigObject)
transferMetadata(ctx, &o, &newo)
reflect.ValueOf(o).Elem().Set(reflect.ValueOf(newo).Elem())
query := createQuery(ctx, o)
jsonResponse := Fe... | [
"func",
"FetchDecodeSocket",
"(",
"ctx",
"context",
".",
"Context",
",",
"o",
"PfconfigObject",
")",
"error",
"{",
"ptrT",
":=",
"reflect",
".",
"TypeOf",
"(",
"o",
")",
"\n",
"new",
":=",
"reflect",
".",
"New",
"(",
"ptrT",
".",
"Elem",
"(",
")",
")... | // Fetch and decode a namespace from pfconfig given a pfconfig compatible struct
// This will fetch the json representation from pfconfig and decode it into o
// o must be a pointer to the struct as this should be used by reference | [
"Fetch",
"and",
"decode",
"a",
"namespace",
"from",
"pfconfig",
"given",
"a",
"pfconfig",
"compatible",
"struct",
"This",
"will",
"fetch",
"the",
"json",
"representation",
"from",
"pfconfig",
"and",
"decode",
"it",
"into",
"o",
"o",
"must",
"be",
"a",
"point... | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/pfconfigdriver/fetch.go#L362-L397 | train |
inverse-inc/packetfence | go/coredns/plugin/backend_lookup.go | AAAA | func AAAA(b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) {
services, err := b.Services(state, false, opt)
if err != nil {
return nil, err
}
for _, serv := range services {
what, ip := serv.HostType()
switch what {
case dns.TypeCN... | go | func AAAA(b ServiceBackend, zone string, state request.Request, previousRecords []dns.RR, opt Options) (records []dns.RR, err error) {
services, err := b.Services(state, false, opt)
if err != nil {
return nil, err
}
for _, serv := range services {
what, ip := serv.HostType()
switch what {
case dns.TypeCN... | [
"func",
"AAAA",
"(",
"b",
"ServiceBackend",
",",
"zone",
"string",
",",
"state",
"request",
".",
"Request",
",",
"previousRecords",
"[",
"]",
"dns",
".",
"RR",
",",
"opt",
"Options",
")",
"(",
"records",
"[",
"]",
"dns",
".",
"RR",
",",
"err",
"error... | // AAAA returns AAAA records from Backend or an error. | [
"AAAA",
"returns",
"AAAA",
"records",
"from",
"Backend",
"or",
"an",
"error",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/backend_lookup.go#L80-L142 | train |
inverse-inc/packetfence | go/coredns/plugin/backend_lookup.go | MX | func MX(b ServiceBackend, zone string, state request.Request, opt Options) (records, extra []dns.RR, err error) {
services, err := b.Services(state, false, opt)
if err != nil {
return nil, nil, err
}
lookup := make(map[string]bool)
for _, serv := range services {
if !serv.Mail {
continue
}
what, ip := ... | go | func MX(b ServiceBackend, zone string, state request.Request, opt Options) (records, extra []dns.RR, err error) {
services, err := b.Services(state, false, opt)
if err != nil {
return nil, nil, err
}
lookup := make(map[string]bool)
for _, serv := range services {
if !serv.Mail {
continue
}
what, ip := ... | [
"func",
"MX",
"(",
"b",
"ServiceBackend",
",",
"zone",
"string",
",",
"state",
"request",
".",
"Request",
",",
"opt",
"Options",
")",
"(",
"records",
",",
"extra",
"[",
"]",
"dns",
".",
"RR",
",",
"err",
"error",
")",
"{",
"services",
",",
"err",
"... | // MX returns MX records from the Backend. If the Target is not a name but an IP address, a name is created on the fly. | [
"MX",
"returns",
"MX",
"records",
"from",
"the",
"Backend",
".",
"If",
"the",
"Target",
"is",
"not",
"a",
"name",
"but",
"an",
"IP",
"address",
"a",
"name",
"is",
"created",
"on",
"the",
"fly",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/backend_lookup.go#L226-L280 | train |
inverse-inc/packetfence | go/coredns/plugin/backend_lookup.go | CNAME | func CNAME(b ServiceBackend, zone string, state request.Request, opt Options) (records []dns.RR, err error) {
services, err := b.Services(state, true, opt)
if err != nil {
return nil, err
}
if len(services) > 0 {
serv := services[0]
if ip := net.ParseIP(serv.Host); ip == nil {
records = append(records, se... | go | func CNAME(b ServiceBackend, zone string, state request.Request, opt Options) (records []dns.RR, err error) {
services, err := b.Services(state, true, opt)
if err != nil {
return nil, err
}
if len(services) > 0 {
serv := services[0]
if ip := net.ParseIP(serv.Host); ip == nil {
records = append(records, se... | [
"func",
"CNAME",
"(",
"b",
"ServiceBackend",
",",
"zone",
"string",
",",
"state",
"request",
".",
"Request",
",",
"opt",
"Options",
")",
"(",
"records",
"[",
"]",
"dns",
".",
"RR",
",",
"err",
"error",
")",
"{",
"services",
",",
"err",
":=",
"b",
"... | // CNAME returns CNAME records from the backend or an error. | [
"CNAME",
"returns",
"CNAME",
"records",
"from",
"the",
"backend",
"or",
"an",
"error",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/backend_lookup.go#L283-L296 | train |
inverse-inc/packetfence | go/coredns/plugin/backend_lookup.go | BackendError | func BackendError(b ServiceBackend, zone string, rcode int, state request.Request, err error, opt Options) (int, error) {
m := new(dns.Msg)
m.SetRcode(state.Req, rcode)
m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
m.Ns, _ = SOA(b, zone, state, opt)
state.SizeAndDo(m)
state.W.WriteMsg(m)
... | go | func BackendError(b ServiceBackend, zone string, rcode int, state request.Request, err error, opt Options) (int, error) {
m := new(dns.Msg)
m.SetRcode(state.Req, rcode)
m.Authoritative, m.RecursionAvailable, m.Compress = true, true, true
m.Ns, _ = SOA(b, zone, state, opt)
state.SizeAndDo(m)
state.W.WriteMsg(m)
... | [
"func",
"BackendError",
"(",
"b",
"ServiceBackend",
",",
"zone",
"string",
",",
"rcode",
"int",
",",
"state",
"request",
".",
"Request",
",",
"err",
"error",
",",
"opt",
"Options",
")",
"(",
"int",
",",
"error",
")",
"{",
"m",
":=",
"new",
"(",
"dns"... | // BackendError writes an error response to the client. | [
"BackendError",
"writes",
"an",
"error",
"response",
"to",
"the",
"client",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/backend_lookup.go#L383-L393 | train |
inverse-inc/packetfence | go/coredns/plugin/reverse/network.go | hostnameToIP | func (network *network) hostnameToIP(rname string) net.IP {
var matchedIP net.IP
match := network.RegexMatchIP.FindStringSubmatch(rname)
if len(match) != 2 {
return nil
}
if network.IPnet.IP.To4() != nil {
matchedIP = net.ParseIP(match[1])
} else {
// TODO: can probably just allocate a []byte and use that... | go | func (network *network) hostnameToIP(rname string) net.IP {
var matchedIP net.IP
match := network.RegexMatchIP.FindStringSubmatch(rname)
if len(match) != 2 {
return nil
}
if network.IPnet.IP.To4() != nil {
matchedIP = net.ParseIP(match[1])
} else {
// TODO: can probably just allocate a []byte and use that... | [
"func",
"(",
"network",
"*",
"network",
")",
"hostnameToIP",
"(",
"rname",
"string",
")",
"net",
".",
"IP",
"{",
"var",
"matchedIP",
"net",
".",
"IP",
"\n\n",
"match",
":=",
"network",
".",
"RegexMatchIP",
".",
"FindStringSubmatch",
"(",
"rname",
")",
"\... | // hostnameToIP converts the hostname back to an ip, based on the template
// returns nil if there is no IP found. | [
"hostnameToIP",
"converts",
"the",
"hostname",
"back",
"to",
"an",
"ip",
"based",
"on",
"the",
"template",
"returns",
"nil",
"if",
"there",
"is",
"no",
"IP",
"found",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/reverse/network.go#L26-L55 | train |
inverse-inc/packetfence | go/coredns/plugin/reverse/network.go | ipToHostname | func (network *network) ipToHostname(ip net.IP) (name string) {
if ipv4 := ip.To4(); ipv4 != nil {
// replace . to -
name = ipv4.String()
} else {
// assume v6
// ensure zeros are present in string
buf := make([]byte, 0, len(ip)*4)
for i := 0; i < len(ip); i++ {
v := ip[i]
buf = append(buf, hexDigit... | go | func (network *network) ipToHostname(ip net.IP) (name string) {
if ipv4 := ip.To4(); ipv4 != nil {
// replace . to -
name = ipv4.String()
} else {
// assume v6
// ensure zeros are present in string
buf := make([]byte, 0, len(ip)*4)
for i := 0; i < len(ip); i++ {
v := ip[i]
buf = append(buf, hexDigit... | [
"func",
"(",
"network",
"*",
"network",
")",
"ipToHostname",
"(",
"ip",
"net",
".",
"IP",
")",
"(",
"name",
"string",
")",
"{",
"if",
"ipv4",
":=",
"ip",
".",
"To4",
"(",
")",
";",
"ipv4",
"!=",
"nil",
"{",
"// replace . to -",
"name",
"=",
"ipv4",... | // ipToHostname converts an IP to an DNS compatible hostname and injects it into the template.domain. | [
"ipToHostname",
"converts",
"an",
"IP",
"to",
"an",
"DNS",
"compatible",
"hostname",
"and",
"injects",
"it",
"into",
"the",
"template",
".",
"domain",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/reverse/network.go#L58-L75 | train |
inverse-inc/packetfence | go/coredns/plugin/health/healther.go | Ok | func (h *health) Ok() bool {
h.RLock()
defer h.RUnlock()
return h.ok
} | go | func (h *health) Ok() bool {
h.RLock()
defer h.RUnlock()
return h.ok
} | [
"func",
"(",
"h",
"*",
"health",
")",
"Ok",
"(",
")",
"bool",
"{",
"h",
".",
"RLock",
"(",
")",
"\n",
"defer",
"h",
".",
"RUnlock",
"(",
")",
"\n",
"return",
"h",
".",
"ok",
"\n",
"}"
] | // Ok returns the global health status of all plugin configured in this server. | [
"Ok",
"returns",
"the",
"global",
"health",
"status",
"of",
"all",
"plugin",
"configured",
"in",
"this",
"server",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/health/healther.go#L16-L20 | train |
inverse-inc/packetfence | go/coredns/plugin/health/healther.go | SetOk | func (h *health) SetOk(ok bool) {
h.Lock()
defer h.Unlock()
h.ok = ok
} | go | func (h *health) SetOk(ok bool) {
h.Lock()
defer h.Unlock()
h.ok = ok
} | [
"func",
"(",
"h",
"*",
"health",
")",
"SetOk",
"(",
"ok",
"bool",
")",
"{",
"h",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"Unlock",
"(",
")",
"\n",
"h",
".",
"ok",
"=",
"ok",
"\n",
"}"
] | // SetOk sets the global health status of all plugin configured in this server. | [
"SetOk",
"sets",
"the",
"global",
"health",
"status",
"of",
"all",
"plugin",
"configured",
"in",
"this",
"server",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/health/healther.go#L23-L27 | train |
inverse-inc/packetfence | go/coredns/plugin/health/healther.go | poll | func (h *health) poll() {
for _, m := range h.h {
if !m.Health() {
h.SetOk(false)
return
}
}
h.SetOk(true)
} | go | func (h *health) poll() {
for _, m := range h.h {
if !m.Health() {
h.SetOk(false)
return
}
}
h.SetOk(true)
} | [
"func",
"(",
"h",
"*",
"health",
")",
"poll",
"(",
")",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"h",
".",
"h",
"{",
"if",
"!",
"m",
".",
"Health",
"(",
")",
"{",
"h",
".",
"SetOk",
"(",
"false",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}"... | // poll polls all healthers and sets the global state. | [
"poll",
"polls",
"all",
"healthers",
"and",
"sets",
"the",
"global",
"state",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/health/healther.go#L30-L38 | train |
inverse-inc/packetfence | go/coredns/plugin/proxy/lookup.go | NewLookupWithOption | func NewLookupWithOption(hosts []string, opts Options) Proxy {
p := Proxy{Next: nil}
// TODO(miek): this needs to be unified with upstream.go's NewStaticUpstreams, caddy uses NewHost
// we should copy/make something similar.
upstream := &staticUpstream{
from: ".",
HealthCheck: healthcheck.HealthCheck{
FailT... | go | func NewLookupWithOption(hosts []string, opts Options) Proxy {
p := Proxy{Next: nil}
// TODO(miek): this needs to be unified with upstream.go's NewStaticUpstreams, caddy uses NewHost
// we should copy/make something similar.
upstream := &staticUpstream{
from: ".",
HealthCheck: healthcheck.HealthCheck{
FailT... | [
"func",
"NewLookupWithOption",
"(",
"hosts",
"[",
"]",
"string",
",",
"opts",
"Options",
")",
"Proxy",
"{",
"p",
":=",
"Proxy",
"{",
"Next",
":",
"nil",
"}",
"\n\n",
"// TODO(miek): this needs to be unified with upstream.go's NewStaticUpstreams, caddy uses NewHost",
"//... | // NewLookupWithOption process creates a simple round robin forward with potentially forced proto for upstream. | [
"NewLookupWithOption",
"process",
"creates",
"a",
"simple",
"round",
"robin",
"forward",
"with",
"potentially",
"forced",
"proto",
"for",
"upstream",
"."
] | f29912bde7974931d699aba60aa8fde1c5d9a826 | https://github.com/inverse-inc/packetfence/blob/f29912bde7974931d699aba60aa8fde1c5d9a826/go/coredns/plugin/proxy/lookup.go#L22-L48 | 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.