id
int32 0
167k
| 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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
164,600 | go-redis/redis | internal/pool/pool.go | IdleLen | func (p *ConnPool) IdleLen() int {
p.connsMu.Lock()
n := p.idleConnsLen
p.connsMu.Unlock()
return n
} | go | func (p *ConnPool) IdleLen() int {
p.connsMu.Lock()
n := p.idleConnsLen
p.connsMu.Unlock()
return n
} | [
"func",
"(",
"p",
"*",
"ConnPool",
")",
"IdleLen",
"(",
")",
"int",
"{",
"p",
".",
"connsMu",
".",
"Lock",
"(",
")",
"\n",
"n",
":=",
"p",
".",
"idleConnsLen",
"\n",
"p",
".",
"connsMu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"n",
"\n",
"}"
] | // IdleLen returns number of idle connections. | [
"IdleLen",
"returns",
"number",
"of",
"idle",
"connections",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/internal/pool/pool.go#L345-L350 |
164,601 | go-redis/redis | cluster.go | GC | func (c *clusterNodes) GC(generation uint32) {
var collected []*clusterNode
c.mu.Lock()
for addr, node := range c.allNodes {
if node.Generation() >= generation {
continue
}
c.clusterAddrs = remove(c.clusterAddrs, addr)
delete(c.allNodes, addr)
collected = append(collected, node)
}
c.mu.Unlock()
for _, node := range collected {
_ = node.Client.Close()
}
} | go | func (c *clusterNodes) GC(generation uint32) {
var collected []*clusterNode
c.mu.Lock()
for addr, node := range c.allNodes {
if node.Generation() >= generation {
continue
}
c.clusterAddrs = remove(c.clusterAddrs, addr)
delete(c.allNodes, addr)
collected = append(collected, node)
}
c.mu.Unlock()
for _, node := range collected {
_ = node.Client.Close()
}
} | [
"func",
"(",
"c",
"*",
"clusterNodes",
")",
"GC",
"(",
"generation",
"uint32",
")",
"{",
"var",
"collected",
"[",
"]",
"*",
"clusterNode",
"\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"for",
"addr",
",",
"node",
":=",
"range",
"c",
".",
"allNodes",
"{",
"if",
"node",
".",
"Generation",
"(",
")",
">=",
"generation",
"{",
"continue",
"\n",
"}",
"\n\n",
"c",
".",
"clusterAddrs",
"=",
"remove",
"(",
"c",
".",
"clusterAddrs",
",",
"addr",
")",
"\n",
"delete",
"(",
"c",
".",
"allNodes",
",",
"addr",
")",
"\n",
"collected",
"=",
"append",
"(",
"collected",
",",
"node",
")",
"\n",
"}",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"node",
":=",
"range",
"collected",
"{",
"_",
"=",
"node",
".",
"Client",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // GC removes unused nodes. | [
"GC",
"removes",
"unused",
"nodes",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/cluster.go#L306-L323 |
164,602 | go-redis/redis | cluster.go | ReloadState | func (c *ClusterClient) ReloadState() error {
_, err := c.state.Reload()
return err
} | go | func (c *ClusterClient) ReloadState() error {
_, err := c.state.Reload()
return err
} | [
"func",
"(",
"c",
"*",
"ClusterClient",
")",
"ReloadState",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"state",
".",
"Reload",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ReloadState reloads cluster state. If available it calls ClusterSlots func
// to get cluster slots information. | [
"ReloadState",
"reloads",
"cluster",
"state",
".",
"If",
"available",
"it",
"calls",
"ClusterSlots",
"func",
"to",
"get",
"cluster",
"slots",
"information",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/cluster.go#L690-L693 |
164,603 | go-redis/redis | cluster.go | ForEachNode | func (c *ClusterClient) ForEachNode(fn func(client *Client) error) error {
state, err := c.state.ReloadOrGet()
if err != nil {
return err
}
var wg sync.WaitGroup
errCh := make(chan error, 1)
worker := func(node *clusterNode) {
defer wg.Done()
err := fn(node.Client)
if err != nil {
select {
case errCh <- err:
default:
}
}
}
for _, node := range state.Masters {
wg.Add(1)
go worker(node)
}
for _, node := range state.Slaves {
wg.Add(1)
go worker(node)
}
wg.Wait()
select {
case err := <-errCh:
return err
default:
return nil
}
} | go | func (c *ClusterClient) ForEachNode(fn func(client *Client) error) error {
state, err := c.state.ReloadOrGet()
if err != nil {
return err
}
var wg sync.WaitGroup
errCh := make(chan error, 1)
worker := func(node *clusterNode) {
defer wg.Done()
err := fn(node.Client)
if err != nil {
select {
case errCh <- err:
default:
}
}
}
for _, node := range state.Masters {
wg.Add(1)
go worker(node)
}
for _, node := range state.Slaves {
wg.Add(1)
go worker(node)
}
wg.Wait()
select {
case err := <-errCh:
return err
default:
return nil
}
} | [
"func",
"(",
"c",
"*",
"ClusterClient",
")",
"ForEachNode",
"(",
"fn",
"func",
"(",
"client",
"*",
"Client",
")",
"error",
")",
"error",
"{",
"state",
",",
"err",
":=",
"c",
".",
"state",
".",
"ReloadOrGet",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"errCh",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"worker",
":=",
"func",
"(",
"node",
"*",
"clusterNode",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"err",
":=",
"fn",
"(",
"node",
".",
"Client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"select",
"{",
"case",
"errCh",
"<-",
"err",
":",
"default",
":",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"node",
":=",
"range",
"state",
".",
"Masters",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"worker",
"(",
"node",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"state",
".",
"Slaves",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"worker",
"(",
"node",
")",
"\n",
"}",
"\n\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"errCh",
":",
"return",
"err",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ForEachNode concurrently calls the fn on each known node in the cluster.
// It returns the first error if any. | [
"ForEachNode",
"concurrently",
"calls",
"the",
"fn",
"on",
"each",
"known",
"node",
"in",
"the",
"cluster",
".",
"It",
"returns",
"the",
"first",
"error",
"if",
"any",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/cluster.go#L1056-L1091 |
164,604 | go-redis/redis | cluster.go | reaper | func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
ticker := time.NewTicker(idleCheckFrequency)
defer ticker.Stop()
for range ticker.C {
nodes, err := c.nodes.All()
if err != nil {
break
}
for _, node := range nodes {
_, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
if err != nil {
internal.Logf("ReapStaleConns failed: %s", err)
}
}
}
} | go | func (c *ClusterClient) reaper(idleCheckFrequency time.Duration) {
ticker := time.NewTicker(idleCheckFrequency)
defer ticker.Stop()
for range ticker.C {
nodes, err := c.nodes.All()
if err != nil {
break
}
for _, node := range nodes {
_, err := node.Client.connPool.(*pool.ConnPool).ReapStaleConns()
if err != nil {
internal.Logf("ReapStaleConns failed: %s", err)
}
}
}
} | [
"func",
"(",
"c",
"*",
"ClusterClient",
")",
"reaper",
"(",
"idleCheckFrequency",
"time",
".",
"Duration",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"idleCheckFrequency",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n\n",
"for",
"range",
"ticker",
".",
"C",
"{",
"nodes",
",",
"err",
":=",
"c",
".",
"nodes",
".",
"All",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"{",
"_",
",",
"err",
":=",
"node",
".",
"Client",
".",
"connPool",
".",
"(",
"*",
"pool",
".",
"ConnPool",
")",
".",
"ReapStaleConns",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"internal",
".",
"Logf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // reaper closes idle connections to the cluster. | [
"reaper",
"closes",
"idle",
"connections",
"to",
"the",
"cluster",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/cluster.go#L1166-L1183 |
164,605 | go-redis/redis | cluster.go | Subscribe | func (c *ClusterClient) Subscribe(channels ...string) *PubSub {
pubsub := c.pubSub()
if len(channels) > 0 {
_ = pubsub.Subscribe(channels...)
}
return pubsub
} | go | func (c *ClusterClient) Subscribe(channels ...string) *PubSub {
pubsub := c.pubSub()
if len(channels) > 0 {
_ = pubsub.Subscribe(channels...)
}
return pubsub
} | [
"func",
"(",
"c",
"*",
"ClusterClient",
")",
"Subscribe",
"(",
"channels",
"...",
"string",
")",
"*",
"PubSub",
"{",
"pubsub",
":=",
"c",
".",
"pubSub",
"(",
")",
"\n",
"if",
"len",
"(",
"channels",
")",
">",
"0",
"{",
"_",
"=",
"pubsub",
".",
"Subscribe",
"(",
"channels",
"...",
")",
"\n",
"}",
"\n",
"return",
"pubsub",
"\n",
"}"
] | // Subscribe subscribes the client to the specified channels.
// Channels can be omitted to create empty subscription. | [
"Subscribe",
"subscribes",
"the",
"client",
"to",
"the",
"specified",
"channels",
".",
"Channels",
"can",
"be",
"omitted",
"to",
"create",
"empty",
"subscription",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/cluster.go#L1574-L1580 |
164,606 | go-redis/redis | tx.go | Watch | func (c *Client) Watch(fn func(*Tx) error, keys ...string) error {
tx := c.newTx()
if len(keys) > 0 {
if err := tx.Watch(keys...).Err(); err != nil {
_ = tx.Close()
return err
}
}
err := fn(tx)
_ = tx.Close()
return err
} | go | func (c *Client) Watch(fn func(*Tx) error, keys ...string) error {
tx := c.newTx()
if len(keys) > 0 {
if err := tx.Watch(keys...).Err(); err != nil {
_ = tx.Close()
return err
}
}
err := fn(tx)
_ = tx.Close()
return err
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Watch",
"(",
"fn",
"func",
"(",
"*",
"Tx",
")",
"error",
",",
"keys",
"...",
"string",
")",
"error",
"{",
"tx",
":=",
"c",
".",
"newTx",
"(",
")",
"\n",
"if",
"len",
"(",
"keys",
")",
">",
"0",
"{",
"if",
"err",
":=",
"tx",
".",
"Watch",
"(",
"keys",
"...",
")",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"_",
"=",
"tx",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"err",
":=",
"fn",
"(",
"tx",
")",
"\n",
"_",
"=",
"tx",
".",
"Close",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Watch prepares a transaction and marks the keys to be watched
// for conditional execution if there are any keys.
//
// The transaction is automatically closed when fn exits. | [
"Watch",
"prepares",
"a",
"transaction",
"and",
"marks",
"the",
"keys",
"to",
"be",
"watched",
"for",
"conditional",
"execution",
"if",
"there",
"are",
"any",
"keys",
".",
"The",
"transaction",
"is",
"automatically",
"closed",
"when",
"fn",
"exits",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/tx.go#L36-L48 |
164,607 | go-redis/redis | tx.go | Close | func (c *Tx) Close() error {
_ = c.Unwatch().Err()
return c.baseClient.Close()
} | go | func (c *Tx) Close() error {
_ = c.Unwatch().Err()
return c.baseClient.Close()
} | [
"func",
"(",
"c",
"*",
"Tx",
")",
"Close",
"(",
")",
"error",
"{",
"_",
"=",
"c",
".",
"Unwatch",
"(",
")",
".",
"Err",
"(",
")",
"\n",
"return",
"c",
".",
"baseClient",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close closes the transaction, releasing any open resources. | [
"Close",
"closes",
"the",
"transaction",
"releasing",
"any",
"open",
"resources",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/tx.go#L51-L54 |
164,608 | go-redis/redis | tx.go | Watch | func (c *Tx) Watch(keys ...string) *StatusCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "watch"
for i, key := range keys {
args[1+i] = key
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
} | go | func (c *Tx) Watch(keys ...string) *StatusCmd {
args := make([]interface{}, 1+len(keys))
args[0] = "watch"
for i, key := range keys {
args[1+i] = key
}
cmd := NewStatusCmd(args...)
c.Process(cmd)
return cmd
} | [
"func",
"(",
"c",
"*",
"Tx",
")",
"Watch",
"(",
"keys",
"...",
"string",
")",
"*",
"StatusCmd",
"{",
"args",
":=",
"make",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"1",
"+",
"len",
"(",
"keys",
")",
")",
"\n",
"args",
"[",
"0",
"]",
"=",
"\"",
"\"",
"\n",
"for",
"i",
",",
"key",
":=",
"range",
"keys",
"{",
"args",
"[",
"1",
"+",
"i",
"]",
"=",
"key",
"\n",
"}",
"\n",
"cmd",
":=",
"NewStatusCmd",
"(",
"args",
"...",
")",
"\n",
"c",
".",
"Process",
"(",
"cmd",
")",
"\n",
"return",
"cmd",
"\n",
"}"
] | // Watch marks the keys to be watched for conditional execution
// of a transaction. | [
"Watch",
"marks",
"the",
"keys",
"to",
"be",
"watched",
"for",
"conditional",
"execution",
"of",
"a",
"transaction",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/tx.go#L58-L67 |
164,609 | go-redis/redis | tx.go | Pipeline | func (c *Tx) Pipeline() Pipeliner {
pipe := Pipeline{
exec: c.processTxPipeline,
}
pipe.statefulCmdable.setProcessor(pipe.Process)
return &pipe
} | go | func (c *Tx) Pipeline() Pipeliner {
pipe := Pipeline{
exec: c.processTxPipeline,
}
pipe.statefulCmdable.setProcessor(pipe.Process)
return &pipe
} | [
"func",
"(",
"c",
"*",
"Tx",
")",
"Pipeline",
"(",
")",
"Pipeliner",
"{",
"pipe",
":=",
"Pipeline",
"{",
"exec",
":",
"c",
".",
"processTxPipeline",
",",
"}",
"\n",
"pipe",
".",
"statefulCmdable",
".",
"setProcessor",
"(",
"pipe",
".",
"Process",
")",
"\n",
"return",
"&",
"pipe",
"\n",
"}"
] | // Pipeline creates a new pipeline. It is more convenient to use Pipelined. | [
"Pipeline",
"creates",
"a",
"new",
"pipeline",
".",
"It",
"is",
"more",
"convenient",
"to",
"use",
"Pipelined",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/tx.go#L82-L88 |
164,610 | go-redis/redis | tx.go | Pipelined | func (c *Tx) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
return c.Pipeline().Pipelined(fn)
} | go | func (c *Tx) Pipelined(fn func(Pipeliner) error) ([]Cmder, error) {
return c.Pipeline().Pipelined(fn)
} | [
"func",
"(",
"c",
"*",
"Tx",
")",
"Pipelined",
"(",
"fn",
"func",
"(",
"Pipeliner",
")",
"error",
")",
"(",
"[",
"]",
"Cmder",
",",
"error",
")",
"{",
"return",
"c",
".",
"Pipeline",
"(",
")",
".",
"Pipelined",
"(",
"fn",
")",
"\n",
"}"
] | // Pipelined executes commands queued in the fn in a transaction.
//
// When using WATCH, EXEC will execute commands only if the watched keys
// were not modified, allowing for a check-and-set mechanism.
//
// Exec always returns list of commands. If transaction fails
// TxFailedErr is returned. Otherwise Exec returns an error of the first
// failed command or nil. | [
"Pipelined",
"executes",
"commands",
"queued",
"in",
"the",
"fn",
"in",
"a",
"transaction",
".",
"When",
"using",
"WATCH",
"EXEC",
"will",
"execute",
"commands",
"only",
"if",
"the",
"watched",
"keys",
"were",
"not",
"modified",
"allowing",
"for",
"a",
"check",
"-",
"and",
"-",
"set",
"mechanism",
".",
"Exec",
"always",
"returns",
"list",
"of",
"commands",
".",
"If",
"transaction",
"fails",
"TxFailedErr",
"is",
"returned",
".",
"Otherwise",
"Exec",
"returns",
"an",
"error",
"of",
"the",
"first",
"failed",
"command",
"or",
"nil",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/tx.go#L98-L100 |
164,611 | go-redis/redis | tx.go | TxPipelined | func (c *Tx) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
return c.Pipelined(fn)
} | go | func (c *Tx) TxPipelined(fn func(Pipeliner) error) ([]Cmder, error) {
return c.Pipelined(fn)
} | [
"func",
"(",
"c",
"*",
"Tx",
")",
"TxPipelined",
"(",
"fn",
"func",
"(",
"Pipeliner",
")",
"error",
")",
"(",
"[",
"]",
"Cmder",
",",
"error",
")",
"{",
"return",
"c",
".",
"Pipelined",
"(",
"fn",
")",
"\n",
"}"
] | // TxPipelined is an alias for Pipelined. | [
"TxPipelined",
"is",
"an",
"alias",
"for",
"Pipelined",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/tx.go#L103-L105 |
164,612 | go-redis/redis | result.go | NewCmdResult | func NewCmdResult(val interface{}, err error) *Cmd {
var cmd Cmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewCmdResult(val interface{}, err error) *Cmd {
var cmd Cmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewCmdResult",
"(",
"val",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"*",
"Cmd",
"{",
"var",
"cmd",
"Cmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewCmdResult returns a Cmd initialised with val and err for testing | [
"NewCmdResult",
"returns",
"a",
"Cmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L6-L11 |
164,613 | go-redis/redis | result.go | NewSliceResult | func NewSliceResult(val []interface{}, err error) *SliceCmd {
var cmd SliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewSliceResult(val []interface{}, err error) *SliceCmd {
var cmd SliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewSliceResult",
"(",
"val",
"[",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"*",
"SliceCmd",
"{",
"var",
"cmd",
"SliceCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewSliceResult returns a SliceCmd initialised with val and err for testing | [
"NewSliceResult",
"returns",
"a",
"SliceCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L14-L19 |
164,614 | go-redis/redis | result.go | NewStatusResult | func NewStatusResult(val string, err error) *StatusCmd {
var cmd StatusCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewStatusResult(val string, err error) *StatusCmd {
var cmd StatusCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewStatusResult",
"(",
"val",
"string",
",",
"err",
"error",
")",
"*",
"StatusCmd",
"{",
"var",
"cmd",
"StatusCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewStatusResult returns a StatusCmd initialised with val and err for testing | [
"NewStatusResult",
"returns",
"a",
"StatusCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L22-L27 |
164,615 | go-redis/redis | result.go | NewIntResult | func NewIntResult(val int64, err error) *IntCmd {
var cmd IntCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewIntResult(val int64, err error) *IntCmd {
var cmd IntCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewIntResult",
"(",
"val",
"int64",
",",
"err",
"error",
")",
"*",
"IntCmd",
"{",
"var",
"cmd",
"IntCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewIntResult returns an IntCmd initialised with val and err for testing | [
"NewIntResult",
"returns",
"an",
"IntCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L30-L35 |
164,616 | go-redis/redis | result.go | NewDurationResult | func NewDurationResult(val time.Duration, err error) *DurationCmd {
var cmd DurationCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewDurationResult(val time.Duration, err error) *DurationCmd {
var cmd DurationCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewDurationResult",
"(",
"val",
"time",
".",
"Duration",
",",
"err",
"error",
")",
"*",
"DurationCmd",
"{",
"var",
"cmd",
"DurationCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewDurationResult returns a DurationCmd initialised with val and err for testing | [
"NewDurationResult",
"returns",
"a",
"DurationCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L38-L43 |
164,617 | go-redis/redis | result.go | NewBoolResult | func NewBoolResult(val bool, err error) *BoolCmd {
var cmd BoolCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewBoolResult(val bool, err error) *BoolCmd {
var cmd BoolCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewBoolResult",
"(",
"val",
"bool",
",",
"err",
"error",
")",
"*",
"BoolCmd",
"{",
"var",
"cmd",
"BoolCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewBoolResult returns a BoolCmd initialised with val and err for testing | [
"NewBoolResult",
"returns",
"a",
"BoolCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L46-L51 |
164,618 | go-redis/redis | result.go | NewStringResult | func NewStringResult(val string, err error) *StringCmd {
var cmd StringCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewStringResult(val string, err error) *StringCmd {
var cmd StringCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewStringResult",
"(",
"val",
"string",
",",
"err",
"error",
")",
"*",
"StringCmd",
"{",
"var",
"cmd",
"StringCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewStringResult returns a StringCmd initialised with val and err for testing | [
"NewStringResult",
"returns",
"a",
"StringCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L54-L59 |
164,619 | go-redis/redis | result.go | NewFloatResult | func NewFloatResult(val float64, err error) *FloatCmd {
var cmd FloatCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewFloatResult(val float64, err error) *FloatCmd {
var cmd FloatCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewFloatResult",
"(",
"val",
"float64",
",",
"err",
"error",
")",
"*",
"FloatCmd",
"{",
"var",
"cmd",
"FloatCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewFloatResult returns a FloatCmd initialised with val and err for testing | [
"NewFloatResult",
"returns",
"a",
"FloatCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L62-L67 |
164,620 | go-redis/redis | result.go | NewStringSliceResult | func NewStringSliceResult(val []string, err error) *StringSliceCmd {
var cmd StringSliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewStringSliceResult(val []string, err error) *StringSliceCmd {
var cmd StringSliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewStringSliceResult",
"(",
"val",
"[",
"]",
"string",
",",
"err",
"error",
")",
"*",
"StringSliceCmd",
"{",
"var",
"cmd",
"StringSliceCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewStringSliceResult returns a StringSliceCmd initialised with val and err for testing | [
"NewStringSliceResult",
"returns",
"a",
"StringSliceCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L70-L75 |
164,621 | go-redis/redis | result.go | NewBoolSliceResult | func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
var cmd BoolSliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
var cmd BoolSliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewBoolSliceResult",
"(",
"val",
"[",
"]",
"bool",
",",
"err",
"error",
")",
"*",
"BoolSliceCmd",
"{",
"var",
"cmd",
"BoolSliceCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewBoolSliceResult returns a BoolSliceCmd initialised with val and err for testing | [
"NewBoolSliceResult",
"returns",
"a",
"BoolSliceCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L78-L83 |
164,622 | go-redis/redis | result.go | NewStringStringMapResult | func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
var cmd StringStringMapCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
var cmd StringStringMapCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewStringStringMapResult",
"(",
"val",
"map",
"[",
"string",
"]",
"string",
",",
"err",
"error",
")",
"*",
"StringStringMapCmd",
"{",
"var",
"cmd",
"StringStringMapCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewStringStringMapResult returns a StringStringMapCmd initialised with val and err for testing | [
"NewStringStringMapResult",
"returns",
"a",
"StringStringMapCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L86-L91 |
164,623 | go-redis/redis | result.go | NewStringIntMapCmdResult | func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
var cmd StringIntMapCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
var cmd StringIntMapCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewStringIntMapCmdResult",
"(",
"val",
"map",
"[",
"string",
"]",
"int64",
",",
"err",
"error",
")",
"*",
"StringIntMapCmd",
"{",
"var",
"cmd",
"StringIntMapCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewStringIntMapCmdResult returns a StringIntMapCmd initialised with val and err for testing | [
"NewStringIntMapCmdResult",
"returns",
"a",
"StringIntMapCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L94-L99 |
164,624 | go-redis/redis | result.go | NewZSliceCmdResult | func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
var cmd ZSliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
var cmd ZSliceCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewZSliceCmdResult",
"(",
"val",
"[",
"]",
"Z",
",",
"err",
"error",
")",
"*",
"ZSliceCmd",
"{",
"var",
"cmd",
"ZSliceCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewZSliceCmdResult returns a ZSliceCmd initialised with val and err for testing | [
"NewZSliceCmdResult",
"returns",
"a",
"ZSliceCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L102-L107 |
164,625 | go-redis/redis | result.go | NewScanCmdResult | func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
var cmd ScanCmd
cmd.page = keys
cmd.cursor = cursor
cmd.setErr(err)
return &cmd
} | go | func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
var cmd ScanCmd
cmd.page = keys
cmd.cursor = cursor
cmd.setErr(err)
return &cmd
} | [
"func",
"NewScanCmdResult",
"(",
"keys",
"[",
"]",
"string",
",",
"cursor",
"uint64",
",",
"err",
"error",
")",
"*",
"ScanCmd",
"{",
"var",
"cmd",
"ScanCmd",
"\n",
"cmd",
".",
"page",
"=",
"keys",
"\n",
"cmd",
".",
"cursor",
"=",
"cursor",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewScanCmdResult returns a ScanCmd initialised with val and err for testing | [
"NewScanCmdResult",
"returns",
"a",
"ScanCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L110-L116 |
164,626 | go-redis/redis | result.go | NewClusterSlotsCmdResult | func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
var cmd ClusterSlotsCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
var cmd ClusterSlotsCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewClusterSlotsCmdResult",
"(",
"val",
"[",
"]",
"ClusterSlot",
",",
"err",
"error",
")",
"*",
"ClusterSlotsCmd",
"{",
"var",
"cmd",
"ClusterSlotsCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewClusterSlotsCmdResult returns a ClusterSlotsCmd initialised with val and err for testing | [
"NewClusterSlotsCmdResult",
"returns",
"a",
"ClusterSlotsCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L119-L124 |
164,627 | go-redis/redis | result.go | NewGeoLocationCmdResult | func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
var cmd GeoLocationCmd
cmd.locations = val
cmd.setErr(err)
return &cmd
} | go | func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
var cmd GeoLocationCmd
cmd.locations = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewGeoLocationCmdResult",
"(",
"val",
"[",
"]",
"GeoLocation",
",",
"err",
"error",
")",
"*",
"GeoLocationCmd",
"{",
"var",
"cmd",
"GeoLocationCmd",
"\n",
"cmd",
".",
"locations",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewGeoLocationCmdResult returns a GeoLocationCmd initialised with val and err for testing | [
"NewGeoLocationCmdResult",
"returns",
"a",
"GeoLocationCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L127-L132 |
164,628 | go-redis/redis | result.go | NewCommandsInfoCmdResult | func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
var cmd CommandsInfoCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | go | func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
var cmd CommandsInfoCmd
cmd.val = val
cmd.setErr(err)
return &cmd
} | [
"func",
"NewCommandsInfoCmdResult",
"(",
"val",
"map",
"[",
"string",
"]",
"*",
"CommandInfo",
",",
"err",
"error",
")",
"*",
"CommandsInfoCmd",
"{",
"var",
"cmd",
"CommandsInfoCmd",
"\n",
"cmd",
".",
"val",
"=",
"val",
"\n",
"cmd",
".",
"setErr",
"(",
"err",
")",
"\n",
"return",
"&",
"cmd",
"\n",
"}"
] | // NewCommandsInfoCmdResult returns a CommandsInfoCmd initialised with val and err for testing | [
"NewCommandsInfoCmdResult",
"returns",
"a",
"CommandsInfoCmd",
"initialised",
"with",
"val",
"and",
"err",
"for",
"testing"
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/result.go#L135-L140 |
164,629 | go-redis/redis | ring.go | Vote | func (shard *ringShard) Vote(up bool) bool {
if up {
changed := shard.IsDown()
atomic.StoreInt32(&shard.down, 0)
return changed
}
if shard.IsDown() {
return false
}
atomic.AddInt32(&shard.down, 1)
return shard.IsDown()
} | go | func (shard *ringShard) Vote(up bool) bool {
if up {
changed := shard.IsDown()
atomic.StoreInt32(&shard.down, 0)
return changed
}
if shard.IsDown() {
return false
}
atomic.AddInt32(&shard.down, 1)
return shard.IsDown()
} | [
"func",
"(",
"shard",
"*",
"ringShard",
")",
"Vote",
"(",
"up",
"bool",
")",
"bool",
"{",
"if",
"up",
"{",
"changed",
":=",
"shard",
".",
"IsDown",
"(",
")",
"\n",
"atomic",
".",
"StoreInt32",
"(",
"&",
"shard",
".",
"down",
",",
"0",
")",
"\n",
"return",
"changed",
"\n",
"}",
"\n\n",
"if",
"shard",
".",
"IsDown",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"atomic",
".",
"AddInt32",
"(",
"&",
"shard",
".",
"down",
",",
"1",
")",
"\n",
"return",
"shard",
".",
"IsDown",
"(",
")",
"\n",
"}"
] | // Vote votes to set shard state and returns true if state was changed. | [
"Vote",
"votes",
"to",
"set",
"shard",
"state",
"and",
"returns",
"true",
"if",
"state",
"was",
"changed",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/ring.go#L148-L161 |
164,630 | go-redis/redis | ring.go | Heartbeat | func (c *ringShards) Heartbeat(frequency time.Duration) {
ticker := time.NewTicker(frequency)
defer ticker.Stop()
for range ticker.C {
var rebalance bool
c.mu.RLock()
if c.closed {
c.mu.RUnlock()
break
}
shards := c.list
c.mu.RUnlock()
for _, shard := range shards {
err := shard.Client.Ping().Err()
if shard.Vote(err == nil || err == pool.ErrPoolTimeout) {
internal.Logf("ring shard state changed: %s", shard)
rebalance = true
}
}
if rebalance {
c.rebalance()
}
}
} | go | func (c *ringShards) Heartbeat(frequency time.Duration) {
ticker := time.NewTicker(frequency)
defer ticker.Stop()
for range ticker.C {
var rebalance bool
c.mu.RLock()
if c.closed {
c.mu.RUnlock()
break
}
shards := c.list
c.mu.RUnlock()
for _, shard := range shards {
err := shard.Client.Ping().Err()
if shard.Vote(err == nil || err == pool.ErrPoolTimeout) {
internal.Logf("ring shard state changed: %s", shard)
rebalance = true
}
}
if rebalance {
c.rebalance()
}
}
} | [
"func",
"(",
"c",
"*",
"ringShards",
")",
"Heartbeat",
"(",
"frequency",
"time",
".",
"Duration",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"frequency",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n",
"for",
"range",
"ticker",
".",
"C",
"{",
"var",
"rebalance",
"bool",
"\n\n",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n\n",
"if",
"c",
".",
"closed",
"{",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n",
"break",
"\n",
"}",
"\n\n",
"shards",
":=",
"c",
".",
"list",
"\n",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"err",
":=",
"shard",
".",
"Client",
".",
"Ping",
"(",
")",
".",
"Err",
"(",
")",
"\n",
"if",
"shard",
".",
"Vote",
"(",
"err",
"==",
"nil",
"||",
"err",
"==",
"pool",
".",
"ErrPoolTimeout",
")",
"{",
"internal",
".",
"Logf",
"(",
"\"",
"\"",
",",
"shard",
")",
"\n",
"rebalance",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"rebalance",
"{",
"c",
".",
"rebalance",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // heartbeat monitors state of each shard in the ring. | [
"heartbeat",
"monitors",
"state",
"of",
"each",
"shard",
"in",
"the",
"ring",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/ring.go#L244-L272 |
164,631 | go-redis/redis | ring.go | rebalance | func (c *ringShards) rebalance() {
c.mu.RLock()
shards := c.shards
c.mu.RUnlock()
hash := newConsistentHash(c.opt)
var shardsNum int
for name, shard := range shards {
if shard.IsUp() {
hash.Add(name)
shardsNum++
}
}
c.mu.Lock()
c.hash = hash
c.len = shardsNum
c.mu.Unlock()
} | go | func (c *ringShards) rebalance() {
c.mu.RLock()
shards := c.shards
c.mu.RUnlock()
hash := newConsistentHash(c.opt)
var shardsNum int
for name, shard := range shards {
if shard.IsUp() {
hash.Add(name)
shardsNum++
}
}
c.mu.Lock()
c.hash = hash
c.len = shardsNum
c.mu.Unlock()
} | [
"func",
"(",
"c",
"*",
"ringShards",
")",
"rebalance",
"(",
")",
"{",
"c",
".",
"mu",
".",
"RLock",
"(",
")",
"\n",
"shards",
":=",
"c",
".",
"shards",
"\n",
"c",
".",
"mu",
".",
"RUnlock",
"(",
")",
"\n\n",
"hash",
":=",
"newConsistentHash",
"(",
"c",
".",
"opt",
")",
"\n",
"var",
"shardsNum",
"int",
"\n",
"for",
"name",
",",
"shard",
":=",
"range",
"shards",
"{",
"if",
"shard",
".",
"IsUp",
"(",
")",
"{",
"hash",
".",
"Add",
"(",
"name",
")",
"\n",
"shardsNum",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"hash",
"=",
"hash",
"\n",
"c",
".",
"len",
"=",
"shardsNum",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // rebalance removes dead shards from the Ring. | [
"rebalance",
"removes",
"dead",
"shards",
"from",
"the",
"Ring",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/ring.go#L275-L293 |
164,632 | go-redis/redis | ring.go | PSubscribe | func (c *Ring) PSubscribe(channels ...string) *PubSub {
if len(channels) == 0 {
panic("at least one channel is required")
}
shard, err := c.shards.GetByKey(channels[0])
if err != nil {
// TODO: return PubSub with sticky error
panic(err)
}
return shard.Client.PSubscribe(channels...)
} | go | func (c *Ring) PSubscribe(channels ...string) *PubSub {
if len(channels) == 0 {
panic("at least one channel is required")
}
shard, err := c.shards.GetByKey(channels[0])
if err != nil {
// TODO: return PubSub with sticky error
panic(err)
}
return shard.Client.PSubscribe(channels...)
} | [
"func",
"(",
"c",
"*",
"Ring",
")",
"PSubscribe",
"(",
"channels",
"...",
"string",
")",
"*",
"PubSub",
"{",
"if",
"len",
"(",
"channels",
")",
"==",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"shard",
",",
"err",
":=",
"c",
".",
"shards",
".",
"GetByKey",
"(",
"channels",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO: return PubSub with sticky error",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"shard",
".",
"Client",
".",
"PSubscribe",
"(",
"channels",
"...",
")",
"\n",
"}"
] | // PSubscribe subscribes the client to the given patterns. | [
"PSubscribe",
"subscribes",
"the",
"client",
"to",
"the",
"given",
"patterns",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/ring.go#L449-L460 |
164,633 | go-redis/redis | ring.go | ForEachShard | func (c *Ring) ForEachShard(fn func(client *Client) error) error {
shards := c.shards.List()
var wg sync.WaitGroup
errCh := make(chan error, 1)
for _, shard := range shards {
if shard.IsDown() {
continue
}
wg.Add(1)
go func(shard *ringShard) {
defer wg.Done()
err := fn(shard.Client)
if err != nil {
select {
case errCh <- err:
default:
}
}
}(shard)
}
wg.Wait()
select {
case err := <-errCh:
return err
default:
return nil
}
} | go | func (c *Ring) ForEachShard(fn func(client *Client) error) error {
shards := c.shards.List()
var wg sync.WaitGroup
errCh := make(chan error, 1)
for _, shard := range shards {
if shard.IsDown() {
continue
}
wg.Add(1)
go func(shard *ringShard) {
defer wg.Done()
err := fn(shard.Client)
if err != nil {
select {
case errCh <- err:
default:
}
}
}(shard)
}
wg.Wait()
select {
case err := <-errCh:
return err
default:
return nil
}
} | [
"func",
"(",
"c",
"*",
"Ring",
")",
"ForEachShard",
"(",
"fn",
"func",
"(",
"client",
"*",
"Client",
")",
"error",
")",
"error",
"{",
"shards",
":=",
"c",
".",
"shards",
".",
"List",
"(",
")",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"errCh",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"for",
"_",
",",
"shard",
":=",
"range",
"shards",
"{",
"if",
"shard",
".",
"IsDown",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"shard",
"*",
"ringShard",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"err",
":=",
"fn",
"(",
"shard",
".",
"Client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"select",
"{",
"case",
"errCh",
"<-",
"err",
":",
"default",
":",
"}",
"\n",
"}",
"\n",
"}",
"(",
"shard",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"errCh",
":",
"return",
"err",
"\n",
"default",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // ForEachShard concurrently calls the fn on each live shard in the ring.
// It returns the first error if any. | [
"ForEachShard",
"concurrently",
"calls",
"the",
"fn",
"on",
"each",
"live",
"shard",
"in",
"the",
"ring",
".",
"It",
"returns",
"the",
"first",
"error",
"if",
"any",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/ring.go#L464-L493 |
164,634 | go-redis/redis | options.go | ParseURL | func ParseURL(redisURL string) (*Options, error) {
o := &Options{Network: "tcp"}
u, err := url.Parse(redisURL)
if err != nil {
return nil, err
}
if u.Scheme != "redis" && u.Scheme != "rediss" {
return nil, errors.New("invalid redis URL scheme: " + u.Scheme)
}
if u.User != nil {
if p, ok := u.User.Password(); ok {
o.Password = p
}
}
if len(u.Query()) > 0 {
return nil, errors.New("no options supported")
}
h, p, err := net.SplitHostPort(u.Host)
if err != nil {
h = u.Host
}
if h == "" {
h = "localhost"
}
if p == "" {
p = "6379"
}
o.Addr = net.JoinHostPort(h, p)
f := strings.FieldsFunc(u.Path, func(r rune) bool {
return r == '/'
})
switch len(f) {
case 0:
o.DB = 0
case 1:
if o.DB, err = strconv.Atoi(f[0]); err != nil {
return nil, fmt.Errorf("invalid redis database number: %q", f[0])
}
default:
return nil, errors.New("invalid redis URL path: " + u.Path)
}
if u.Scheme == "rediss" {
o.TLSConfig = &tls.Config{ServerName: h}
}
return o, nil
} | go | func ParseURL(redisURL string) (*Options, error) {
o := &Options{Network: "tcp"}
u, err := url.Parse(redisURL)
if err != nil {
return nil, err
}
if u.Scheme != "redis" && u.Scheme != "rediss" {
return nil, errors.New("invalid redis URL scheme: " + u.Scheme)
}
if u.User != nil {
if p, ok := u.User.Password(); ok {
o.Password = p
}
}
if len(u.Query()) > 0 {
return nil, errors.New("no options supported")
}
h, p, err := net.SplitHostPort(u.Host)
if err != nil {
h = u.Host
}
if h == "" {
h = "localhost"
}
if p == "" {
p = "6379"
}
o.Addr = net.JoinHostPort(h, p)
f := strings.FieldsFunc(u.Path, func(r rune) bool {
return r == '/'
})
switch len(f) {
case 0:
o.DB = 0
case 1:
if o.DB, err = strconv.Atoi(f[0]); err != nil {
return nil, fmt.Errorf("invalid redis database number: %q", f[0])
}
default:
return nil, errors.New("invalid redis URL path: " + u.Path)
}
if u.Scheme == "rediss" {
o.TLSConfig = &tls.Config{ServerName: h}
}
return o, nil
} | [
"func",
"ParseURL",
"(",
"redisURL",
"string",
")",
"(",
"*",
"Options",
",",
"error",
")",
"{",
"o",
":=",
"&",
"Options",
"{",
"Network",
":",
"\"",
"\"",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"redisURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"u",
".",
"Scheme",
"!=",
"\"",
"\"",
"&&",
"u",
".",
"Scheme",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"u",
".",
"Scheme",
")",
"\n",
"}",
"\n\n",
"if",
"u",
".",
"User",
"!=",
"nil",
"{",
"if",
"p",
",",
"ok",
":=",
"u",
".",
"User",
".",
"Password",
"(",
")",
";",
"ok",
"{",
"o",
".",
"Password",
"=",
"p",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"u",
".",
"Query",
"(",
")",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"h",
",",
"p",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"u",
".",
"Host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"h",
"=",
"u",
".",
"Host",
"\n",
"}",
"\n",
"if",
"h",
"==",
"\"",
"\"",
"{",
"h",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"p",
"==",
"\"",
"\"",
"{",
"p",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"o",
".",
"Addr",
"=",
"net",
".",
"JoinHostPort",
"(",
"h",
",",
"p",
")",
"\n\n",
"f",
":=",
"strings",
".",
"FieldsFunc",
"(",
"u",
".",
"Path",
",",
"func",
"(",
"r",
"rune",
")",
"bool",
"{",
"return",
"r",
"==",
"'/'",
"\n",
"}",
")",
"\n",
"switch",
"len",
"(",
"f",
")",
"{",
"case",
"0",
":",
"o",
".",
"DB",
"=",
"0",
"\n",
"case",
"1",
":",
"if",
"o",
".",
"DB",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"f",
"[",
"0",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"f",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"u",
".",
"Path",
")",
"\n",
"}",
"\n\n",
"if",
"u",
".",
"Scheme",
"==",
"\"",
"\"",
"{",
"o",
".",
"TLSConfig",
"=",
"&",
"tls",
".",
"Config",
"{",
"ServerName",
":",
"h",
"}",
"\n",
"}",
"\n",
"return",
"o",
",",
"nil",
"\n",
"}"
] | // ParseURL parses an URL into Options that can be used to connect to Redis. | [
"ParseURL",
"parses",
"an",
"URL",
"into",
"Options",
"that",
"can",
"be",
"used",
"to",
"connect",
"to",
"Redis",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/options.go#L163-L214 |
164,635 | go-redis/redis | pubsub.go | Subscribe | func (c *PubSub) Subscribe(channels ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
err := c.subscribe("subscribe", channels...)
if c.channels == nil {
c.channels = make(map[string]struct{})
}
for _, s := range channels {
c.channels[s] = struct{}{}
}
return err
} | go | func (c *PubSub) Subscribe(channels ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
err := c.subscribe("subscribe", channels...)
if c.channels == nil {
c.channels = make(map[string]struct{})
}
for _, s := range channels {
c.channels[s] = struct{}{}
}
return err
} | [
"func",
"(",
"c",
"*",
"PubSub",
")",
"Subscribe",
"(",
"channels",
"...",
"string",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"err",
":=",
"c",
".",
"subscribe",
"(",
"\"",
"\"",
",",
"channels",
"...",
")",
"\n",
"if",
"c",
".",
"channels",
"==",
"nil",
"{",
"c",
".",
"channels",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"channels",
"{",
"c",
".",
"channels",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // Subscribe the client to the specified channels. It returns
// empty subscription if there are no channels. | [
"Subscribe",
"the",
"client",
"to",
"the",
"specified",
"channels",
".",
"It",
"returns",
"empty",
"subscription",
"if",
"there",
"are",
"no",
"channels",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pubsub.go#L182-L194 |
164,636 | go-redis/redis | pubsub.go | PSubscribe | func (c *PubSub) PSubscribe(patterns ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
err := c.subscribe("psubscribe", patterns...)
if c.patterns == nil {
c.patterns = make(map[string]struct{})
}
for _, s := range patterns {
c.patterns[s] = struct{}{}
}
return err
} | go | func (c *PubSub) PSubscribe(patterns ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
err := c.subscribe("psubscribe", patterns...)
if c.patterns == nil {
c.patterns = make(map[string]struct{})
}
for _, s := range patterns {
c.patterns[s] = struct{}{}
}
return err
} | [
"func",
"(",
"c",
"*",
"PubSub",
")",
"PSubscribe",
"(",
"patterns",
"...",
"string",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"err",
":=",
"c",
".",
"subscribe",
"(",
"\"",
"\"",
",",
"patterns",
"...",
")",
"\n",
"if",
"c",
".",
"patterns",
"==",
"nil",
"{",
"c",
".",
"patterns",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"patterns",
"{",
"c",
".",
"patterns",
"[",
"s",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // PSubscribe the client to the given patterns. It returns
// empty subscription if there are no patterns. | [
"PSubscribe",
"the",
"client",
"to",
"the",
"given",
"patterns",
".",
"It",
"returns",
"empty",
"subscription",
"if",
"there",
"are",
"no",
"patterns",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pubsub.go#L198-L210 |
164,637 | go-redis/redis | pubsub.go | Unsubscribe | func (c *PubSub) Unsubscribe(channels ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
for _, channel := range channels {
delete(c.channels, channel)
}
err := c.subscribe("unsubscribe", channels...)
return err
} | go | func (c *PubSub) Unsubscribe(channels ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
for _, channel := range channels {
delete(c.channels, channel)
}
err := c.subscribe("unsubscribe", channels...)
return err
} | [
"func",
"(",
"c",
"*",
"PubSub",
")",
"Unsubscribe",
"(",
"channels",
"...",
"string",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"channel",
":=",
"range",
"channels",
"{",
"delete",
"(",
"c",
".",
"channels",
",",
"channel",
")",
"\n",
"}",
"\n",
"err",
":=",
"c",
".",
"subscribe",
"(",
"\"",
"\"",
",",
"channels",
"...",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Unsubscribe the client from the given channels, or from all of
// them if none is given. | [
"Unsubscribe",
"the",
"client",
"from",
"the",
"given",
"channels",
"or",
"from",
"all",
"of",
"them",
"if",
"none",
"is",
"given",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pubsub.go#L214-L223 |
164,638 | go-redis/redis | pubsub.go | PUnsubscribe | func (c *PubSub) PUnsubscribe(patterns ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
for _, pattern := range patterns {
delete(c.patterns, pattern)
}
err := c.subscribe("punsubscribe", patterns...)
return err
} | go | func (c *PubSub) PUnsubscribe(patterns ...string) error {
c.mu.Lock()
defer c.mu.Unlock()
for _, pattern := range patterns {
delete(c.patterns, pattern)
}
err := c.subscribe("punsubscribe", patterns...)
return err
} | [
"func",
"(",
"c",
"*",
"PubSub",
")",
"PUnsubscribe",
"(",
"patterns",
"...",
"string",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"for",
"_",
",",
"pattern",
":=",
"range",
"patterns",
"{",
"delete",
"(",
"c",
".",
"patterns",
",",
"pattern",
")",
"\n",
"}",
"\n",
"err",
":=",
"c",
".",
"subscribe",
"(",
"\"",
"\"",
",",
"patterns",
"...",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // PUnsubscribe the client from the given patterns, or from all of
// them if none is given. | [
"PUnsubscribe",
"the",
"client",
"from",
"the",
"given",
"patterns",
"or",
"from",
"all",
"of",
"them",
"if",
"none",
"is",
"given",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pubsub.go#L227-L236 |
164,639 | go-redis/redis | pubsub.go | ReceiveTimeout | func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
if c.cmd == nil {
c.cmd = NewCmd()
}
cn, err := c.conn()
if err != nil {
return nil, err
}
err = cn.WithReader(timeout, func(rd *proto.Reader) error {
return c.cmd.readReply(rd)
})
c.releaseConn(cn, err, timeout > 0)
if err != nil {
return nil, err
}
return c.newMessage(c.cmd.Val())
} | go | func (c *PubSub) ReceiveTimeout(timeout time.Duration) (interface{}, error) {
if c.cmd == nil {
c.cmd = NewCmd()
}
cn, err := c.conn()
if err != nil {
return nil, err
}
err = cn.WithReader(timeout, func(rd *proto.Reader) error {
return c.cmd.readReply(rd)
})
c.releaseConn(cn, err, timeout > 0)
if err != nil {
return nil, err
}
return c.newMessage(c.cmd.Val())
} | [
"func",
"(",
"c",
"*",
"PubSub",
")",
"ReceiveTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"c",
".",
"cmd",
"==",
"nil",
"{",
"c",
".",
"cmd",
"=",
"NewCmd",
"(",
")",
"\n",
"}",
"\n\n",
"cn",
",",
"err",
":=",
"c",
".",
"conn",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"cn",
".",
"WithReader",
"(",
"timeout",
",",
"func",
"(",
"rd",
"*",
"proto",
".",
"Reader",
")",
"error",
"{",
"return",
"c",
".",
"cmd",
".",
"readReply",
"(",
"rd",
")",
"\n",
"}",
")",
"\n\n",
"c",
".",
"releaseConn",
"(",
"cn",
",",
"err",
",",
"timeout",
">",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"newMessage",
"(",
"c",
".",
"cmd",
".",
"Val",
"(",
")",
")",
"\n",
"}"
] | // ReceiveTimeout acts like Receive but returns an error if message
// is not received in time. This is low-level API and in most cases
// Channel should be used instead. | [
"ReceiveTimeout",
"acts",
"like",
"Receive",
"but",
"returns",
"an",
"error",
"if",
"message",
"is",
"not",
"received",
"in",
"time",
".",
"This",
"is",
"low",
"-",
"level",
"API",
"and",
"in",
"most",
"cases",
"Channel",
"should",
"be",
"used",
"instead",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pubsub.go#L343-L363 |
164,640 | go-redis/redis | pubsub.go | ReceiveMessage | func (c *PubSub) ReceiveMessage() (*Message, error) {
for {
msg, err := c.Receive()
if err != nil {
return nil, err
}
switch msg := msg.(type) {
case *Subscription:
// Ignore.
case *Pong:
// Ignore.
case *Message:
return msg, nil
default:
err := fmt.Errorf("redis: unknown message: %T", msg)
return nil, err
}
}
} | go | func (c *PubSub) ReceiveMessage() (*Message, error) {
for {
msg, err := c.Receive()
if err != nil {
return nil, err
}
switch msg := msg.(type) {
case *Subscription:
// Ignore.
case *Pong:
// Ignore.
case *Message:
return msg, nil
default:
err := fmt.Errorf("redis: unknown message: %T", msg)
return nil, err
}
}
} | [
"func",
"(",
"c",
"*",
"PubSub",
")",
"ReceiveMessage",
"(",
")",
"(",
"*",
"Message",
",",
"error",
")",
"{",
"for",
"{",
"msg",
",",
"err",
":=",
"c",
".",
"Receive",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"msg",
":=",
"msg",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Subscription",
":",
"// Ignore.",
"case",
"*",
"Pong",
":",
"// Ignore.",
"case",
"*",
"Message",
":",
"return",
"msg",
",",
"nil",
"\n",
"default",
":",
"err",
":=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"msg",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // ReceiveMessage returns a Message or error ignoring Subscription and Pong
// messages. This is low-level API and in most cases Channel should be used
// instead. | [
"ReceiveMessage",
"returns",
"a",
"Message",
"or",
"error",
"ignoring",
"Subscription",
"and",
"Pong",
"messages",
".",
"This",
"is",
"low",
"-",
"level",
"API",
"and",
"in",
"most",
"cases",
"Channel",
"should",
"be",
"used",
"instead",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pubsub.go#L375-L394 |
164,641 | go-redis/redis | script.go | Run | func (s *Script) Run(c scripter, keys []string, args ...interface{}) *Cmd {
r := s.EvalSha(c, keys, args...)
if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") {
return s.Eval(c, keys, args...)
}
return r
} | go | func (s *Script) Run(c scripter, keys []string, args ...interface{}) *Cmd {
r := s.EvalSha(c, keys, args...)
if err := r.Err(); err != nil && strings.HasPrefix(err.Error(), "NOSCRIPT ") {
return s.Eval(c, keys, args...)
}
return r
} | [
"func",
"(",
"s",
"*",
"Script",
")",
"Run",
"(",
"c",
"scripter",
",",
"keys",
"[",
"]",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"*",
"Cmd",
"{",
"r",
":=",
"s",
".",
"EvalSha",
"(",
"c",
",",
"keys",
",",
"args",
"...",
")",
"\n",
"if",
"err",
":=",
"r",
".",
"Err",
"(",
")",
";",
"err",
"!=",
"nil",
"&&",
"strings",
".",
"HasPrefix",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"s",
".",
"Eval",
"(",
"c",
",",
"keys",
",",
"args",
"...",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // Run optimistically uses EVALSHA to run the script. If script does not exist
// it is retried using EVAL. | [
"Run",
"optimistically",
"uses",
"EVALSHA",
"to",
"run",
"the",
"script",
".",
"If",
"script",
"does",
"not",
"exist",
"it",
"is",
"retried",
"using",
"EVAL",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/script.go#L56-L62 |
164,642 | go-redis/redis | pipeline.go | Process | func (c *Pipeline) Process(cmd Cmder) error {
c.mu.Lock()
c.cmds = append(c.cmds, cmd)
c.mu.Unlock()
return nil
} | go | func (c *Pipeline) Process(cmd Cmder) error {
c.mu.Lock()
c.cmds = append(c.cmds, cmd)
c.mu.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Pipeline",
")",
"Process",
"(",
"cmd",
"Cmder",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"cmds",
"=",
"append",
"(",
"c",
".",
"cmds",
",",
"cmd",
")",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Process queues the cmd for later execution. | [
"Process",
"queues",
"the",
"cmd",
"for",
"later",
"execution",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pipeline.go#L55-L60 |
164,643 | go-redis/redis | pipeline.go | Close | func (c *Pipeline) Close() error {
c.mu.Lock()
c.discard()
c.closed = true
c.mu.Unlock()
return nil
} | go | func (c *Pipeline) Close() error {
c.mu.Lock()
c.discard()
c.closed = true
c.mu.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Pipeline",
")",
"Close",
"(",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"discard",
"(",
")",
"\n",
"c",
".",
"closed",
"=",
"true",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Close closes the pipeline, releasing any open resources. | [
"Close",
"closes",
"the",
"pipeline",
"releasing",
"any",
"open",
"resources",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pipeline.go#L63-L69 |
164,644 | go-redis/redis | pipeline.go | Discard | func (c *Pipeline) Discard() error {
c.mu.Lock()
err := c.discard()
c.mu.Unlock()
return err
} | go | func (c *Pipeline) Discard() error {
c.mu.Lock()
err := c.discard()
c.mu.Unlock()
return err
} | [
"func",
"(",
"c",
"*",
"Pipeline",
")",
"Discard",
"(",
")",
"error",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"err",
":=",
"c",
".",
"discard",
"(",
")",
"\n",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Discard resets the pipeline and discards queued commands. | [
"Discard",
"resets",
"the",
"pipeline",
"and",
"discards",
"queued",
"commands",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pipeline.go#L72-L77 |
164,645 | go-redis/redis | pipeline.go | Exec | func (c *Pipeline) Exec() ([]Cmder, error) {
c.mu.Lock()
defer c.mu.Unlock()
if c.closed {
return nil, pool.ErrClosed
}
if len(c.cmds) == 0 {
return nil, nil
}
cmds := c.cmds
c.cmds = nil
return cmds, c.exec(cmds)
} | go | func (c *Pipeline) Exec() ([]Cmder, error) {
c.mu.Lock()
defer c.mu.Unlock()
if c.closed {
return nil, pool.ErrClosed
}
if len(c.cmds) == 0 {
return nil, nil
}
cmds := c.cmds
c.cmds = nil
return cmds, c.exec(cmds)
} | [
"func",
"(",
"c",
"*",
"Pipeline",
")",
"Exec",
"(",
")",
"(",
"[",
"]",
"Cmder",
",",
"error",
")",
"{",
"c",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"c",
".",
"closed",
"{",
"return",
"nil",
",",
"pool",
".",
"ErrClosed",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"cmds",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"cmds",
":=",
"c",
".",
"cmds",
"\n",
"c",
".",
"cmds",
"=",
"nil",
"\n\n",
"return",
"cmds",
",",
"c",
".",
"exec",
"(",
"cmds",
")",
"\n",
"}"
] | // Exec executes all previously queued commands using one
// client-server roundtrip.
//
// Exec always returns list of commands and error of the first failed
// command if any. | [
"Exec",
"executes",
"all",
"previously",
"queued",
"commands",
"using",
"one",
"client",
"-",
"server",
"roundtrip",
".",
"Exec",
"always",
"returns",
"list",
"of",
"commands",
"and",
"error",
"of",
"the",
"first",
"failed",
"command",
"if",
"any",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/pipeline.go#L92-L108 |
164,646 | go-redis/redis | internal/hashtag/hashtag.go | Slot | func Slot(key string) int {
if key == "" {
return RandomSlot()
}
key = Key(key)
return int(crc16sum(key)) % slotNumber
} | go | func Slot(key string) int {
if key == "" {
return RandomSlot()
}
key = Key(key)
return int(crc16sum(key)) % slotNumber
} | [
"func",
"Slot",
"(",
"key",
"string",
")",
"int",
"{",
"if",
"key",
"==",
"\"",
"\"",
"{",
"return",
"RandomSlot",
"(",
")",
"\n",
"}",
"\n",
"key",
"=",
"Key",
"(",
"key",
")",
"\n",
"return",
"int",
"(",
"crc16sum",
"(",
"key",
")",
")",
"%",
"slotNumber",
"\n",
"}"
] | // hashSlot returns a consistent slot number between 0 and 16383
// for any given string key. | [
"hashSlot",
"returns",
"a",
"consistent",
"slot",
"number",
"between",
"0",
"and",
"16383",
"for",
"any",
"given",
"string",
"key",
"."
] | 97e6ed817821d91977b51fdec185ca2dbb917fa6 | https://github.com/go-redis/redis/blob/97e6ed817821d91977b51fdec185ca2dbb917fa6/internal/hashtag/hashtag.go#L64-L70 |
164,647 | dexidp/dex | server/rotation.go | staticRotationStrategy | func staticRotationStrategy(key *rsa.PrivateKey) rotationStrategy {
return rotationStrategy{
// Setting these values to 100 years is easier than having a flag indicating no rotation.
rotationFrequency: time.Hour * 8760 * 100,
idTokenValidFor: time.Hour * 8760 * 100,
key: func() (*rsa.PrivateKey, error) { return key, nil },
}
} | go | func staticRotationStrategy(key *rsa.PrivateKey) rotationStrategy {
return rotationStrategy{
// Setting these values to 100 years is easier than having a flag indicating no rotation.
rotationFrequency: time.Hour * 8760 * 100,
idTokenValidFor: time.Hour * 8760 * 100,
key: func() (*rsa.PrivateKey, error) { return key, nil },
}
} | [
"func",
"staticRotationStrategy",
"(",
"key",
"*",
"rsa",
".",
"PrivateKey",
")",
"rotationStrategy",
"{",
"return",
"rotationStrategy",
"{",
"// Setting these values to 100 years is easier than having a flag indicating no rotation.",
"rotationFrequency",
":",
"time",
".",
"Hour",
"*",
"8760",
"*",
"100",
",",
"idTokenValidFor",
":",
"time",
".",
"Hour",
"*",
"8760",
"*",
"100",
",",
"key",
":",
"func",
"(",
")",
"(",
"*",
"rsa",
".",
"PrivateKey",
",",
"error",
")",
"{",
"return",
"key",
",",
"nil",
"}",
",",
"}",
"\n",
"}"
] | // staticRotationStrategy returns a strategy which never rotates keys. | [
"staticRotationStrategy",
"returns",
"a",
"strategy",
"which",
"never",
"rotates",
"keys",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/rotation.go#L37-L44 |
164,648 | dexidp/dex | server/rotation.go | defaultRotationStrategy | func defaultRotationStrategy(rotationFrequency, idTokenValidFor time.Duration) rotationStrategy {
return rotationStrategy{
rotationFrequency: rotationFrequency,
idTokenValidFor: idTokenValidFor,
key: func() (*rsa.PrivateKey, error) {
return rsa.GenerateKey(rand.Reader, 2048)
},
}
} | go | func defaultRotationStrategy(rotationFrequency, idTokenValidFor time.Duration) rotationStrategy {
return rotationStrategy{
rotationFrequency: rotationFrequency,
idTokenValidFor: idTokenValidFor,
key: func() (*rsa.PrivateKey, error) {
return rsa.GenerateKey(rand.Reader, 2048)
},
}
} | [
"func",
"defaultRotationStrategy",
"(",
"rotationFrequency",
",",
"idTokenValidFor",
"time",
".",
"Duration",
")",
"rotationStrategy",
"{",
"return",
"rotationStrategy",
"{",
"rotationFrequency",
":",
"rotationFrequency",
",",
"idTokenValidFor",
":",
"idTokenValidFor",
",",
"key",
":",
"func",
"(",
")",
"(",
"*",
"rsa",
".",
"PrivateKey",
",",
"error",
")",
"{",
"return",
"rsa",
".",
"GenerateKey",
"(",
"rand",
".",
"Reader",
",",
"2048",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // defaultRotationStrategy returns a strategy which rotates keys every provided period,
// holding onto the public parts for some specified amount of time. | [
"defaultRotationStrategy",
"returns",
"a",
"strategy",
"which",
"rotates",
"keys",
"every",
"provided",
"period",
"holding",
"onto",
"the",
"public",
"parts",
"for",
"some",
"specified",
"amount",
"of",
"time",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/rotation.go#L48-L56 |
164,649 | dexidp/dex | server/rotation.go | startKeyRotation | func (s *Server) startKeyRotation(ctx context.Context, strategy rotationStrategy, now func() time.Time) {
rotater := keyRotater{s.storage, strategy, now, s.logger}
// Try to rotate immediately so properly configured storages will have keys.
if err := rotater.rotate(); err != nil {
if err == errAlreadyRotated {
s.logger.Infof("Key rotation not needed: %v", err)
} else {
s.logger.Errorf("failed to rotate keys: %v", err)
}
}
go func() {
for {
select {
case <-ctx.Done():
return
case <-time.After(time.Second * 30):
if err := rotater.rotate(); err != nil {
s.logger.Errorf("failed to rotate keys: %v", err)
}
}
}
}()
return
} | go | func (s *Server) startKeyRotation(ctx context.Context, strategy rotationStrategy, now func() time.Time) {
rotater := keyRotater{s.storage, strategy, now, s.logger}
// Try to rotate immediately so properly configured storages will have keys.
if err := rotater.rotate(); err != nil {
if err == errAlreadyRotated {
s.logger.Infof("Key rotation not needed: %v", err)
} else {
s.logger.Errorf("failed to rotate keys: %v", err)
}
}
go func() {
for {
select {
case <-ctx.Done():
return
case <-time.After(time.Second * 30):
if err := rotater.rotate(); err != nil {
s.logger.Errorf("failed to rotate keys: %v", err)
}
}
}
}()
return
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"startKeyRotation",
"(",
"ctx",
"context",
".",
"Context",
",",
"strategy",
"rotationStrategy",
",",
"now",
"func",
"(",
")",
"time",
".",
"Time",
")",
"{",
"rotater",
":=",
"keyRotater",
"{",
"s",
".",
"storage",
",",
"strategy",
",",
"now",
",",
"s",
".",
"logger",
"}",
"\n\n",
"// Try to rotate immediately so properly configured storages will have keys.",
"if",
"err",
":=",
"rotater",
".",
"rotate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"errAlreadyRotated",
"{",
"s",
".",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"s",
".",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"time",
".",
"Second",
"*",
"30",
")",
":",
"if",
"err",
":=",
"rotater",
".",
"rotate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"s",
".",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // startKeyRotation begins key rotation in a new goroutine, closing once the context is canceled.
//
// The method blocks until after the first attempt to rotate keys has completed. That way
// healthy storages will return from this call with valid keys. | [
"startKeyRotation",
"begins",
"key",
"rotation",
"in",
"a",
"new",
"goroutine",
"closing",
"once",
"the",
"context",
"is",
"canceled",
".",
"The",
"method",
"blocks",
"until",
"after",
"the",
"first",
"attempt",
"to",
"rotate",
"keys",
"has",
"completed",
".",
"That",
"way",
"healthy",
"storages",
"will",
"return",
"from",
"this",
"call",
"with",
"valid",
"keys",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/rotation.go#L71-L96 |
164,650 | dexidp/dex | storage/memory/memory.go | New | func New(logger log.Logger) storage.Storage {
return &memStorage{
clients: make(map[string]storage.Client),
authCodes: make(map[string]storage.AuthCode),
refreshTokens: make(map[string]storage.RefreshToken),
authReqs: make(map[string]storage.AuthRequest),
passwords: make(map[string]storage.Password),
offlineSessions: make(map[offlineSessionID]storage.OfflineSessions),
connectors: make(map[string]storage.Connector),
logger: logger,
}
} | go | func New(logger log.Logger) storage.Storage {
return &memStorage{
clients: make(map[string]storage.Client),
authCodes: make(map[string]storage.AuthCode),
refreshTokens: make(map[string]storage.RefreshToken),
authReqs: make(map[string]storage.AuthRequest),
passwords: make(map[string]storage.Password),
offlineSessions: make(map[offlineSessionID]storage.OfflineSessions),
connectors: make(map[string]storage.Connector),
logger: logger,
}
} | [
"func",
"New",
"(",
"logger",
"log",
".",
"Logger",
")",
"storage",
".",
"Storage",
"{",
"return",
"&",
"memStorage",
"{",
"clients",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"storage",
".",
"Client",
")",
",",
"authCodes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"storage",
".",
"AuthCode",
")",
",",
"refreshTokens",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"storage",
".",
"RefreshToken",
")",
",",
"authReqs",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"storage",
".",
"AuthRequest",
")",
",",
"passwords",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"storage",
".",
"Password",
")",
",",
"offlineSessions",
":",
"make",
"(",
"map",
"[",
"offlineSessionID",
"]",
"storage",
".",
"OfflineSessions",
")",
",",
"connectors",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"storage",
".",
"Connector",
")",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"}"
] | // New returns an in memory storage. | [
"New",
"returns",
"an",
"in",
"memory",
"storage",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/memory/memory.go#L14-L25 |
164,651 | dexidp/dex | storage/memory/memory.go | Open | func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
return New(logger), nil
} | go | func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
return New(logger), nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"logger",
"log",
".",
"Logger",
")",
"(",
"storage",
".",
"Storage",
",",
"error",
")",
"{",
"return",
"New",
"(",
"logger",
")",
",",
"nil",
"\n",
"}"
] | // Open always returns a new in memory storage. | [
"Open",
"always",
"returns",
"a",
"new",
"in",
"memory",
"storage",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/memory/memory.go#L35-L37 |
164,652 | dexidp/dex | connector/oidc/oidc.go | knownBrokenAuthHeaderProvider | func knownBrokenAuthHeaderProvider(issuerURL string) bool {
if u, err := url.Parse(issuerURL); err == nil {
for _, host := range brokenAuthHeaderDomains {
if u.Host == host || strings.HasSuffix(u.Host, "."+host) {
return true
}
}
}
return false
} | go | func knownBrokenAuthHeaderProvider(issuerURL string) bool {
if u, err := url.Parse(issuerURL); err == nil {
for _, host := range brokenAuthHeaderDomains {
if u.Host == host || strings.HasSuffix(u.Host, "."+host) {
return true
}
}
}
return false
} | [
"func",
"knownBrokenAuthHeaderProvider",
"(",
"issuerURL",
"string",
")",
"bool",
"{",
"if",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"issuerURL",
")",
";",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"host",
":=",
"range",
"brokenAuthHeaderDomains",
"{",
"if",
"u",
".",
"Host",
"==",
"host",
"||",
"strings",
".",
"HasSuffix",
"(",
"u",
".",
"Host",
",",
"\"",
"\"",
"+",
"host",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // Detect auth header provider issues for known providers. This lets users
// avoid having to explicitly set "basicAuthUnsupported" in their config.
//
// Setting the config field always overrides values returned by this function. | [
"Detect",
"auth",
"header",
"provider",
"issues",
"for",
"known",
"providers",
".",
"This",
"lets",
"users",
"avoid",
"having",
"to",
"explicitly",
"set",
"basicAuthUnsupported",
"in",
"their",
"config",
".",
"Setting",
"the",
"config",
"field",
"always",
"overrides",
"values",
"returned",
"by",
"this",
"function",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/oidc/oidc.go#L56-L65 |
164,653 | dexidp/dex | connector/oidc/oidc.go | Open | func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, err error) {
ctx, cancel := context.WithCancel(context.Background())
provider, err := oidc.NewProvider(ctx, c.Issuer)
if err != nil {
cancel()
return nil, fmt.Errorf("failed to get provider: %v", err)
}
if c.BasicAuthUnsupported != nil {
// Setting "basicAuthUnsupported" always overrides our detection.
if *c.BasicAuthUnsupported {
registerBrokenAuthHeaderProvider(provider.Endpoint().TokenURL)
}
} else if knownBrokenAuthHeaderProvider(c.Issuer) {
registerBrokenAuthHeaderProvider(provider.Endpoint().TokenURL)
}
scopes := []string{oidc.ScopeOpenID}
if len(c.Scopes) > 0 {
scopes = append(scopes, c.Scopes...)
} else {
scopes = append(scopes, "profile", "email")
}
clientID := c.ClientID
return &oidcConnector{
redirectURI: c.RedirectURI,
oauth2Config: &oauth2.Config{
ClientID: clientID,
ClientSecret: c.ClientSecret,
Endpoint: provider.Endpoint(),
Scopes: scopes,
RedirectURL: c.RedirectURI,
},
verifier: provider.Verifier(
&oidc.Config{ClientID: clientID},
),
logger: logger,
cancel: cancel,
hostedDomains: c.HostedDomains,
insecureSkipEmailVerified: c.InsecureSkipEmailVerified,
}, nil
} | go | func (c *Config) Open(id string, logger log.Logger) (conn connector.Connector, err error) {
ctx, cancel := context.WithCancel(context.Background())
provider, err := oidc.NewProvider(ctx, c.Issuer)
if err != nil {
cancel()
return nil, fmt.Errorf("failed to get provider: %v", err)
}
if c.BasicAuthUnsupported != nil {
// Setting "basicAuthUnsupported" always overrides our detection.
if *c.BasicAuthUnsupported {
registerBrokenAuthHeaderProvider(provider.Endpoint().TokenURL)
}
} else if knownBrokenAuthHeaderProvider(c.Issuer) {
registerBrokenAuthHeaderProvider(provider.Endpoint().TokenURL)
}
scopes := []string{oidc.ScopeOpenID}
if len(c.Scopes) > 0 {
scopes = append(scopes, c.Scopes...)
} else {
scopes = append(scopes, "profile", "email")
}
clientID := c.ClientID
return &oidcConnector{
redirectURI: c.RedirectURI,
oauth2Config: &oauth2.Config{
ClientID: clientID,
ClientSecret: c.ClientSecret,
Endpoint: provider.Endpoint(),
Scopes: scopes,
RedirectURL: c.RedirectURI,
},
verifier: provider.Verifier(
&oidc.Config{ClientID: clientID},
),
logger: logger,
cancel: cancel,
hostedDomains: c.HostedDomains,
insecureSkipEmailVerified: c.InsecureSkipEmailVerified,
}, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"conn",
"connector",
".",
"Connector",
",",
"err",
"error",
")",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n\n",
"provider",
",",
"err",
":=",
"oidc",
".",
"NewProvider",
"(",
"ctx",
",",
"c",
".",
"Issuer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cancel",
"(",
")",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"BasicAuthUnsupported",
"!=",
"nil",
"{",
"// Setting \"basicAuthUnsupported\" always overrides our detection.",
"if",
"*",
"c",
".",
"BasicAuthUnsupported",
"{",
"registerBrokenAuthHeaderProvider",
"(",
"provider",
".",
"Endpoint",
"(",
")",
".",
"TokenURL",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"knownBrokenAuthHeaderProvider",
"(",
"c",
".",
"Issuer",
")",
"{",
"registerBrokenAuthHeaderProvider",
"(",
"provider",
".",
"Endpoint",
"(",
")",
".",
"TokenURL",
")",
"\n",
"}",
"\n\n",
"scopes",
":=",
"[",
"]",
"string",
"{",
"oidc",
".",
"ScopeOpenID",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"Scopes",
")",
">",
"0",
"{",
"scopes",
"=",
"append",
"(",
"scopes",
",",
"c",
".",
"Scopes",
"...",
")",
"\n",
"}",
"else",
"{",
"scopes",
"=",
"append",
"(",
"scopes",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"clientID",
":=",
"c",
".",
"ClientID",
"\n",
"return",
"&",
"oidcConnector",
"{",
"redirectURI",
":",
"c",
".",
"RedirectURI",
",",
"oauth2Config",
":",
"&",
"oauth2",
".",
"Config",
"{",
"ClientID",
":",
"clientID",
",",
"ClientSecret",
":",
"c",
".",
"ClientSecret",
",",
"Endpoint",
":",
"provider",
".",
"Endpoint",
"(",
")",
",",
"Scopes",
":",
"scopes",
",",
"RedirectURL",
":",
"c",
".",
"RedirectURI",
",",
"}",
",",
"verifier",
":",
"provider",
".",
"Verifier",
"(",
"&",
"oidc",
".",
"Config",
"{",
"ClientID",
":",
"clientID",
"}",
",",
")",
",",
"logger",
":",
"logger",
",",
"cancel",
":",
"cancel",
",",
"hostedDomains",
":",
"c",
".",
"HostedDomains",
",",
"insecureSkipEmailVerified",
":",
"c",
".",
"InsecureSkipEmailVerified",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Open returns a connector which can be used to login users through an upstream
// OpenID Connect provider. | [
"Open",
"returns",
"a",
"connector",
"which",
"can",
"be",
"used",
"to",
"login",
"users",
"through",
"an",
"upstream",
"OpenID",
"Connect",
"provider",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/oidc/oidc.go#L81-L124 |
164,654 | dexidp/dex | connector/oidc/oidc.go | Refresh | func (c *oidcConnector) Refresh(ctx context.Context, s connector.Scopes, identity connector.Identity) (connector.Identity, error) {
return identity, nil
} | go | func (c *oidcConnector) Refresh(ctx context.Context, s connector.Scopes, identity connector.Identity) (connector.Identity, error) {
return identity, nil
} | [
"func",
"(",
"c",
"*",
"oidcConnector",
")",
"Refresh",
"(",
"ctx",
"context",
".",
"Context",
",",
"s",
"connector",
".",
"Scopes",
",",
"identity",
"connector",
".",
"Identity",
")",
"(",
"connector",
".",
"Identity",
",",
"error",
")",
"{",
"return",
"identity",
",",
"nil",
"\n",
"}"
] | // Refresh is implemented for backwards compatibility, even though it's a no-op. | [
"Refresh",
"is",
"implemented",
"for",
"backwards",
"compatibility",
"even",
"though",
"it",
"s",
"a",
"no",
"-",
"op",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/oidc/oidc.go#L232-L234 |
164,655 | dexidp/dex | connector/saml/saml.go | Open | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return c.openConnector(logger)
} | go | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return c.openConnector(logger)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"connector",
".",
"Connector",
",",
"error",
")",
"{",
"return",
"c",
".",
"openConnector",
"(",
"logger",
")",
"\n",
"}"
] | // Open validates the config and returns a connector. It does not actually
// validate connectivity with the provider. | [
"Open",
"validates",
"the",
"config",
"and",
"returns",
"a",
"connector",
".",
"It",
"does",
"not",
"actually",
"validate",
"connectivity",
"with",
"the",
"provider",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/saml/saml.go#L128-L130 |
164,656 | dexidp/dex | connector/saml/saml.go | validateStatus | func (p *provider) validateStatus(status *status) error {
// StatusCode is mandatory in the Status type
statusCode := status.StatusCode
if statusCode == nil {
return fmt.Errorf("response did not contain a StatusCode")
}
if statusCode.Value != statusCodeSuccess {
parts := strings.Split(statusCode.Value, ":")
lastPart := parts[len(parts)-1]
errorMessage := fmt.Sprintf("status code of the Response was not Success, was %q", lastPart)
statusMessage := status.StatusMessage
if statusMessage != nil && statusMessage.Value != "" {
errorMessage += " -> " + statusMessage.Value
}
return fmt.Errorf(errorMessage)
}
return nil
} | go | func (p *provider) validateStatus(status *status) error {
// StatusCode is mandatory in the Status type
statusCode := status.StatusCode
if statusCode == nil {
return fmt.Errorf("response did not contain a StatusCode")
}
if statusCode.Value != statusCodeSuccess {
parts := strings.Split(statusCode.Value, ":")
lastPart := parts[len(parts)-1]
errorMessage := fmt.Sprintf("status code of the Response was not Success, was %q", lastPart)
statusMessage := status.StatusMessage
if statusMessage != nil && statusMessage.Value != "" {
errorMessage += " -> " + statusMessage.Value
}
return fmt.Errorf(errorMessage)
}
return nil
} | [
"func",
"(",
"p",
"*",
"provider",
")",
"validateStatus",
"(",
"status",
"*",
"status",
")",
"error",
"{",
"// StatusCode is mandatory in the Status type",
"statusCode",
":=",
"status",
".",
"StatusCode",
"\n",
"if",
"statusCode",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"statusCode",
".",
"Value",
"!=",
"statusCodeSuccess",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"statusCode",
".",
"Value",
",",
"\"",
"\"",
")",
"\n",
"lastPart",
":=",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
"\n",
"errorMessage",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"lastPart",
")",
"\n",
"statusMessage",
":=",
"status",
".",
"StatusMessage",
"\n",
"if",
"statusMessage",
"!=",
"nil",
"&&",
"statusMessage",
".",
"Value",
"!=",
"\"",
"\"",
"{",
"errorMessage",
"+=",
"\"",
"\"",
"+",
"statusMessage",
".",
"Value",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"errorMessage",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // validateStatus verifies that the response has a good status code or
// formats a human readble error based on the bad status. | [
"validateStatus",
"verifies",
"that",
"the",
"response",
"has",
"a",
"good",
"status",
"code",
"or",
"formats",
"a",
"human",
"readble",
"error",
"based",
"on",
"the",
"bad",
"status",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/saml/saml.go#L415-L433 |
164,657 | dexidp/dex | connector/saml/saml.go | before | func before(now, notBefore time.Time) bool {
return now.Add(allowedClockDrift).Before(notBefore)
} | go | func before(now, notBefore time.Time) bool {
return now.Add(allowedClockDrift).Before(notBefore)
} | [
"func",
"before",
"(",
"now",
",",
"notBefore",
"time",
".",
"Time",
")",
"bool",
"{",
"return",
"now",
".",
"Add",
"(",
"allowedClockDrift",
")",
".",
"Before",
"(",
"notBefore",
")",
"\n",
"}"
] | // before determines if a given time is before the current time, with an
// allowed clock drift. | [
"before",
"determines",
"if",
"a",
"given",
"time",
"is",
"before",
"the",
"current",
"time",
"with",
"an",
"allowed",
"clock",
"drift",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/saml/saml.go#L596-L598 |
164,658 | dexidp/dex | connector/saml/saml.go | after | func after(now, notOnOrAfter time.Time) bool {
return now.After(notOnOrAfter.Add(allowedClockDrift))
} | go | func after(now, notOnOrAfter time.Time) bool {
return now.After(notOnOrAfter.Add(allowedClockDrift))
} | [
"func",
"after",
"(",
"now",
",",
"notOnOrAfter",
"time",
".",
"Time",
")",
"bool",
"{",
"return",
"now",
".",
"After",
"(",
"notOnOrAfter",
".",
"Add",
"(",
"allowedClockDrift",
")",
")",
"\n",
"}"
] | // after determines if a given time is after the current time, with an
// allowed clock drift. | [
"after",
"determines",
"if",
"a",
"given",
"time",
"is",
"after",
"the",
"current",
"time",
"with",
"an",
"allowed",
"clock",
"drift",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/saml/saml.go#L602-L604 |
164,659 | dexidp/dex | cmd/example-app/main.go | httpClientForRootCAs | func httpClientForRootCAs(rootCAs string) (*http.Client, error) {
tlsConfig := tls.Config{RootCAs: x509.NewCertPool()}
rootCABytes, err := ioutil.ReadFile(rootCAs)
if err != nil {
return nil, fmt.Errorf("failed to read root-ca: %v", err)
}
if !tlsConfig.RootCAs.AppendCertsFromPEM(rootCABytes) {
return nil, fmt.Errorf("no certs found in root CA file %q", rootCAs)
}
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}, nil
} | go | func httpClientForRootCAs(rootCAs string) (*http.Client, error) {
tlsConfig := tls.Config{RootCAs: x509.NewCertPool()}
rootCABytes, err := ioutil.ReadFile(rootCAs)
if err != nil {
return nil, fmt.Errorf("failed to read root-ca: %v", err)
}
if !tlsConfig.RootCAs.AppendCertsFromPEM(rootCABytes) {
return nil, fmt.Errorf("no certs found in root CA file %q", rootCAs)
}
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tlsConfig,
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}, nil
} | [
"func",
"httpClientForRootCAs",
"(",
"rootCAs",
"string",
")",
"(",
"*",
"http",
".",
"Client",
",",
"error",
")",
"{",
"tlsConfig",
":=",
"tls",
".",
"Config",
"{",
"RootCAs",
":",
"x509",
".",
"NewCertPool",
"(",
")",
"}",
"\n",
"rootCABytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"rootCAs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"tlsConfig",
".",
"RootCAs",
".",
"AppendCertsFromPEM",
"(",
"rootCABytes",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rootCAs",
")",
"\n",
"}",
"\n",
"return",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"&",
"tlsConfig",
",",
"Proxy",
":",
"http",
".",
"ProxyFromEnvironment",
",",
"Dial",
":",
"(",
"&",
"net",
".",
"Dialer",
"{",
"Timeout",
":",
"30",
"*",
"time",
".",
"Second",
",",
"KeepAlive",
":",
"30",
"*",
"time",
".",
"Second",
",",
"}",
")",
".",
"Dial",
",",
"TLSHandshakeTimeout",
":",
"10",
"*",
"time",
".",
"Second",
",",
"ExpectContinueTimeout",
":",
"1",
"*",
"time",
".",
"Second",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // return an HTTP client which trusts the provided root CAs. | [
"return",
"an",
"HTTP",
"client",
"which",
"trusts",
"the",
"provided",
"root",
"CAs",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/cmd/example-app/main.go#L44-L65 |
164,660 | dexidp/dex | server/oauth2.go | signatureAlgorithm | func signatureAlgorithm(jwk *jose.JSONWebKey) (alg jose.SignatureAlgorithm, err error) {
if jwk.Key == nil {
return alg, errors.New("no signing key")
}
switch key := jwk.Key.(type) {
case *rsa.PrivateKey:
// Because OIDC mandates that we support RS256, we always return that
// value. In the future, we might want to make this configurable on a
// per client basis. For example allowing PS256 or ECDSA variants.
//
// See https://github.com/dexidp/dex/issues/692
return jose.RS256, nil
case *ecdsa.PrivateKey:
// We don't actually support ECDSA keys yet, but they're tested for
// in case we want to in the future.
//
// These values are prescribed depending on the ECDSA key type. We
// can't return different values.
switch key.Params() {
case elliptic.P256().Params():
return jose.ES256, nil
case elliptic.P384().Params():
return jose.ES384, nil
case elliptic.P521().Params():
return jose.ES512, nil
default:
return alg, errors.New("unsupported ecdsa curve")
}
default:
return alg, fmt.Errorf("unsupported signing key type %T", key)
}
} | go | func signatureAlgorithm(jwk *jose.JSONWebKey) (alg jose.SignatureAlgorithm, err error) {
if jwk.Key == nil {
return alg, errors.New("no signing key")
}
switch key := jwk.Key.(type) {
case *rsa.PrivateKey:
// Because OIDC mandates that we support RS256, we always return that
// value. In the future, we might want to make this configurable on a
// per client basis. For example allowing PS256 or ECDSA variants.
//
// See https://github.com/dexidp/dex/issues/692
return jose.RS256, nil
case *ecdsa.PrivateKey:
// We don't actually support ECDSA keys yet, but they're tested for
// in case we want to in the future.
//
// These values are prescribed depending on the ECDSA key type. We
// can't return different values.
switch key.Params() {
case elliptic.P256().Params():
return jose.ES256, nil
case elliptic.P384().Params():
return jose.ES384, nil
case elliptic.P521().Params():
return jose.ES512, nil
default:
return alg, errors.New("unsupported ecdsa curve")
}
default:
return alg, fmt.Errorf("unsupported signing key type %T", key)
}
} | [
"func",
"signatureAlgorithm",
"(",
"jwk",
"*",
"jose",
".",
"JSONWebKey",
")",
"(",
"alg",
"jose",
".",
"SignatureAlgorithm",
",",
"err",
"error",
")",
"{",
"if",
"jwk",
".",
"Key",
"==",
"nil",
"{",
"return",
"alg",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"key",
":=",
"jwk",
".",
"Key",
".",
"(",
"type",
")",
"{",
"case",
"*",
"rsa",
".",
"PrivateKey",
":",
"// Because OIDC mandates that we support RS256, we always return that",
"// value. In the future, we might want to make this configurable on a",
"// per client basis. For example allowing PS256 or ECDSA variants.",
"//",
"// See https://github.com/dexidp/dex/issues/692",
"return",
"jose",
".",
"RS256",
",",
"nil",
"\n",
"case",
"*",
"ecdsa",
".",
"PrivateKey",
":",
"// We don't actually support ECDSA keys yet, but they're tested for",
"// in case we want to in the future.",
"//",
"// These values are prescribed depending on the ECDSA key type. We",
"// can't return different values.",
"switch",
"key",
".",
"Params",
"(",
")",
"{",
"case",
"elliptic",
".",
"P256",
"(",
")",
".",
"Params",
"(",
")",
":",
"return",
"jose",
".",
"ES256",
",",
"nil",
"\n",
"case",
"elliptic",
".",
"P384",
"(",
")",
".",
"Params",
"(",
")",
":",
"return",
"jose",
".",
"ES384",
",",
"nil",
"\n",
"case",
"elliptic",
".",
"P521",
"(",
")",
".",
"Params",
"(",
")",
":",
"return",
"jose",
".",
"ES512",
",",
"nil",
"\n",
"default",
":",
"return",
"alg",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"alg",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"}",
"\n",
"}"
] | // Determine the signature algorithm for a JWT. | [
"Determine",
"the",
"signature",
"algorithm",
"for",
"a",
"JWT",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/oauth2.go#L143-L174 |
164,661 | dexidp/dex | storage/kubernetes/storage.go | Open | func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
cli, err := c.open(logger, false)
if err != nil {
return nil, err
}
return cli, nil
} | go | func (c *Config) Open(logger log.Logger) (storage.Storage, error) {
cli, err := c.open(logger, false)
if err != nil {
return nil, err
}
return cli, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"logger",
"log",
".",
"Logger",
")",
"(",
"storage",
".",
"Storage",
",",
"error",
")",
"{",
"cli",
",",
"err",
":=",
"c",
".",
"open",
"(",
"logger",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"cli",
",",
"nil",
"\n",
"}"
] | // Open returns a storage using Kubernetes third party resource. | [
"Open",
"returns",
"a",
"storage",
"using",
"Kubernetes",
"third",
"party",
"resource",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/kubernetes/storage.go#L45-L51 |
164,662 | dexidp/dex | storage/kubernetes/storage.go | waitForCRDs | func (cli *client) waitForCRDs(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
for _, crd := range customResourceDefinitions {
for {
err := cli.isCRDReady(crd.Name)
if err == nil {
break
}
cli.logger.Errorf("checking CRD: %v", err)
select {
case <-ctx.Done():
return errors.New("timed out waiting for CRDs to be available")
case <-time.After(time.Millisecond * 100):
}
}
}
return nil
} | go | func (cli *client) waitForCRDs(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()
for _, crd := range customResourceDefinitions {
for {
err := cli.isCRDReady(crd.Name)
if err == nil {
break
}
cli.logger.Errorf("checking CRD: %v", err)
select {
case <-ctx.Done():
return errors.New("timed out waiting for CRDs to be available")
case <-time.After(time.Millisecond * 100):
}
}
}
return nil
} | [
"func",
"(",
"cli",
"*",
"client",
")",
"waitForCRDs",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"time",
".",
"Second",
"*",
"30",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n\n",
"for",
"_",
",",
"crd",
":=",
"range",
"customResourceDefinitions",
"{",
"for",
"{",
"err",
":=",
"cli",
".",
"isCRDReady",
"(",
"crd",
".",
"Name",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"break",
"\n",
"}",
"\n\n",
"cli",
".",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"time",
".",
"Millisecond",
"*",
"100",
")",
":",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // waitForCRDs waits for all CRDs to be in a ready state, and is used
// by the tests to synchronize before running conformance. | [
"waitForCRDs",
"waits",
"for",
"all",
"CRDs",
"to",
"be",
"in",
"a",
"ready",
"state",
"and",
"is",
"used",
"by",
"the",
"tests",
"to",
"synchronize",
"before",
"running",
"conformance",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/kubernetes/storage.go#L182-L203 |
164,663 | dexidp/dex | storage/kubernetes/storage.go | isCRDReady | func (cli *client) isCRDReady(name string) error {
var r k8sapi.CustomResourceDefinition
err := cli.getResource("apiextensions.k8s.io/v1beta1", "", "customresourcedefinitions", name, &r)
if err != nil {
return fmt.Errorf("get crd %s: %v", name, err)
}
conds := make(map[string]string) // For debugging, keep the conditions around.
for _, c := range r.Status.Conditions {
if c.Type == k8sapi.Established && c.Status == k8sapi.ConditionTrue {
return nil
}
conds[string(c.Type)] = string(c.Status)
}
return fmt.Errorf("crd %s not ready %#v", name, conds)
} | go | func (cli *client) isCRDReady(name string) error {
var r k8sapi.CustomResourceDefinition
err := cli.getResource("apiextensions.k8s.io/v1beta1", "", "customresourcedefinitions", name, &r)
if err != nil {
return fmt.Errorf("get crd %s: %v", name, err)
}
conds := make(map[string]string) // For debugging, keep the conditions around.
for _, c := range r.Status.Conditions {
if c.Type == k8sapi.Established && c.Status == k8sapi.ConditionTrue {
return nil
}
conds[string(c.Type)] = string(c.Status)
}
return fmt.Errorf("crd %s not ready %#v", name, conds)
} | [
"func",
"(",
"cli",
"*",
"client",
")",
"isCRDReady",
"(",
"name",
"string",
")",
"error",
"{",
"var",
"r",
"k8sapi",
".",
"CustomResourceDefinition",
"\n",
"err",
":=",
"cli",
".",
"getResource",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"name",
",",
"&",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"conds",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"// For debugging, keep the conditions around.",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"r",
".",
"Status",
".",
"Conditions",
"{",
"if",
"c",
".",
"Type",
"==",
"k8sapi",
".",
"Established",
"&&",
"c",
".",
"Status",
"==",
"k8sapi",
".",
"ConditionTrue",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"conds",
"[",
"string",
"(",
"c",
".",
"Type",
")",
"]",
"=",
"string",
"(",
"c",
".",
"Status",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"conds",
")",
"\n",
"}"
] | // isCRDReady determines if a CRD is ready by inspecting its conditions. | [
"isCRDReady",
"determines",
"if",
"a",
"CRD",
"is",
"ready",
"by",
"inspecting",
"its",
"conditions",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/kubernetes/storage.go#L206-L221 |
164,664 | dexidp/dex | storage/sql/crud.go | delete | func (c *conn) delete(table, field, id string) error {
result, err := c.Exec(`delete from `+table+` where `+field+` = $1`, id)
if err != nil {
return fmt.Errorf("delete %s: %v", table, id)
}
// For now mandate that the driver implements RowsAffected. If we ever need to support
// a driver that doesn't implement this, we can run this in a transaction with a get beforehand.
n, err := result.RowsAffected()
if err != nil {
return fmt.Errorf("rows affected: %v", err)
}
if n < 1 {
return storage.ErrNotFound
}
return nil
} | go | func (c *conn) delete(table, field, id string) error {
result, err := c.Exec(`delete from `+table+` where `+field+` = $1`, id)
if err != nil {
return fmt.Errorf("delete %s: %v", table, id)
}
// For now mandate that the driver implements RowsAffected. If we ever need to support
// a driver that doesn't implement this, we can run this in a transaction with a get beforehand.
n, err := result.RowsAffected()
if err != nil {
return fmt.Errorf("rows affected: %v", err)
}
if n < 1 {
return storage.ErrNotFound
}
return nil
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"delete",
"(",
"table",
",",
"field",
",",
"id",
"string",
")",
"error",
"{",
"result",
",",
"err",
":=",
"c",
".",
"Exec",
"(",
"`delete from `",
"+",
"table",
"+",
"` where `",
"+",
"field",
"+",
"` = $1`",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"table",
",",
"id",
")",
"\n",
"}",
"\n\n",
"// For now mandate that the driver implements RowsAffected. If we ever need to support",
"// a driver that doesn't implement this, we can run this in a transaction with a get beforehand.",
"n",
",",
"err",
":=",
"result",
".",
"RowsAffected",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"n",
"<",
"1",
"{",
"return",
"storage",
".",
"ErrNotFound",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Do NOT call directly. Does not escape table. | [
"Do",
"NOT",
"call",
"directly",
".",
"Does",
"not",
"escape",
"table",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/sql/crud.go#L846-L862 |
164,665 | dexidp/dex | storage/etcd/config.go | Open | func (p *Etcd) Open(logger log.Logger) (storage.Storage, error) {
return p.open(logger)
} | go | func (p *Etcd) Open(logger log.Logger) (storage.Storage, error) {
return p.open(logger)
} | [
"func",
"(",
"p",
"*",
"Etcd",
")",
"Open",
"(",
"logger",
"log",
".",
"Logger",
")",
"(",
"storage",
".",
"Storage",
",",
"error",
")",
"{",
"return",
"p",
".",
"open",
"(",
"logger",
")",
"\n",
"}"
] | // Open creates a new storage implementation backed by Etcd | [
"Open",
"creates",
"a",
"new",
"storage",
"implementation",
"backed",
"by",
"Etcd"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/etcd/config.go#L39-L41 |
164,666 | dexidp/dex | connector/gitlab/gitlab.go | Open | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
if c.BaseURL == "" {
c.BaseURL = "https://gitlab.com"
}
return &gitlabConnector{
baseURL: c.BaseURL,
redirectURI: c.RedirectURI,
clientID: c.ClientID,
clientSecret: c.ClientSecret,
logger: logger,
}, nil
} | go | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
if c.BaseURL == "" {
c.BaseURL = "https://gitlab.com"
}
return &gitlabConnector{
baseURL: c.BaseURL,
redirectURI: c.RedirectURI,
clientID: c.ClientID,
clientSecret: c.ClientSecret,
logger: logger,
}, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"connector",
".",
"Connector",
",",
"error",
")",
"{",
"if",
"c",
".",
"BaseURL",
"==",
"\"",
"\"",
"{",
"c",
".",
"BaseURL",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"&",
"gitlabConnector",
"{",
"baseURL",
":",
"c",
".",
"BaseURL",
",",
"redirectURI",
":",
"c",
".",
"RedirectURI",
",",
"clientID",
":",
"c",
".",
"ClientID",
",",
"clientSecret",
":",
"c",
".",
"ClientSecret",
",",
"logger",
":",
"logger",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Open returns a strategy for logging in through GitLab. | [
"Open",
"returns",
"a",
"strategy",
"for",
"logging",
"in",
"through",
"GitLab",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/gitlab/gitlab.go#L45-L56 |
164,667 | dexidp/dex | connector/authproxy/authproxy.go | Open | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &callback{logger: logger, pathSuffix: "/" + id}, nil
} | go | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &callback{logger: logger, pathSuffix: "/" + id}, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"connector",
".",
"Connector",
",",
"error",
")",
"{",
"return",
"&",
"callback",
"{",
"logger",
":",
"logger",
",",
"pathSuffix",
":",
"\"",
"\"",
"+",
"id",
"}",
",",
"nil",
"\n",
"}"
] | // Open returns an authentication strategy which requires no user interaction. | [
"Open",
"returns",
"an",
"authentication",
"strategy",
"which",
"requires",
"no",
"user",
"interaction",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/authproxy/authproxy.go#L20-L22 |
164,668 | dexidp/dex | connector/authproxy/authproxy.go | LoginURL | func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (string, error) {
u, err := url.Parse(callbackURL)
if err != nil {
return "", fmt.Errorf("failed to parse callbackURL %q: %v", callbackURL, err)
}
u.Path = u.Path + m.pathSuffix
v := u.Query()
v.Set("state", state)
u.RawQuery = v.Encode()
return u.String(), nil
} | go | func (m *callback) LoginURL(s connector.Scopes, callbackURL, state string) (string, error) {
u, err := url.Parse(callbackURL)
if err != nil {
return "", fmt.Errorf("failed to parse callbackURL %q: %v", callbackURL, err)
}
u.Path = u.Path + m.pathSuffix
v := u.Query()
v.Set("state", state)
u.RawQuery = v.Encode()
return u.String(), nil
} | [
"func",
"(",
"m",
"*",
"callback",
")",
"LoginURL",
"(",
"s",
"connector",
".",
"Scopes",
",",
"callbackURL",
",",
"state",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"callbackURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"callbackURL",
",",
"err",
")",
"\n",
"}",
"\n",
"u",
".",
"Path",
"=",
"u",
".",
"Path",
"+",
"m",
".",
"pathSuffix",
"\n",
"v",
":=",
"u",
".",
"Query",
"(",
")",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"state",
")",
"\n",
"u",
".",
"RawQuery",
"=",
"v",
".",
"Encode",
"(",
")",
"\n",
"return",
"u",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] | // LoginURL returns the URL to redirect the user to login with. | [
"LoginURL",
"returns",
"the",
"URL",
"to",
"redirect",
"the",
"user",
"to",
"login",
"with",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/authproxy/authproxy.go#L32-L42 |
164,669 | dexidp/dex | connector/authproxy/authproxy.go | HandleCallback | func (m *callback) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) {
remoteUser := r.Header.Get("X-Remote-User")
if remoteUser == "" {
return connector.Identity{}, fmt.Errorf("required HTTP header X-Remote-User is not set")
}
// TODO: add support for X-Remote-Group, see
// https://kubernetes.io/docs/admin/authentication/#authenticating-proxy
return connector.Identity{
UserID: remoteUser, // TODO: figure out if this is a bad ID value.
Email: remoteUser,
EmailVerified: true,
}, nil
} | go | func (m *callback) HandleCallback(s connector.Scopes, r *http.Request) (connector.Identity, error) {
remoteUser := r.Header.Get("X-Remote-User")
if remoteUser == "" {
return connector.Identity{}, fmt.Errorf("required HTTP header X-Remote-User is not set")
}
// TODO: add support for X-Remote-Group, see
// https://kubernetes.io/docs/admin/authentication/#authenticating-proxy
return connector.Identity{
UserID: remoteUser, // TODO: figure out if this is a bad ID value.
Email: remoteUser,
EmailVerified: true,
}, nil
} | [
"func",
"(",
"m",
"*",
"callback",
")",
"HandleCallback",
"(",
"s",
"connector",
".",
"Scopes",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"connector",
".",
"Identity",
",",
"error",
")",
"{",
"remoteUser",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"remoteUser",
"==",
"\"",
"\"",
"{",
"return",
"connector",
".",
"Identity",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// TODO: add support for X-Remote-Group, see",
"// https://kubernetes.io/docs/admin/authentication/#authenticating-proxy",
"return",
"connector",
".",
"Identity",
"{",
"UserID",
":",
"remoteUser",
",",
"// TODO: figure out if this is a bad ID value.",
"Email",
":",
"remoteUser",
",",
"EmailVerified",
":",
"true",
",",
"}",
",",
"nil",
"\n",
"}"
] | // HandleCallback parses the request and returns the user's identity | [
"HandleCallback",
"parses",
"the",
"request",
"and",
"returns",
"the",
"user",
"s",
"identity"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/authproxy/authproxy.go#L45-L57 |
164,670 | dexidp/dex | server/templates.go | loadTemplates | func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
files, err := ioutil.ReadDir(templatesDir)
if err != nil {
return nil, fmt.Errorf("read dir: %v", err)
}
filenames := []string{}
for _, file := range files {
if file.IsDir() {
continue
}
filenames = append(filenames, filepath.Join(templatesDir, file.Name()))
}
if len(filenames) == 0 {
return nil, fmt.Errorf("no files in template dir %q", templatesDir)
}
funcs := map[string]interface{}{
"issuer": func() string { return c.issuer },
"logo": func() string { return c.logoURL },
"url": func(s string) string { return join(c.issuerURL, s) },
"lower": strings.ToLower,
}
tmpls, err := template.New("").Funcs(funcs).ParseFiles(filenames...)
if err != nil {
return nil, fmt.Errorf("parse files: %v", err)
}
missingTmpls := []string{}
for _, tmplName := range requiredTmpls {
if tmpls.Lookup(tmplName) == nil {
missingTmpls = append(missingTmpls, tmplName)
}
}
if len(missingTmpls) > 0 {
return nil, fmt.Errorf("missing template(s): %s", missingTmpls)
}
return &templates{
loginTmpl: tmpls.Lookup(tmplLogin),
approvalTmpl: tmpls.Lookup(tmplApproval),
passwordTmpl: tmpls.Lookup(tmplPassword),
oobTmpl: tmpls.Lookup(tmplOOB),
errorTmpl: tmpls.Lookup(tmplError),
}, nil
} | go | func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
files, err := ioutil.ReadDir(templatesDir)
if err != nil {
return nil, fmt.Errorf("read dir: %v", err)
}
filenames := []string{}
for _, file := range files {
if file.IsDir() {
continue
}
filenames = append(filenames, filepath.Join(templatesDir, file.Name()))
}
if len(filenames) == 0 {
return nil, fmt.Errorf("no files in template dir %q", templatesDir)
}
funcs := map[string]interface{}{
"issuer": func() string { return c.issuer },
"logo": func() string { return c.logoURL },
"url": func(s string) string { return join(c.issuerURL, s) },
"lower": strings.ToLower,
}
tmpls, err := template.New("").Funcs(funcs).ParseFiles(filenames...)
if err != nil {
return nil, fmt.Errorf("parse files: %v", err)
}
missingTmpls := []string{}
for _, tmplName := range requiredTmpls {
if tmpls.Lookup(tmplName) == nil {
missingTmpls = append(missingTmpls, tmplName)
}
}
if len(missingTmpls) > 0 {
return nil, fmt.Errorf("missing template(s): %s", missingTmpls)
}
return &templates{
loginTmpl: tmpls.Lookup(tmplLogin),
approvalTmpl: tmpls.Lookup(tmplApproval),
passwordTmpl: tmpls.Lookup(tmplPassword),
oobTmpl: tmpls.Lookup(tmplOOB),
errorTmpl: tmpls.Lookup(tmplError),
}, nil
} | [
"func",
"loadTemplates",
"(",
"c",
"webConfig",
",",
"templatesDir",
"string",
")",
"(",
"*",
"templates",
",",
"error",
")",
"{",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"templatesDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"filenames",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"file",
":=",
"range",
"files",
"{",
"if",
"file",
".",
"IsDir",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"filenames",
"=",
"append",
"(",
"filenames",
",",
"filepath",
".",
"Join",
"(",
"templatesDir",
",",
"file",
".",
"Name",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"filenames",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"templatesDir",
")",
"\n",
"}",
"\n\n",
"funcs",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"func",
"(",
")",
"string",
"{",
"return",
"c",
".",
"issuer",
"}",
",",
"\"",
"\"",
":",
"func",
"(",
")",
"string",
"{",
"return",
"c",
".",
"logoURL",
"}",
",",
"\"",
"\"",
":",
"func",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"join",
"(",
"c",
".",
"issuerURL",
",",
"s",
")",
"}",
",",
"\"",
"\"",
":",
"strings",
".",
"ToLower",
",",
"}",
"\n\n",
"tmpls",
",",
"err",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Funcs",
"(",
"funcs",
")",
".",
"ParseFiles",
"(",
"filenames",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"missingTmpls",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"tmplName",
":=",
"range",
"requiredTmpls",
"{",
"if",
"tmpls",
".",
"Lookup",
"(",
"tmplName",
")",
"==",
"nil",
"{",
"missingTmpls",
"=",
"append",
"(",
"missingTmpls",
",",
"tmplName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"missingTmpls",
")",
">",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"missingTmpls",
")",
"\n",
"}",
"\n",
"return",
"&",
"templates",
"{",
"loginTmpl",
":",
"tmpls",
".",
"Lookup",
"(",
"tmplLogin",
")",
",",
"approvalTmpl",
":",
"tmpls",
".",
"Lookup",
"(",
"tmplApproval",
")",
",",
"passwordTmpl",
":",
"tmpls",
".",
"Lookup",
"(",
"tmplPassword",
")",
",",
"oobTmpl",
":",
"tmpls",
".",
"Lookup",
"(",
"tmplOOB",
")",
",",
"errorTmpl",
":",
"tmpls",
".",
"Lookup",
"(",
"tmplError",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // loadTemplates parses the expected templates from the provided directory. | [
"loadTemplates",
"parses",
"the",
"expected",
"templates",
"from",
"the",
"provided",
"directory",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/templates.go#L121-L165 |
164,671 | dexidp/dex | storage/kubernetes/client.go | idToName | func (c *client) idToName(s string) string {
return idToName(s, c.hash)
} | go | func (c *client) idToName(s string) string {
return idToName(s, c.hash)
} | [
"func",
"(",
"c",
"*",
"client",
")",
"idToName",
"(",
"s",
"string",
")",
"string",
"{",
"return",
"idToName",
"(",
"s",
",",
"c",
".",
"hash",
")",
"\n",
"}"
] | // idToName maps an arbitrary ID, such as an email or client ID to a Kubernetes object name. | [
"idToName",
"maps",
"an",
"arbitrary",
"ID",
"such",
"as",
"an",
"email",
"or",
"client",
"ID",
"to",
"a",
"Kubernetes",
"object",
"name",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/kubernetes/client.go#L58-L60 |
164,672 | dexidp/dex | storage/kubernetes/client.go | offlineTokenName | func (c *client) offlineTokenName(userID string, connID string) string {
return offlineTokenName(userID, connID, c.hash)
} | go | func (c *client) offlineTokenName(userID string, connID string) string {
return offlineTokenName(userID, connID, c.hash)
} | [
"func",
"(",
"c",
"*",
"client",
")",
"offlineTokenName",
"(",
"userID",
"string",
",",
"connID",
"string",
")",
"string",
"{",
"return",
"offlineTokenName",
"(",
"userID",
",",
"connID",
",",
"c",
".",
"hash",
")",
"\n",
"}"
] | // offlineTokenName maps two arbitrary IDs, to a single Kubernetes object name.
// This is used when more than one field is used to uniquely identify the object. | [
"offlineTokenName",
"maps",
"two",
"arbitrary",
"IDs",
"to",
"a",
"single",
"Kubernetes",
"object",
"name",
".",
"This",
"is",
"used",
"when",
"more",
"than",
"one",
"field",
"is",
"used",
"to",
"uniquely",
"identify",
"the",
"object",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/kubernetes/client.go#L64-L66 |
164,673 | dexidp/dex | storage/kubernetes/client.go | closeResp | func closeResp(r *http.Response) {
io.Copy(ioutil.Discard, r.Body)
r.Body.Close()
} | go | func closeResp(r *http.Response) {
io.Copy(ioutil.Discard, r.Body)
r.Body.Close()
} | [
"func",
"closeResp",
"(",
"r",
"*",
"http",
".",
"Response",
")",
"{",
"io",
".",
"Copy",
"(",
"ioutil",
".",
"Discard",
",",
"r",
".",
"Body",
")",
"\n",
"r",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close the response body. The initial request is drained so the connection can
// be reused. | [
"Close",
"the",
"response",
"body",
".",
"The",
"initial",
"request",
"is",
"drained",
"so",
"the",
"connection",
"can",
"be",
"reused",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/kubernetes/client.go#L154-L157 |
164,674 | dexidp/dex | storage/sql/sql.go | translateArgs | func (c *conn) translateArgs(args []interface{}) []interface{} {
if c.flavor.supportsTimezones {
return args
}
for i, arg := range args {
if t, ok := arg.(time.Time); ok {
args[i] = t.UTC()
}
}
return args
} | go | func (c *conn) translateArgs(args []interface{}) []interface{} {
if c.flavor.supportsTimezones {
return args
}
for i, arg := range args {
if t, ok := arg.(time.Time); ok {
args[i] = t.UTC()
}
}
return args
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"translateArgs",
"(",
"args",
"[",
"]",
"interface",
"{",
"}",
")",
"[",
"]",
"interface",
"{",
"}",
"{",
"if",
"c",
".",
"flavor",
".",
"supportsTimezones",
"{",
"return",
"args",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"t",
",",
"ok",
":=",
"arg",
".",
"(",
"time",
".",
"Time",
")",
";",
"ok",
"{",
"args",
"[",
"i",
"]",
"=",
"t",
".",
"UTC",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"args",
"\n",
"}"
] | // translateArgs translates query parameters that may be unique to
// a specific SQL flavor. For example, standardizing "time.Time"
// types to UTC for clients that don't provide timezone support. | [
"translateArgs",
"translates",
"query",
"parameters",
"that",
"may",
"be",
"unique",
"to",
"a",
"specific",
"SQL",
"flavor",
".",
"For",
"example",
"standardizing",
"time",
".",
"Time",
"types",
"to",
"UTC",
"for",
"clients",
"that",
"don",
"t",
"provide",
"timezone",
"support",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/sql/sql.go#L99-L110 |
164,675 | dexidp/dex | storage/sql/sql.go | ExecTx | func (c *conn) ExecTx(fn func(tx *trans) error) error {
if c.flavor.executeTx != nil {
return c.flavor.executeTx(c.db, func(sqlTx *sql.Tx) error {
return fn(&trans{sqlTx, c})
})
}
sqlTx, err := c.db.Begin()
if err != nil {
return err
}
if err := fn(&trans{sqlTx, c}); err != nil {
sqlTx.Rollback()
return err
}
return sqlTx.Commit()
} | go | func (c *conn) ExecTx(fn func(tx *trans) error) error {
if c.flavor.executeTx != nil {
return c.flavor.executeTx(c.db, func(sqlTx *sql.Tx) error {
return fn(&trans{sqlTx, c})
})
}
sqlTx, err := c.db.Begin()
if err != nil {
return err
}
if err := fn(&trans{sqlTx, c}); err != nil {
sqlTx.Rollback()
return err
}
return sqlTx.Commit()
} | [
"func",
"(",
"c",
"*",
"conn",
")",
"ExecTx",
"(",
"fn",
"func",
"(",
"tx",
"*",
"trans",
")",
"error",
")",
"error",
"{",
"if",
"c",
".",
"flavor",
".",
"executeTx",
"!=",
"nil",
"{",
"return",
"c",
".",
"flavor",
".",
"executeTx",
"(",
"c",
".",
"db",
",",
"func",
"(",
"sqlTx",
"*",
"sql",
".",
"Tx",
")",
"error",
"{",
"return",
"fn",
"(",
"&",
"trans",
"{",
"sqlTx",
",",
"c",
"}",
")",
"\n",
"}",
")",
"\n",
"}",
"\n\n",
"sqlTx",
",",
"err",
":=",
"c",
".",
"db",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"fn",
"(",
"&",
"trans",
"{",
"sqlTx",
",",
"c",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"sqlTx",
".",
"Rollback",
"(",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"return",
"sqlTx",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // ExecTx runs a method which operates on a transaction. | [
"ExecTx",
"runs",
"a",
"method",
"which",
"operates",
"on",
"a",
"transaction",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/sql/sql.go#L142-L158 |
164,676 | dexidp/dex | server/internal/codec.go | Marshal | func Marshal(message proto.Message) (string, error) {
data, err := proto.Marshal(message)
if err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(data), nil
} | go | func Marshal(message proto.Message) (string, error) {
data, err := proto.Marshal(message)
if err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(data), nil
} | [
"func",
"Marshal",
"(",
"message",
"proto",
".",
"Message",
")",
"(",
"string",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"proto",
".",
"Marshal",
"(",
"message",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"base64",
".",
"RawURLEncoding",
".",
"EncodeToString",
"(",
"data",
")",
",",
"nil",
"\n",
"}"
] | // Marshal converts a protobuf message to a URL legal string. | [
"Marshal",
"converts",
"a",
"protobuf",
"message",
"to",
"a",
"URL",
"legal",
"string",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/internal/codec.go#L10-L16 |
164,677 | dexidp/dex | server/internal/codec.go | Unmarshal | func Unmarshal(s string, message proto.Message) error {
data, err := base64.RawURLEncoding.DecodeString(s)
if err != nil {
return err
}
return proto.Unmarshal(data, message)
} | go | func Unmarshal(s string, message proto.Message) error {
data, err := base64.RawURLEncoding.DecodeString(s)
if err != nil {
return err
}
return proto.Unmarshal(data, message)
} | [
"func",
"Unmarshal",
"(",
"s",
"string",
",",
"message",
"proto",
".",
"Message",
")",
"error",
"{",
"data",
",",
"err",
":=",
"base64",
".",
"RawURLEncoding",
".",
"DecodeString",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"proto",
".",
"Unmarshal",
"(",
"data",
",",
"message",
")",
"\n",
"}"
] | // Unmarshal decodes a protobuf message. | [
"Unmarshal",
"decodes",
"a",
"protobuf",
"message",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/internal/codec.go#L19-L25 |
164,678 | dexidp/dex | storage/storage.go | NewID | func NewID() string {
buff := make([]byte, 16) // 128 bit random ID.
if _, err := io.ReadFull(rand.Reader, buff); err != nil {
panic(err)
}
// Avoid the identifier to begin with number and trim padding
return string(buff[0]%26+'a') + strings.TrimRight(encoding.EncodeToString(buff[1:]), "=")
} | go | func NewID() string {
buff := make([]byte, 16) // 128 bit random ID.
if _, err := io.ReadFull(rand.Reader, buff); err != nil {
panic(err)
}
// Avoid the identifier to begin with number and trim padding
return string(buff[0]%26+'a') + strings.TrimRight(encoding.EncodeToString(buff[1:]), "=")
} | [
"func",
"NewID",
"(",
")",
"string",
"{",
"buff",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"16",
")",
"// 128 bit random ID.",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"ReadFull",
"(",
"rand",
".",
"Reader",
",",
"buff",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"// Avoid the identifier to begin with number and trim padding",
"return",
"string",
"(",
"buff",
"[",
"0",
"]",
"%",
"26",
"+",
"'a'",
")",
"+",
"strings",
".",
"TrimRight",
"(",
"encoding",
".",
"EncodeToString",
"(",
"buff",
"[",
"1",
":",
"]",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // NewID returns a random string which can be used as an ID for objects. | [
"NewID",
"returns",
"a",
"random",
"string",
"which",
"can",
"be",
"used",
"as",
"an",
"ID",
"for",
"objects",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/storage.go#L28-L35 |
164,679 | dexidp/dex | storage/sql/config.go | Open | func (s *SQLite3) Open(logger log.Logger) (storage.Storage, error) {
conn, err := s.open(logger)
if err != nil {
return nil, err
}
return conn, nil
} | go | func (s *SQLite3) Open(logger log.Logger) (storage.Storage, error) {
conn, err := s.open(logger)
if err != nil {
return nil, err
}
return conn, nil
} | [
"func",
"(",
"s",
"*",
"SQLite3",
")",
"Open",
"(",
"logger",
"log",
".",
"Logger",
")",
"(",
"storage",
".",
"Storage",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"s",
".",
"open",
"(",
"logger",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"conn",
",",
"nil",
"\n",
"}"
] | // Open creates a new storage implementation backed by SQLite3 | [
"Open",
"creates",
"a",
"new",
"storage",
"implementation",
"backed",
"by",
"SQLite3"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/sql/config.go#L31-L37 |
164,680 | dexidp/dex | storage/sql/config.go | Open | func (p *Postgres) Open(logger log.Logger) (storage.Storage, error) {
conn, err := p.open(logger, p.createDataSourceName())
if err != nil {
return nil, err
}
return conn, nil
} | go | func (p *Postgres) Open(logger log.Logger) (storage.Storage, error) {
conn, err := p.open(logger, p.createDataSourceName())
if err != nil {
return nil, err
}
return conn, nil
} | [
"func",
"(",
"p",
"*",
"Postgres",
")",
"Open",
"(",
"logger",
"log",
".",
"Logger",
")",
"(",
"storage",
".",
"Storage",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"p",
".",
"open",
"(",
"logger",
",",
"p",
".",
"createDataSourceName",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"conn",
",",
"nil",
"\n",
"}"
] | // Open creates a new storage implementation backed by Postgres. | [
"Open",
"creates",
"a",
"new",
"storage",
"implementation",
"backed",
"by",
"Postgres",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/sql/config.go#L102-L108 |
164,681 | dexidp/dex | cmd/dex/config.go | UnmarshalJSON | func (s *Storage) UnmarshalJSON(b []byte) error {
var store struct {
Type string `json:"type"`
Config json.RawMessage `json:"config"`
}
if err := json.Unmarshal(b, &store); err != nil {
return fmt.Errorf("parse storage: %v", err)
}
f, ok := storages[store.Type]
if !ok {
return fmt.Errorf("unknown storage type %q", store.Type)
}
storageConfig := f()
if len(store.Config) != 0 {
data := []byte(os.ExpandEnv(string(store.Config)))
if err := json.Unmarshal(data, storageConfig); err != nil {
return fmt.Errorf("parse storage config: %v", err)
}
}
*s = Storage{
Type: store.Type,
Config: storageConfig,
}
return nil
} | go | func (s *Storage) UnmarshalJSON(b []byte) error {
var store struct {
Type string `json:"type"`
Config json.RawMessage `json:"config"`
}
if err := json.Unmarshal(b, &store); err != nil {
return fmt.Errorf("parse storage: %v", err)
}
f, ok := storages[store.Type]
if !ok {
return fmt.Errorf("unknown storage type %q", store.Type)
}
storageConfig := f()
if len(store.Config) != 0 {
data := []byte(os.ExpandEnv(string(store.Config)))
if err := json.Unmarshal(data, storageConfig); err != nil {
return fmt.Errorf("parse storage config: %v", err)
}
}
*s = Storage{
Type: store.Type,
Config: storageConfig,
}
return nil
} | [
"func",
"(",
"s",
"*",
"Storage",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"store",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"Config",
"json",
".",
"RawMessage",
"`json:\"config\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"store",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"f",
",",
"ok",
":=",
"storages",
"[",
"store",
".",
"Type",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"store",
".",
"Type",
")",
"\n",
"}",
"\n\n",
"storageConfig",
":=",
"f",
"(",
")",
"\n",
"if",
"len",
"(",
"store",
".",
"Config",
")",
"!=",
"0",
"{",
"data",
":=",
"[",
"]",
"byte",
"(",
"os",
".",
"ExpandEnv",
"(",
"string",
"(",
"store",
".",
"Config",
")",
")",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"storageConfig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"*",
"s",
"=",
"Storage",
"{",
"Type",
":",
"store",
".",
"Type",
",",
"Config",
":",
"storageConfig",
",",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON allows Storage to implement the unmarshaler interface to
// dynamically determine the type of the storage config. | [
"UnmarshalJSON",
"allows",
"Storage",
"to",
"implement",
"the",
"unmarshaler",
"interface",
"to",
"dynamically",
"determine",
"the",
"type",
"of",
"the",
"storage",
"config",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/cmd/dex/config.go#L143-L168 |
164,682 | dexidp/dex | cmd/dex/config.go | UnmarshalJSON | func (c *Connector) UnmarshalJSON(b []byte) error {
var conn struct {
Type string `json:"type"`
Name string `json:"name"`
ID string `json:"id"`
Config json.RawMessage `json:"config"`
}
if err := json.Unmarshal(b, &conn); err != nil {
return fmt.Errorf("parse connector: %v", err)
}
f, ok := server.ConnectorsConfig[conn.Type]
if !ok {
return fmt.Errorf("unknown connector type %q", conn.Type)
}
connConfig := f()
if len(conn.Config) != 0 {
data := []byte(os.ExpandEnv(string(conn.Config)))
if err := json.Unmarshal(data, connConfig); err != nil {
return fmt.Errorf("parse connector config: %v", err)
}
}
*c = Connector{
Type: conn.Type,
Name: conn.Name,
ID: conn.ID,
Config: connConfig,
}
return nil
} | go | func (c *Connector) UnmarshalJSON(b []byte) error {
var conn struct {
Type string `json:"type"`
Name string `json:"name"`
ID string `json:"id"`
Config json.RawMessage `json:"config"`
}
if err := json.Unmarshal(b, &conn); err != nil {
return fmt.Errorf("parse connector: %v", err)
}
f, ok := server.ConnectorsConfig[conn.Type]
if !ok {
return fmt.Errorf("unknown connector type %q", conn.Type)
}
connConfig := f()
if len(conn.Config) != 0 {
data := []byte(os.ExpandEnv(string(conn.Config)))
if err := json.Unmarshal(data, connConfig); err != nil {
return fmt.Errorf("parse connector config: %v", err)
}
}
*c = Connector{
Type: conn.Type,
Name: conn.Name,
ID: conn.ID,
Config: connConfig,
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connector",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"conn",
"struct",
"{",
"Type",
"string",
"`json:\"type\"`",
"\n",
"Name",
"string",
"`json:\"name\"`",
"\n",
"ID",
"string",
"`json:\"id\"`",
"\n\n",
"Config",
"json",
".",
"RawMessage",
"`json:\"config\"`",
"\n",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"&",
"conn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"f",
",",
"ok",
":=",
"server",
".",
"ConnectorsConfig",
"[",
"conn",
".",
"Type",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"conn",
".",
"Type",
")",
"\n",
"}",
"\n\n",
"connConfig",
":=",
"f",
"(",
")",
"\n",
"if",
"len",
"(",
"conn",
".",
"Config",
")",
"!=",
"0",
"{",
"data",
":=",
"[",
"]",
"byte",
"(",
"os",
".",
"ExpandEnv",
"(",
"string",
"(",
"conn",
".",
"Config",
")",
")",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"connConfig",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"*",
"c",
"=",
"Connector",
"{",
"Type",
":",
"conn",
".",
"Type",
",",
"Name",
":",
"conn",
".",
"Name",
",",
"ID",
":",
"conn",
".",
"ID",
",",
"Config",
":",
"connConfig",
",",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalJSON allows Connector to implement the unmarshaler interface to
// dynamically determine the type of the connector config. | [
"UnmarshalJSON",
"allows",
"Connector",
"to",
"implement",
"the",
"unmarshaler",
"interface",
"to",
"dynamically",
"determine",
"the",
"type",
"of",
"the",
"connector",
"config",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/cmd/dex/config.go#L182-L212 |
164,683 | dexidp/dex | cmd/dex/config.go | ToStorageConnector | func ToStorageConnector(c Connector) (storage.Connector, error) {
data, err := json.Marshal(c.Config)
if err != nil {
return storage.Connector{}, fmt.Errorf("failed to marshal connector config: %v", err)
}
return storage.Connector{
ID: c.ID,
Type: c.Type,
Name: c.Name,
Config: data,
}, nil
} | go | func ToStorageConnector(c Connector) (storage.Connector, error) {
data, err := json.Marshal(c.Config)
if err != nil {
return storage.Connector{}, fmt.Errorf("failed to marshal connector config: %v", err)
}
return storage.Connector{
ID: c.ID,
Type: c.Type,
Name: c.Name,
Config: data,
}, nil
} | [
"func",
"ToStorageConnector",
"(",
"c",
"Connector",
")",
"(",
"storage",
".",
"Connector",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"c",
".",
"Config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"storage",
".",
"Connector",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"storage",
".",
"Connector",
"{",
"ID",
":",
"c",
".",
"ID",
",",
"Type",
":",
"c",
".",
"Type",
",",
"Name",
":",
"c",
".",
"Name",
",",
"Config",
":",
"data",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ToStorageConnector converts an object to storage connector type. | [
"ToStorageConnector",
"converts",
"an",
"object",
"to",
"storage",
"connector",
"type",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/cmd/dex/config.go#L215-L227 |
164,684 | dexidp/dex | connector/saml/types.go | names | func (a *attributeStatement) names() []string {
s := make([]string, len(a.Attributes))
for i, attr := range a.Attributes {
s[i] = attr.Name
}
return s
} | go | func (a *attributeStatement) names() []string {
s := make([]string, len(a.Attributes))
for i, attr := range a.Attributes {
s[i] = attr.Name
}
return s
} | [
"func",
"(",
"a",
"*",
"attributeStatement",
")",
"names",
"(",
")",
"[",
"]",
"string",
"{",
"s",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"a",
".",
"Attributes",
")",
")",
"\n\n",
"for",
"i",
",",
"attr",
":=",
"range",
"a",
".",
"Attributes",
"{",
"s",
"[",
"i",
"]",
"=",
"attr",
".",
"Name",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // names list the names of all attributes in the attribute statement. | [
"names",
"list",
"the",
"names",
"of",
"all",
"attributes",
"in",
"the",
"attribute",
"statement",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/saml/types.go#L228-L235 |
164,685 | dexidp/dex | connector/saml/types.go | String | func (a *attributeStatement) String() string {
buff := new(bytes.Buffer)
for i, attr := range a.Attributes {
if i != 0 {
buff.WriteString(", ")
}
buff.WriteString(attr.String())
}
return buff.String()
} | go | func (a *attributeStatement) String() string {
buff := new(bytes.Buffer)
for i, attr := range a.Attributes {
if i != 0 {
buff.WriteString(", ")
}
buff.WriteString(attr.String())
}
return buff.String()
} | [
"func",
"(",
"a",
"*",
"attributeStatement",
")",
"String",
"(",
")",
"string",
"{",
"buff",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"for",
"i",
",",
"attr",
":=",
"range",
"a",
".",
"Attributes",
"{",
"if",
"i",
"!=",
"0",
"{",
"buff",
".",
"WriteString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"buff",
".",
"WriteString",
"(",
"attr",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"buff",
".",
"String",
"(",
")",
"\n",
"}"
] | // String is a formatter for logging an attribute statement's sub statements. | [
"String",
"is",
"a",
"formatter",
"for",
"logging",
"an",
"attribute",
"statement",
"s",
"sub",
"statements",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/saml/types.go#L238-L247 |
164,686 | dexidp/dex | connector/microsoft/microsoft.go | Open | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
m := microsoftConnector{
redirectURI: c.RedirectURI,
clientID: c.ClientID,
clientSecret: c.ClientSecret,
tenant: c.Tenant,
onlySecurityGroups: c.OnlySecurityGroups,
groups: c.Groups,
logger: logger,
}
// By default allow logins from both personal and business/school
// accounts.
if m.tenant == "" {
m.tenant = "common"
}
return &m, nil
} | go | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
m := microsoftConnector{
redirectURI: c.RedirectURI,
clientID: c.ClientID,
clientSecret: c.ClientSecret,
tenant: c.Tenant,
onlySecurityGroups: c.OnlySecurityGroups,
groups: c.Groups,
logger: logger,
}
// By default allow logins from both personal and business/school
// accounts.
if m.tenant == "" {
m.tenant = "common"
}
return &m, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"connector",
".",
"Connector",
",",
"error",
")",
"{",
"m",
":=",
"microsoftConnector",
"{",
"redirectURI",
":",
"c",
".",
"RedirectURI",
",",
"clientID",
":",
"c",
".",
"ClientID",
",",
"clientSecret",
":",
"c",
".",
"ClientSecret",
",",
"tenant",
":",
"c",
".",
"Tenant",
",",
"onlySecurityGroups",
":",
"c",
".",
"OnlySecurityGroups",
",",
"groups",
":",
"c",
".",
"Groups",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"// By default allow logins from both personal and business/school",
"// accounts.",
"if",
"m",
".",
"tenant",
"==",
"\"",
"\"",
"{",
"m",
".",
"tenant",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"&",
"m",
",",
"nil",
"\n",
"}"
] | // Open returns a strategy for logging in through Microsoft. | [
"Open",
"returns",
"a",
"strategy",
"for",
"logging",
"in",
"through",
"Microsoft",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/microsoft/microsoft.go#L41-L58 |
164,687 | dexidp/dex | server/api.go | NewAPI | func NewAPI(s storage.Storage, logger log.Logger) api.DexServer {
return dexAPI{
s: s,
logger: logger,
}
} | go | func NewAPI(s storage.Storage, logger log.Logger) api.DexServer {
return dexAPI{
s: s,
logger: logger,
}
} | [
"func",
"NewAPI",
"(",
"s",
"storage",
".",
"Storage",
",",
"logger",
"log",
".",
"Logger",
")",
"api",
".",
"DexServer",
"{",
"return",
"dexAPI",
"{",
"s",
":",
"s",
",",
"logger",
":",
"logger",
",",
"}",
"\n",
"}"
] | // NewAPI returns a server which implements the gRPC API interface. | [
"NewAPI",
"returns",
"a",
"server",
"which",
"implements",
"the",
"gRPC",
"API",
"interface",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/api.go#L36-L41 |
164,688 | dexidp/dex | server/api.go | checkCost | func checkCost(hash []byte) error {
actual, err := bcrypt.Cost(hash)
if err != nil {
return fmt.Errorf("parsing bcrypt hash: %v", err)
}
if actual < bcrypt.DefaultCost {
return fmt.Errorf("given hash cost = %d does not meet minimum cost requirement = %d", actual, bcrypt.DefaultCost)
}
if actual > upBoundCost {
return fmt.Errorf("given hash cost = %d is above upper bound cost = %d, recommended cost = %d", actual, upBoundCost, recCost)
}
return nil
} | go | func checkCost(hash []byte) error {
actual, err := bcrypt.Cost(hash)
if err != nil {
return fmt.Errorf("parsing bcrypt hash: %v", err)
}
if actual < bcrypt.DefaultCost {
return fmt.Errorf("given hash cost = %d does not meet minimum cost requirement = %d", actual, bcrypt.DefaultCost)
}
if actual > upBoundCost {
return fmt.Errorf("given hash cost = %d is above upper bound cost = %d, recommended cost = %d", actual, upBoundCost, recCost)
}
return nil
} | [
"func",
"checkCost",
"(",
"hash",
"[",
"]",
"byte",
")",
"error",
"{",
"actual",
",",
"err",
":=",
"bcrypt",
".",
"Cost",
"(",
"hash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"actual",
"<",
"bcrypt",
".",
"DefaultCost",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"actual",
",",
"bcrypt",
".",
"DefaultCost",
")",
"\n",
"}",
"\n",
"if",
"actual",
">",
"upBoundCost",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"actual",
",",
"upBoundCost",
",",
"recCost",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // checkCost returns an error if the hash provided does not meet lower or upper
// bound cost requirements. | [
"checkCost",
"returns",
"an",
"error",
"if",
"the",
"hash",
"provided",
"does",
"not",
"meet",
"lower",
"or",
"upper",
"bound",
"cost",
"requirements",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/server/api.go#L127-L139 |
164,689 | dexidp/dex | connector/bitbucketcloud/bitbucketcloud.go | Open | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
b := bitbucketConnector{
redirectURI: c.RedirectURI,
teams: c.Teams,
clientID: c.ClientID,
clientSecret: c.ClientSecret,
apiURL: apiURL,
logger: logger,
}
return &b, nil
} | go | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
b := bitbucketConnector{
redirectURI: c.RedirectURI,
teams: c.Teams,
clientID: c.ClientID,
clientSecret: c.ClientSecret,
apiURL: apiURL,
logger: logger,
}
return &b, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"connector",
".",
"Connector",
",",
"error",
")",
"{",
"b",
":=",
"bitbucketConnector",
"{",
"redirectURI",
":",
"c",
".",
"RedirectURI",
",",
"teams",
":",
"c",
".",
"Teams",
",",
"clientID",
":",
"c",
".",
"ClientID",
",",
"clientSecret",
":",
"c",
".",
"ClientSecret",
",",
"apiURL",
":",
"apiURL",
",",
"logger",
":",
"logger",
",",
"}",
"\n\n",
"return",
"&",
"b",
",",
"nil",
"\n",
"}"
] | // Open returns a strategy for logging in through Bitbucket. | [
"Open",
"returns",
"a",
"strategy",
"for",
"logging",
"in",
"through",
"Bitbucket",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/bitbucketcloud/bitbucketcloud.go#L42-L54 |
164,690 | dexidp/dex | connector/bitbucketcloud/bitbucketcloud.go | groupsRequired | func (b *bitbucketConnector) groupsRequired(groupScope bool) bool {
return len(b.teams) > 0 || groupScope
} | go | func (b *bitbucketConnector) groupsRequired(groupScope bool) bool {
return len(b.teams) > 0 || groupScope
} | [
"func",
"(",
"b",
"*",
"bitbucketConnector",
")",
"groupsRequired",
"(",
"groupScope",
"bool",
")",
"bool",
"{",
"return",
"len",
"(",
"b",
".",
"teams",
")",
">",
"0",
"||",
"groupScope",
"\n",
"}"
] | // groupsRequired returns whether dex requires Bitbucket's 'team' scope. | [
"groupsRequired",
"returns",
"whether",
"dex",
"requires",
"Bitbucket",
"s",
"team",
"scope",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/bitbucketcloud/bitbucketcloud.go#L81-L83 |
164,691 | dexidp/dex | connector/bitbucketcloud/bitbucketcloud.go | getGroups | func (b *bitbucketConnector) getGroups(ctx context.Context, client *http.Client, groupScope bool, userLogin string) ([]string, error) {
bitbucketTeams, err := b.userTeams(ctx, client)
if err != nil {
return nil, err
}
if len(b.teams) > 0 {
filteredTeams := filterTeams(bitbucketTeams, b.teams)
if len(filteredTeams) == 0 {
return nil, fmt.Errorf("bitbucket: user %q is not in any of the required teams", userLogin)
}
return filteredTeams, nil
} else if groupScope {
return bitbucketTeams, nil
}
return nil, nil
} | go | func (b *bitbucketConnector) getGroups(ctx context.Context, client *http.Client, groupScope bool, userLogin string) ([]string, error) {
bitbucketTeams, err := b.userTeams(ctx, client)
if err != nil {
return nil, err
}
if len(b.teams) > 0 {
filteredTeams := filterTeams(bitbucketTeams, b.teams)
if len(filteredTeams) == 0 {
return nil, fmt.Errorf("bitbucket: user %q is not in any of the required teams", userLogin)
}
return filteredTeams, nil
} else if groupScope {
return bitbucketTeams, nil
}
return nil, nil
} | [
"func",
"(",
"b",
"*",
"bitbucketConnector",
")",
"getGroups",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"http",
".",
"Client",
",",
"groupScope",
"bool",
",",
"userLogin",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"bitbucketTeams",
",",
"err",
":=",
"b",
".",
"userTeams",
"(",
"ctx",
",",
"client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"b",
".",
"teams",
")",
">",
"0",
"{",
"filteredTeams",
":=",
"filterTeams",
"(",
"bitbucketTeams",
",",
"b",
".",
"teams",
")",
"\n",
"if",
"len",
"(",
"filteredTeams",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"userLogin",
")",
"\n",
"}",
"\n",
"return",
"filteredTeams",
",",
"nil",
"\n",
"}",
"else",
"if",
"groupScope",
"{",
"return",
"bitbucketTeams",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // getGroups retrieves Bitbucket teams a user is in, if any. | [
"getGroups",
"retrieves",
"Bitbucket",
"teams",
"a",
"user",
"is",
"in",
"if",
"any",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/bitbucketcloud/bitbucketcloud.go#L346-L363 |
164,692 | dexidp/dex | connector/bitbucketcloud/bitbucketcloud.go | get | func get(ctx context.Context, client *http.Client, apiURL string, v interface{}) error {
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return fmt.Errorf("bitbucket: new req: %v", err)
}
req = req.WithContext(ctx)
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("bitbucket: get URL %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("bitbucket: read body: %s: %v", resp.Status, err)
}
return fmt.Errorf("%s: %s", resp.Status, body)
}
if err := json.NewDecoder(resp.Body).Decode(v); err != nil {
return fmt.Errorf("bitbucket: failed to decode response: %v", err)
}
return nil
} | go | func get(ctx context.Context, client *http.Client, apiURL string, v interface{}) error {
req, err := http.NewRequest("GET", apiURL, nil)
if err != nil {
return fmt.Errorf("bitbucket: new req: %v", err)
}
req = req.WithContext(ctx)
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("bitbucket: get URL %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("bitbucket: read body: %s: %v", resp.Status, err)
}
return fmt.Errorf("%s: %s", resp.Status, body)
}
if err := json.NewDecoder(resp.Body).Decode(v); err != nil {
return fmt.Errorf("bitbucket: failed to decode response: %v", err)
}
return nil
} | [
"func",
"get",
"(",
"ctx",
"context",
".",
"Context",
",",
"client",
"*",
"http",
".",
"Client",
",",
"apiURL",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"apiURL",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
"=",
"req",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
",",
"body",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
".",
"Decode",
"(",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // get creates a "GET `apiURL`" request with context, sends the request using
// the client, and decodes the resulting response body into v.
// Any errors encountered when building requests, sending requests, and
// reading and decoding response data are returned. | [
"get",
"creates",
"a",
"GET",
"apiURL",
"request",
"with",
"context",
"sends",
"the",
"request",
"using",
"the",
"client",
"and",
"decodes",
"the",
"resulting",
"response",
"body",
"into",
"v",
".",
"Any",
"errors",
"encountered",
"when",
"building",
"requests",
"sending",
"requests",
"and",
"reading",
"and",
"decoding",
"response",
"data",
"are",
"returned",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/bitbucketcloud/bitbucketcloud.go#L418-L443 |
164,693 | dexidp/dex | storage/static.go | WithStaticClients | func WithStaticClients(s Storage, staticClients []Client) Storage {
clientsByID := make(map[string]Client, len(staticClients))
for _, client := range staticClients {
clientsByID[client.ID] = client
}
return staticClientsStorage{s, staticClients, clientsByID}
} | go | func WithStaticClients(s Storage, staticClients []Client) Storage {
clientsByID := make(map[string]Client, len(staticClients))
for _, client := range staticClients {
clientsByID[client.ID] = client
}
return staticClientsStorage{s, staticClients, clientsByID}
} | [
"func",
"WithStaticClients",
"(",
"s",
"Storage",
",",
"staticClients",
"[",
"]",
"Client",
")",
"Storage",
"{",
"clientsByID",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Client",
",",
"len",
"(",
"staticClients",
")",
")",
"\n",
"for",
"_",
",",
"client",
":=",
"range",
"staticClients",
"{",
"clientsByID",
"[",
"client",
".",
"ID",
"]",
"=",
"client",
"\n",
"}",
"\n\n",
"return",
"staticClientsStorage",
"{",
"s",
",",
"staticClients",
",",
"clientsByID",
"}",
"\n",
"}"
] | // WithStaticClients adds a read-only set of clients to the underlying storages. | [
"WithStaticClients",
"adds",
"a",
"read",
"-",
"only",
"set",
"of",
"clients",
"to",
"the",
"underlying",
"storages",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/static.go#L25-L32 |
164,694 | dexidp/dex | storage/static.go | WithStaticPasswords | func WithStaticPasswords(s Storage, staticPasswords []Password, logger log.Logger) Storage {
passwordsByEmail := make(map[string]Password, len(staticPasswords))
for _, p := range staticPasswords {
//Enable case insensitive email comparison.
lowerEmail := strings.ToLower(p.Email)
if _, ok := passwordsByEmail[lowerEmail]; ok {
logger.Errorf("Attempting to create StaticPasswords with the same email id: %s", p.Email)
}
passwordsByEmail[lowerEmail] = p
}
return staticPasswordsStorage{s, staticPasswords, passwordsByEmail, logger}
} | go | func WithStaticPasswords(s Storage, staticPasswords []Password, logger log.Logger) Storage {
passwordsByEmail := make(map[string]Password, len(staticPasswords))
for _, p := range staticPasswords {
//Enable case insensitive email comparison.
lowerEmail := strings.ToLower(p.Email)
if _, ok := passwordsByEmail[lowerEmail]; ok {
logger.Errorf("Attempting to create StaticPasswords with the same email id: %s", p.Email)
}
passwordsByEmail[lowerEmail] = p
}
return staticPasswordsStorage{s, staticPasswords, passwordsByEmail, logger}
} | [
"func",
"WithStaticPasswords",
"(",
"s",
"Storage",
",",
"staticPasswords",
"[",
"]",
"Password",
",",
"logger",
"log",
".",
"Logger",
")",
"Storage",
"{",
"passwordsByEmail",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Password",
",",
"len",
"(",
"staticPasswords",
")",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"staticPasswords",
"{",
"//Enable case insensitive email comparison.",
"lowerEmail",
":=",
"strings",
".",
"ToLower",
"(",
"p",
".",
"Email",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"passwordsByEmail",
"[",
"lowerEmail",
"]",
";",
"ok",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"Email",
")",
"\n",
"}",
"\n",
"passwordsByEmail",
"[",
"lowerEmail",
"]",
"=",
"p",
"\n",
"}",
"\n\n",
"return",
"staticPasswordsStorage",
"{",
"s",
",",
"staticPasswords",
",",
"passwordsByEmail",
",",
"logger",
"}",
"\n",
"}"
] | // WithStaticPasswords returns a storage with a read-only set of passwords. | [
"WithStaticPasswords",
"returns",
"a",
"storage",
"with",
"a",
"read",
"-",
"only",
"set",
"of",
"passwords",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/static.go#L96-L108 |
164,695 | dexidp/dex | storage/static.go | WithStaticConnectors | func WithStaticConnectors(s Storage, staticConnectors []Connector) Storage {
connectorsByID := make(map[string]Connector, len(staticConnectors))
for _, c := range staticConnectors {
connectorsByID[c.ID] = c
}
return staticConnectorsStorage{s, staticConnectors, connectorsByID}
} | go | func WithStaticConnectors(s Storage, staticConnectors []Connector) Storage {
connectorsByID := make(map[string]Connector, len(staticConnectors))
for _, c := range staticConnectors {
connectorsByID[c.ID] = c
}
return staticConnectorsStorage{s, staticConnectors, connectorsByID}
} | [
"func",
"WithStaticConnectors",
"(",
"s",
"Storage",
",",
"staticConnectors",
"[",
"]",
"Connector",
")",
"Storage",
"{",
"connectorsByID",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Connector",
",",
"len",
"(",
"staticConnectors",
")",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"staticConnectors",
"{",
"connectorsByID",
"[",
"c",
".",
"ID",
"]",
"=",
"c",
"\n",
"}",
"\n",
"return",
"staticConnectorsStorage",
"{",
"s",
",",
"staticConnectors",
",",
"connectorsByID",
"}",
"\n",
"}"
] | // WithStaticConnectors returns a storage with a read-only set of Connectors. Write actions,
// such as updating existing Connectors, will fail. | [
"WithStaticConnectors",
"returns",
"a",
"storage",
"with",
"a",
"read",
"-",
"only",
"set",
"of",
"Connectors",
".",
"Write",
"actions",
"such",
"as",
"updating",
"existing",
"Connectors",
"will",
"fail",
"."
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/storage/static.go#L175-L181 |
164,696 | dexidp/dex | connector/linkedin/linkedin.go | Open | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &linkedInConnector{
oauth2Config: &oauth2.Config{
ClientID: c.ClientID,
ClientSecret: c.ClientSecret,
Endpoint: oauth2.Endpoint{
AuthURL: authURL,
TokenURL: tokenURL,
},
Scopes: []string{"r_basicprofile", "r_emailaddress"},
RedirectURL: c.RedirectURI,
},
logger: logger,
}, nil
} | go | func (c *Config) Open(id string, logger log.Logger) (connector.Connector, error) {
return &linkedInConnector{
oauth2Config: &oauth2.Config{
ClientID: c.ClientID,
ClientSecret: c.ClientSecret,
Endpoint: oauth2.Endpoint{
AuthURL: authURL,
TokenURL: tokenURL,
},
Scopes: []string{"r_basicprofile", "r_emailaddress"},
RedirectURL: c.RedirectURI,
},
logger: logger,
}, nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Open",
"(",
"id",
"string",
",",
"logger",
"log",
".",
"Logger",
")",
"(",
"connector",
".",
"Connector",
",",
"error",
")",
"{",
"return",
"&",
"linkedInConnector",
"{",
"oauth2Config",
":",
"&",
"oauth2",
".",
"Config",
"{",
"ClientID",
":",
"c",
".",
"ClientID",
",",
"ClientSecret",
":",
"c",
".",
"ClientSecret",
",",
"Endpoint",
":",
"oauth2",
".",
"Endpoint",
"{",
"AuthURL",
":",
"authURL",
",",
"TokenURL",
":",
"tokenURL",
",",
"}",
",",
"Scopes",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"RedirectURL",
":",
"c",
".",
"RedirectURI",
",",
"}",
",",
"logger",
":",
"logger",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Open returns a strategy for logging in through LinkedIn | [
"Open",
"returns",
"a",
"strategy",
"for",
"logging",
"in",
"through",
"LinkedIn"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/linkedin/linkedin.go#L32-L46 |
164,697 | dexidp/dex | connector/linkedin/linkedin.go | LoginURL | func (c *linkedInConnector) LoginURL(scopes connector.Scopes, callbackURL, state string) (string, error) {
if c.oauth2Config.RedirectURL != callbackURL {
return "", fmt.Errorf("expected callback URL %q did not match the URL in the config %q",
callbackURL, c.oauth2Config.RedirectURL)
}
return c.oauth2Config.AuthCodeURL(state), nil
} | go | func (c *linkedInConnector) LoginURL(scopes connector.Scopes, callbackURL, state string) (string, error) {
if c.oauth2Config.RedirectURL != callbackURL {
return "", fmt.Errorf("expected callback URL %q did not match the URL in the config %q",
callbackURL, c.oauth2Config.RedirectURL)
}
return c.oauth2Config.AuthCodeURL(state), nil
} | [
"func",
"(",
"c",
"*",
"linkedInConnector",
")",
"LoginURL",
"(",
"scopes",
"connector",
".",
"Scopes",
",",
"callbackURL",
",",
"state",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"c",
".",
"oauth2Config",
".",
"RedirectURL",
"!=",
"callbackURL",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"callbackURL",
",",
"c",
".",
"oauth2Config",
".",
"RedirectURL",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"oauth2Config",
".",
"AuthCodeURL",
"(",
"state",
")",
",",
"nil",
"\n",
"}"
] | // LoginURL returns an access token request URL | [
"LoginURL",
"returns",
"an",
"access",
"token",
"request",
"URL"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/linkedin/linkedin.go#L65-L72 |
164,698 | dexidp/dex | connector/linkedin/linkedin.go | HandleCallback | func (c *linkedInConnector) HandleCallback(s connector.Scopes, r *http.Request) (identity connector.Identity, err error) {
q := r.URL.Query()
if errType := q.Get("error"); errType != "" {
return identity, &oauth2Error{errType, q.Get("error_description")}
}
ctx := r.Context()
token, err := c.oauth2Config.Exchange(ctx, q.Get("code"))
if err != nil {
return identity, fmt.Errorf("linkedin: get token: %v", err)
}
client := c.oauth2Config.Client(ctx, token)
profile, err := c.profile(ctx, client)
if err != nil {
return identity, fmt.Errorf("linkedin: get profile: %v", err)
}
identity = connector.Identity{
UserID: profile.ID,
Username: profile.fullname(),
Email: profile.Email,
EmailVerified: true,
}
if s.OfflineAccess {
data := connectorData{AccessToken: token.AccessToken}
connData, err := json.Marshal(data)
if err != nil {
return identity, fmt.Errorf("linkedin: marshal connector data: %v", err)
}
identity.ConnectorData = connData
}
return identity, nil
} | go | func (c *linkedInConnector) HandleCallback(s connector.Scopes, r *http.Request) (identity connector.Identity, err error) {
q := r.URL.Query()
if errType := q.Get("error"); errType != "" {
return identity, &oauth2Error{errType, q.Get("error_description")}
}
ctx := r.Context()
token, err := c.oauth2Config.Exchange(ctx, q.Get("code"))
if err != nil {
return identity, fmt.Errorf("linkedin: get token: %v", err)
}
client := c.oauth2Config.Client(ctx, token)
profile, err := c.profile(ctx, client)
if err != nil {
return identity, fmt.Errorf("linkedin: get profile: %v", err)
}
identity = connector.Identity{
UserID: profile.ID,
Username: profile.fullname(),
Email: profile.Email,
EmailVerified: true,
}
if s.OfflineAccess {
data := connectorData{AccessToken: token.AccessToken}
connData, err := json.Marshal(data)
if err != nil {
return identity, fmt.Errorf("linkedin: marshal connector data: %v", err)
}
identity.ConnectorData = connData
}
return identity, nil
} | [
"func",
"(",
"c",
"*",
"linkedInConnector",
")",
"HandleCallback",
"(",
"s",
"connector",
".",
"Scopes",
",",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"identity",
"connector",
".",
"Identity",
",",
"err",
"error",
")",
"{",
"q",
":=",
"r",
".",
"URL",
".",
"Query",
"(",
")",
"\n",
"if",
"errType",
":=",
"q",
".",
"Get",
"(",
"\"",
"\"",
")",
";",
"errType",
"!=",
"\"",
"\"",
"{",
"return",
"identity",
",",
"&",
"oauth2Error",
"{",
"errType",
",",
"q",
".",
"Get",
"(",
"\"",
"\"",
")",
"}",
"\n",
"}",
"\n\n",
"ctx",
":=",
"r",
".",
"Context",
"(",
")",
"\n",
"token",
",",
"err",
":=",
"c",
".",
"oauth2Config",
".",
"Exchange",
"(",
"ctx",
",",
"q",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"identity",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"client",
":=",
"c",
".",
"oauth2Config",
".",
"Client",
"(",
"ctx",
",",
"token",
")",
"\n",
"profile",
",",
"err",
":=",
"c",
".",
"profile",
"(",
"ctx",
",",
"client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"identity",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"identity",
"=",
"connector",
".",
"Identity",
"{",
"UserID",
":",
"profile",
".",
"ID",
",",
"Username",
":",
"profile",
".",
"fullname",
"(",
")",
",",
"Email",
":",
"profile",
".",
"Email",
",",
"EmailVerified",
":",
"true",
",",
"}",
"\n\n",
"if",
"s",
".",
"OfflineAccess",
"{",
"data",
":=",
"connectorData",
"{",
"AccessToken",
":",
"token",
".",
"AccessToken",
"}",
"\n",
"connData",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"identity",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"identity",
".",
"ConnectorData",
"=",
"connData",
"\n",
"}",
"\n\n",
"return",
"identity",
",",
"nil",
"\n",
"}"
] | // HandleCallback handles HTTP redirect from LinkedIn | [
"HandleCallback",
"handles",
"HTTP",
"redirect",
"from",
"LinkedIn"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/linkedin/linkedin.go#L75-L110 |
164,699 | dexidp/dex | connector/linkedin/linkedin.go | fullname | func (p profile) fullname() string {
fname := strings.TrimSpace(p.FirstName + " " + p.LastName)
if fname == "" {
return p.Email
}
return fname
} | go | func (p profile) fullname() string {
fname := strings.TrimSpace(p.FirstName + " " + p.LastName)
if fname == "" {
return p.Email
}
return fname
} | [
"func",
"(",
"p",
"profile",
")",
"fullname",
"(",
")",
"string",
"{",
"fname",
":=",
"strings",
".",
"TrimSpace",
"(",
"p",
".",
"FirstName",
"+",
"\"",
"\"",
"+",
"p",
".",
"LastName",
")",
"\n",
"if",
"fname",
"==",
"\"",
"\"",
"{",
"return",
"p",
".",
"Email",
"\n",
"}",
"\n\n",
"return",
"fname",
"\n",
"}"
] | // fullname returns a full name of a person, or email if the resulting name is
// empty | [
"fullname",
"returns",
"a",
"full",
"name",
"of",
"a",
"person",
"or",
"email",
"if",
"the",
"resulting",
"name",
"is",
"empty"
] | 60f47c4228b7719889eee4ca6c4c6cc60834d910 | https://github.com/dexidp/dex/blob/60f47c4228b7719889eee4ca6c4c6cc60834d910/connector/linkedin/linkedin.go#L143-L150 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.