repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
chrislusf/gleam
distributed/agent/agent_server.go
serveTcp
func (as *AgentServer) serveTcp(listener net.Listener) { for { // Listen for an incoming connection. conn, err := listener.Accept() if err != nil { fmt.Println("Error accepting: ", err.Error()) continue } // Handle connections in a new goroutine. go func() { defer conn.Close() if err = conn.SetDeadline(time.Time{}); err != nil { fmt.Printf("Failed to set timeout: %v\n", err) } if c, ok := conn.(*net.TCPConn); ok { c.SetKeepAlive(true) } as.handleRequest(conn) }() } }
go
func (as *AgentServer) serveTcp(listener net.Listener) { for { // Listen for an incoming connection. conn, err := listener.Accept() if err != nil { fmt.Println("Error accepting: ", err.Error()) continue } // Handle connections in a new goroutine. go func() { defer conn.Close() if err = conn.SetDeadline(time.Time{}); err != nil { fmt.Printf("Failed to set timeout: %v\n", err) } if c, ok := conn.(*net.TCPConn); ok { c.SetKeepAlive(true) } as.handleRequest(conn) }() } }
[ "func", "(", "as", "*", "AgentServer", ")", "serveTcp", "(", "listener", "net", ".", "Listener", ")", "{", "for", "{", "conn", ",", "err", ":=", "listener", ".", "Accept", "(", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"Error accepting: \"", ",", "err", ".", "Error", "(", ")", ")", "\n", "continue", "\n", "}", "\n", "go", "func", "(", ")", "{", "defer", "conn", ".", "Close", "(", ")", "\n", "if", "err", "=", "conn", ".", "SetDeadline", "(", "time", ".", "Time", "{", "}", ")", ";", "err", "!=", "nil", "{", "fmt", ".", "Printf", "(", "\"Failed to set timeout: %v\\n\"", ",", "\\n", ")", "\n", "}", "\n", "err", "\n", "if", "c", ",", "ok", ":=", "conn", ".", "(", "*", "net", ".", "TCPConn", ")", ";", "ok", "{", "c", ".", "SetKeepAlive", "(", "true", ")", "\n", "}", "\n", "}", "as", ".", "handleRequest", "(", "conn", ")", "\n", "}", "\n", "}" ]
// Run starts the heartbeating to master and starts accepting requests.
[ "Run", "starts", "the", "heartbeating", "to", "master", "and", "starts", "accepting", "requests", "." ]
a7aa467b545f5e5e452aaf818299a5f6e6b23760
https://github.com/chrislusf/gleam/blob/a7aa467b545f5e5e452aaf818299a5f6e6b23760/distributed/agent/agent_server.go#L104-L125
train
chrislusf/gleam
sql/util/types/etc.go
IsTypeBlob
func IsTypeBlob(tp byte) bool { switch tp { case mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob: return true default: return false } }
go
func IsTypeBlob(tp byte) bool { switch tp { case mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob: return true default: return false } }
[ "func", "IsTypeBlob", "(", "tp", "byte", ")", "bool", "{", "switch", "tp", "{", "case", "mysql", ".", "TypeTinyBlob", ",", "mysql", ".", "TypeMediumBlob", ",", "mysql", ".", "TypeBlob", ",", "mysql", ".", "TypeLongBlob", ":", "return", "true", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// IsTypeBlob returns a boolean indicating whether the tp is a blob type.
[ "IsTypeBlob", "returns", "a", "boolean", "indicating", "whether", "the", "tp", "is", "a", "blob", "type", "." ]
a7aa467b545f5e5e452aaf818299a5f6e6b23760
https://github.com/chrislusf/gleam/blob/a7aa467b545f5e5e452aaf818299a5f6e6b23760/sql/util/types/etc.go#L32-L39
train
chrislusf/gleam
sql/util/types/etc.go
IsTypeChar
func IsTypeChar(tp byte) bool { switch tp { case mysql.TypeString, mysql.TypeVarchar: return true default: return false } }
go
func IsTypeChar(tp byte) bool { switch tp { case mysql.TypeString, mysql.TypeVarchar: return true default: return false } }
[ "func", "IsTypeChar", "(", "tp", "byte", ")", "bool", "{", "switch", "tp", "{", "case", "mysql", ".", "TypeString", ",", "mysql", ".", "TypeVarchar", ":", "return", "true", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// IsTypeChar returns a boolean indicating // whether the tp is the char type like a string type or a varchar type.
[ "IsTypeChar", "returns", "a", "boolean", "indicating", "whether", "the", "tp", "is", "the", "char", "type", "like", "a", "string", "type", "or", "a", "varchar", "type", "." ]
a7aa467b545f5e5e452aaf818299a5f6e6b23760
https://github.com/chrislusf/gleam/blob/a7aa467b545f5e5e452aaf818299a5f6e6b23760/sql/util/types/etc.go#L43-L50
train
chrislusf/gleam
sql/util/types/etc.go
overflow
func overflow(v interface{}, tp byte) error { return errors.Errorf("constant %v overflows %s", v, TypeStr(tp)) }
go
func overflow(v interface{}, tp byte) error { return errors.Errorf("constant %v overflows %s", v, TypeStr(tp)) }
[ "func", "overflow", "(", "v", "interface", "{", "}", ",", "tp", "byte", ")", "error", "{", "return", "errors", ".", "Errorf", "(", "\"constant %v overflows %s\"", ",", "v", ",", "TypeStr", "(", "tp", ")", ")", "\n", "}" ]
// Overflow returns an overflowed error.
[ "Overflow", "returns", "an", "overflowed", "error", "." ]
a7aa467b545f5e5e452aaf818299a5f6e6b23760
https://github.com/chrislusf/gleam/blob/a7aa467b545f5e5e452aaf818299a5f6e6b23760/sql/util/types/etc.go#L132-L134
train
chrislusf/gleam
instruction/select.go
DoSelect
func DoSelect(reader io.Reader, writer io.Writer, keyIndexes, valueIndexes []int, stats *pb.InstructionStat) error { return util.ProcessRow(reader, nil, func(row *util.Row) error { stats.InputCounter++ var keys, values []interface{} kLen := len(row.K) for _, x := range keyIndexes { if x <= kLen { keys = append(keys, row.K[x-1]) } else { keys = append(keys, row.V[x-1-kLen]) } } for _, x := range valueIndexes { if x <= kLen { values = append(values, row.K[x-1]) } else { values = append(values, row.V[x-1-kLen]) } } row.K, row.V = keys, values row.WriteTo(writer) stats.OutputCounter++ return nil }) }
go
func DoSelect(reader io.Reader, writer io.Writer, keyIndexes, valueIndexes []int, stats *pb.InstructionStat) error { return util.ProcessRow(reader, nil, func(row *util.Row) error { stats.InputCounter++ var keys, values []interface{} kLen := len(row.K) for _, x := range keyIndexes { if x <= kLen { keys = append(keys, row.K[x-1]) } else { keys = append(keys, row.V[x-1-kLen]) } } for _, x := range valueIndexes { if x <= kLen { values = append(values, row.K[x-1]) } else { values = append(values, row.V[x-1-kLen]) } } row.K, row.V = keys, values row.WriteTo(writer) stats.OutputCounter++ return nil }) }
[ "func", "DoSelect", "(", "reader", "io", ".", "Reader", ",", "writer", "io", ".", "Writer", ",", "keyIndexes", ",", "valueIndexes", "[", "]", "int", ",", "stats", "*", "pb", ".", "InstructionStat", ")", "error", "{", "return", "util", ".", "ProcessRow", "(", "reader", ",", "nil", ",", "func", "(", "row", "*", "util", ".", "Row", ")", "error", "{", "stats", ".", "InputCounter", "++", "\n", "var", "keys", ",", "values", "[", "]", "interface", "{", "}", "\n", "kLen", ":=", "len", "(", "row", ".", "K", ")", "\n", "for", "_", ",", "x", ":=", "range", "keyIndexes", "{", "if", "x", "<=", "kLen", "{", "keys", "=", "append", "(", "keys", ",", "row", ".", "K", "[", "x", "-", "1", "]", ")", "\n", "}", "else", "{", "keys", "=", "append", "(", "keys", ",", "row", ".", "V", "[", "x", "-", "1", "-", "kLen", "]", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "x", ":=", "range", "valueIndexes", "{", "if", "x", "<=", "kLen", "{", "values", "=", "append", "(", "values", ",", "row", ".", "K", "[", "x", "-", "1", "]", ")", "\n", "}", "else", "{", "values", "=", "append", "(", "values", ",", "row", ".", "V", "[", "x", "-", "1", "-", "kLen", "]", ")", "\n", "}", "\n", "}", "\n", "row", ".", "K", ",", "row", ".", "V", "=", "keys", ",", "values", "\n", "row", ".", "WriteTo", "(", "writer", ")", "\n", "stats", ".", "OutputCounter", "++", "\n", "return", "nil", "\n", "}", ")", "\n", "}" ]
// DoSelect projects the fields
[ "DoSelect", "projects", "the", "fields" ]
a7aa467b545f5e5e452aaf818299a5f6e6b23760
https://github.com/chrislusf/gleam/blob/a7aa467b545f5e5e452aaf818299a5f6e6b23760/instruction/select.go#L57-L86
train
gojektech/heimdall
retry.go
NextInterval
func (r *retrier) NextInterval(retry int) time.Duration { return r.backoff.Next(retry) }
go
func (r *retrier) NextInterval(retry int) time.Duration { return r.backoff.Next(retry) }
[ "func", "(", "r", "*", "retrier", ")", "NextInterval", "(", "retry", "int", ")", "time", ".", "Duration", "{", "return", "r", ".", "backoff", ".", "Next", "(", "retry", ")", "\n", "}" ]
// NextInterval returns next retriable time
[ "NextInterval", "returns", "next", "retriable", "time" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/retry.go#L36-L38
train
gojektech/heimdall
hystrix/options.go
WithHTTPTimeout
func WithHTTPTimeout(timeout time.Duration) Option { return func(c *Client) { c.timeout = timeout } }
go
func WithHTTPTimeout(timeout time.Duration) Option { return func(c *Client) { c.timeout = timeout } }
[ "func", "WithHTTPTimeout", "(", "timeout", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "Client", ")", "{", "c", ".", "timeout", "=", "timeout", "\n", "}", "\n", "}" ]
// WithHTTPTimeout sets hystrix timeout
[ "WithHTTPTimeout", "sets", "hystrix", "timeout" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/options.go#L20-L24
train
gojektech/heimdall
hystrix/options.go
WithHystrixTimeout
func WithHystrixTimeout(timeout time.Duration) Option { return func(c *Client) { c.hystrixTimeout = timeout } }
go
func WithHystrixTimeout(timeout time.Duration) Option { return func(c *Client) { c.hystrixTimeout = timeout } }
[ "func", "WithHystrixTimeout", "(", "timeout", "time", ".", "Duration", ")", "Option", "{", "return", "func", "(", "c", "*", "Client", ")", "{", "c", ".", "hystrixTimeout", "=", "timeout", "\n", "}", "\n", "}" ]
// WithHystrixTimeout sets hystrix timeout
[ "WithHystrixTimeout", "sets", "hystrix", "timeout" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/options.go#L27-L31
train
gojektech/heimdall
hystrix/options.go
WithRetrier
func WithRetrier(retrier heimdall.Retriable) Option { return func(c *Client) { c.retrier = retrier } }
go
func WithRetrier(retrier heimdall.Retriable) Option { return func(c *Client) { c.retrier = retrier } }
[ "func", "WithRetrier", "(", "retrier", "heimdall", ".", "Retriable", ")", "Option", "{", "return", "func", "(", "c", "*", "Client", ")", "{", "c", ".", "retrier", "=", "retrier", "\n", "}", "\n", "}" ]
// WithRetrier sets the strategy for retrying
[ "WithRetrier", "sets", "the", "strategy", "for", "retrying" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/options.go#L76-L80
train
gojektech/heimdall
hystrix/options.go
WithHTTPClient
func WithHTTPClient(client heimdall.Doer) Option { return func(c *Client) { c.client = client } }
go
func WithHTTPClient(client heimdall.Doer) Option { return func(c *Client) { c.client = client } }
[ "func", "WithHTTPClient", "(", "client", "heimdall", ".", "Doer", ")", "Option", "{", "return", "func", "(", "c", "*", "Client", ")", "{", "c", ".", "client", "=", "client", "\n", "}", "\n", "}" ]
// WithHTTPClient sets a custom http client for hystrix client
[ "WithHTTPClient", "sets", "a", "custom", "http", "client", "for", "hystrix", "client" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/options.go#L83-L87
train
gojektech/heimdall
httpclient/client.go
NewClient
func NewClient(opts ...Option) *Client { client := Client{ timeout: defaultHTTPTimeout, retryCount: defaultRetryCount, retrier: heimdall.NewNoRetrier(), } for _, opt := range opts { opt(&client) } if client.client == nil { client.client = &http.Client{ Timeout: client.timeout, } } return &client }
go
func NewClient(opts ...Option) *Client { client := Client{ timeout: defaultHTTPTimeout, retryCount: defaultRetryCount, retrier: heimdall.NewNoRetrier(), } for _, opt := range opts { opt(&client) } if client.client == nil { client.client = &http.Client{ Timeout: client.timeout, } } return &client }
[ "func", "NewClient", "(", "opts", "...", "Option", ")", "*", "Client", "{", "client", ":=", "Client", "{", "timeout", ":", "defaultHTTPTimeout", ",", "retryCount", ":", "defaultRetryCount", ",", "retrier", ":", "heimdall", ".", "NewNoRetrier", "(", ")", ",", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", "(", "&", "client", ")", "\n", "}", "\n", "if", "client", ".", "client", "==", "nil", "{", "client", ".", "client", "=", "&", "http", ".", "Client", "{", "Timeout", ":", "client", ".", "timeout", ",", "}", "\n", "}", "\n", "return", "&", "client", "\n", "}" ]
// NewClient returns a new instance of http Client
[ "NewClient", "returns", "a", "new", "instance", "of", "http", "Client" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/httpclient/client.go#L32-L50
train
gojektech/heimdall
backoff.go
Next
func (cb *constantBackoff) Next(retry int) time.Duration { if retry <= 0 { return 0 * time.Millisecond } return (time.Duration(cb.backoffInterval) * time.Millisecond) + (time.Duration(rand.Int63n(cb.maximumJitterInterval)) * time.Millisecond) }
go
func (cb *constantBackoff) Next(retry int) time.Duration { if retry <= 0 { return 0 * time.Millisecond } return (time.Duration(cb.backoffInterval) * time.Millisecond) + (time.Duration(rand.Int63n(cb.maximumJitterInterval)) * time.Millisecond) }
[ "func", "(", "cb", "*", "constantBackoff", ")", "Next", "(", "retry", "int", ")", "time", ".", "Duration", "{", "if", "retry", "<=", "0", "{", "return", "0", "*", "time", ".", "Millisecond", "\n", "}", "\n", "return", "(", "time", ".", "Duration", "(", "cb", ".", "backoffInterval", ")", "*", "time", ".", "Millisecond", ")", "+", "(", "time", ".", "Duration", "(", "rand", ".", "Int63n", "(", "cb", ".", "maximumJitterInterval", ")", ")", "*", "time", ".", "Millisecond", ")", "\n", "}" ]
// Next returns next time for retrying operation with constant strategy
[ "Next", "returns", "next", "time", "for", "retrying", "operation", "with", "constant", "strategy" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/backoff.go#L33-L38
train
gojektech/heimdall
backoff.go
Next
func (eb *exponentialBackoff) Next(retry int) time.Duration { if retry <= 0 { return 0 * time.Millisecond } return time.Duration(math.Min(eb.initialTimeout+math.Pow(eb.exponentFactor, float64(retry)), eb.maxTimeout)+float64(rand.Int63n(eb.maximumJitterInterval))) * time.Millisecond }
go
func (eb *exponentialBackoff) Next(retry int) time.Duration { if retry <= 0 { return 0 * time.Millisecond } return time.Duration(math.Min(eb.initialTimeout+math.Pow(eb.exponentFactor, float64(retry)), eb.maxTimeout)+float64(rand.Int63n(eb.maximumJitterInterval))) * time.Millisecond }
[ "func", "(", "eb", "*", "exponentialBackoff", ")", "Next", "(", "retry", "int", ")", "time", ".", "Duration", "{", "if", "retry", "<=", "0", "{", "return", "0", "*", "time", ".", "Millisecond", "\n", "}", "\n", "return", "time", ".", "Duration", "(", "math", ".", "Min", "(", "eb", ".", "initialTimeout", "+", "math", ".", "Pow", "(", "eb", ".", "exponentFactor", ",", "float64", "(", "retry", ")", ")", ",", "eb", ".", "maxTimeout", ")", "+", "float64", "(", "rand", ".", "Int63n", "(", "eb", ".", "maximumJitterInterval", ")", ")", ")", "*", "time", ".", "Millisecond", "\n", "}" ]
// Next returns next time for retrying operation with exponential strategy
[ "Next", "returns", "next", "time", "for", "retrying", "operation", "with", "exponential", "strategy" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/backoff.go#L59-L64
train
gojektech/heimdall
hystrix/hystrix_client.go
NewClient
func NewClient(opts ...Option) *Client { client := Client{ timeout: defaultHTTPTimeout, hystrixTimeout: defaultHystrixTimeout, maxConcurrentRequests: defaultMaxConcurrentRequests, errorPercentThreshold: defaultErrorPercentThreshold, sleepWindow: defaultSleepWindow, requestVolumeThreshold: defaultRequestVolumeThreshold, retryCount: defaultHystrixRetryCount, retrier: heimdall.NewNoRetrier(), } for _, opt := range opts { opt(&client) } if client.client == nil { client.client = &http.Client{ Timeout: client.timeout, } } hystrix.ConfigureCommand(client.hystrixCommandName, hystrix.CommandConfig{ Timeout: durationToInt(client.hystrixTimeout, time.Millisecond), MaxConcurrentRequests: client.maxConcurrentRequests, RequestVolumeThreshold: client.requestVolumeThreshold, SleepWindow: client.sleepWindow, ErrorPercentThreshold: client.errorPercentThreshold, }) return &client }
go
func NewClient(opts ...Option) *Client { client := Client{ timeout: defaultHTTPTimeout, hystrixTimeout: defaultHystrixTimeout, maxConcurrentRequests: defaultMaxConcurrentRequests, errorPercentThreshold: defaultErrorPercentThreshold, sleepWindow: defaultSleepWindow, requestVolumeThreshold: defaultRequestVolumeThreshold, retryCount: defaultHystrixRetryCount, retrier: heimdall.NewNoRetrier(), } for _, opt := range opts { opt(&client) } if client.client == nil { client.client = &http.Client{ Timeout: client.timeout, } } hystrix.ConfigureCommand(client.hystrixCommandName, hystrix.CommandConfig{ Timeout: durationToInt(client.hystrixTimeout, time.Millisecond), MaxConcurrentRequests: client.maxConcurrentRequests, RequestVolumeThreshold: client.requestVolumeThreshold, SleepWindow: client.sleepWindow, ErrorPercentThreshold: client.errorPercentThreshold, }) return &client }
[ "func", "NewClient", "(", "opts", "...", "Option", ")", "*", "Client", "{", "client", ":=", "Client", "{", "timeout", ":", "defaultHTTPTimeout", ",", "hystrixTimeout", ":", "defaultHystrixTimeout", ",", "maxConcurrentRequests", ":", "defaultMaxConcurrentRequests", ",", "errorPercentThreshold", ":", "defaultErrorPercentThreshold", ",", "sleepWindow", ":", "defaultSleepWindow", ",", "requestVolumeThreshold", ":", "defaultRequestVolumeThreshold", ",", "retryCount", ":", "defaultHystrixRetryCount", ",", "retrier", ":", "heimdall", ".", "NewNoRetrier", "(", ")", ",", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "opt", "(", "&", "client", ")", "\n", "}", "\n", "if", "client", ".", "client", "==", "nil", "{", "client", ".", "client", "=", "&", "http", ".", "Client", "{", "Timeout", ":", "client", ".", "timeout", ",", "}", "\n", "}", "\n", "hystrix", ".", "ConfigureCommand", "(", "client", ".", "hystrixCommandName", ",", "hystrix", ".", "CommandConfig", "{", "Timeout", ":", "durationToInt", "(", "client", ".", "hystrixTimeout", ",", "time", ".", "Millisecond", ")", ",", "MaxConcurrentRequests", ":", "client", ".", "maxConcurrentRequests", ",", "RequestVolumeThreshold", ":", "client", ".", "requestVolumeThreshold", ",", "SleepWindow", ":", "client", ".", "sleepWindow", ",", "ErrorPercentThreshold", ":", "client", ".", "errorPercentThreshold", ",", "}", ")", "\n", "return", "&", "client", "\n", "}" ]
// NewClient returns a new instance of hystrix Client
[ "NewClient", "returns", "a", "new", "instance", "of", "hystrix", "Client" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/hystrix_client.go#L50-L81
train
gojektech/heimdall
hystrix/hystrix_client.go
Patch
func (hhc *Client) Patch(url string, body io.Reader, headers http.Header) (*http.Response, error) { var response *http.Response request, err := http.NewRequest(http.MethodPatch, url, body) if err != nil { return response, errors.Wrap(err, "PATCH - request creation failed") } request.Header = headers return hhc.Do(request) }
go
func (hhc *Client) Patch(url string, body io.Reader, headers http.Header) (*http.Response, error) { var response *http.Response request, err := http.NewRequest(http.MethodPatch, url, body) if err != nil { return response, errors.Wrap(err, "PATCH - request creation failed") } request.Header = headers return hhc.Do(request) }
[ "func", "(", "hhc", "*", "Client", ")", "Patch", "(", "url", "string", ",", "body", "io", ".", "Reader", ",", "headers", "http", ".", "Header", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "var", "response", "*", "http", ".", "Response", "\n", "request", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodPatch", ",", "url", ",", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "response", ",", "errors", ".", "Wrap", "(", "err", ",", "\"PATCH - request creation failed\"", ")", "\n", "}", "\n", "request", ".", "Header", "=", "headers", "\n", "return", "hhc", ".", "Do", "(", "request", ")", "\n", "}" ]
// Patch makes a HTTP PATCH request to provided URL and requestBody
[ "Patch", "makes", "a", "HTTP", "PATCH", "request", "to", "provided", "URL", "and", "requestBody" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/hystrix_client.go#L135-L145
train
gojektech/heimdall
hystrix/hystrix_client.go
Delete
func (hhc *Client) Delete(url string, headers http.Header) (*http.Response, error) { var response *http.Response request, err := http.NewRequest(http.MethodDelete, url, nil) if err != nil { return response, errors.Wrap(err, "DELETE - request creation failed") } request.Header = headers return hhc.Do(request) }
go
func (hhc *Client) Delete(url string, headers http.Header) (*http.Response, error) { var response *http.Response request, err := http.NewRequest(http.MethodDelete, url, nil) if err != nil { return response, errors.Wrap(err, "DELETE - request creation failed") } request.Header = headers return hhc.Do(request) }
[ "func", "(", "hhc", "*", "Client", ")", "Delete", "(", "url", "string", ",", "headers", "http", ".", "Header", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "var", "response", "*", "http", ".", "Response", "\n", "request", ",", "err", ":=", "http", ".", "NewRequest", "(", "http", ".", "MethodDelete", ",", "url", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "response", ",", "errors", ".", "Wrap", "(", "err", ",", "\"DELETE - request creation failed\"", ")", "\n", "}", "\n", "request", ".", "Header", "=", "headers", "\n", "return", "hhc", ".", "Do", "(", "request", ")", "\n", "}" ]
// Delete makes a HTTP DELETE request with provided URL
[ "Delete", "makes", "a", "HTTP", "DELETE", "request", "with", "provided", "URL" ]
ef69e0bb0cbf72e832303efe6362855811e8cc89
https://github.com/gojektech/heimdall/blob/ef69e0bb0cbf72e832303efe6362855811e8cc89/hystrix/hystrix_client.go#L148-L158
train
gopasspw/gopass
pkg/clipboard/clipboard.go
CopyTo
func CopyTo(ctx context.Context, name string, content []byte) error { if clipboard.Unsupported { out.Yellow(ctx, "%s", ErrNotSupported) return nil } if err := clipboard.WriteAll(string(content)); err != nil { return errors.Wrapf(err, "failed to write to clipboard") } if err := clear(ctx, content, ctxutil.GetClipTimeout(ctx)); err != nil { return errors.Wrapf(err, "failed to clear clipboard") } out.Print(ctx, "✔ Copied %s to clipboard. Will clear in %d seconds.", color.YellowString(name), ctxutil.GetClipTimeout(ctx)) return nil }
go
func CopyTo(ctx context.Context, name string, content []byte) error { if clipboard.Unsupported { out.Yellow(ctx, "%s", ErrNotSupported) return nil } if err := clipboard.WriteAll(string(content)); err != nil { return errors.Wrapf(err, "failed to write to clipboard") } if err := clear(ctx, content, ctxutil.GetClipTimeout(ctx)); err != nil { return errors.Wrapf(err, "failed to clear clipboard") } out.Print(ctx, "✔ Copied %s to clipboard. Will clear in %d seconds.", color.YellowString(name), ctxutil.GetClipTimeout(ctx)) return nil }
[ "func", "CopyTo", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "content", "[", "]", "byte", ")", "error", "{", "if", "clipboard", ".", "Unsupported", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"%s\"", ",", "ErrNotSupported", ")", "\n", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "clipboard", ".", "WriteAll", "(", "string", "(", "content", ")", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to write to clipboard\"", ")", "\n", "}", "\n", "if", "err", ":=", "clear", "(", "ctx", ",", "content", ",", "ctxutil", ".", "GetClipTimeout", "(", "ctx", ")", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to clear clipboard\"", ")", "\n", "}", "\n", "out", ".", "Print", "(", "ctx", ",", "\"✔ Copied %s to clipboard. Will clear in %d seconds.\", ", " ", "c", "lor.Y", "e", "llowString(n", "a", "me),", " ", "c", ")", "\n", "xutil.G", "e", "tClipTimeout(c", "t", "x))", ")", "\n", "}" ]
// CopyTo copies the given data to the clipboard and enqueues automatic // clearing of the clipboard
[ "CopyTo", "copies", "the", "given", "data", "to", "the", "clipboard", "and", "enqueues", "automatic", "clearing", "of", "the", "clipboard" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/clipboard/clipboard.go#L23-L39
train
gopasspw/gopass
pkg/store/sub/crypto.go
GetCryptoBackend
func GetCryptoBackend(ctx context.Context, cb backend.CryptoBackend, cfgdir string, agent *client.Client) (backend.Crypto, error) { ctx = client.WithClient(ctx, agent) ctx = ctxutil.WithConfigDir(ctx, cfgdir) crypto, err := backend.NewCrypto(ctx, cb) if err != nil { return nil, errors.Wrapf(err, "unknown crypto backend") } return crypto, nil }
go
func GetCryptoBackend(ctx context.Context, cb backend.CryptoBackend, cfgdir string, agent *client.Client) (backend.Crypto, error) { ctx = client.WithClient(ctx, agent) ctx = ctxutil.WithConfigDir(ctx, cfgdir) crypto, err := backend.NewCrypto(ctx, cb) if err != nil { return nil, errors.Wrapf(err, "unknown crypto backend") } return crypto, nil }
[ "func", "GetCryptoBackend", "(", "ctx", "context", ".", "Context", ",", "cb", "backend", ".", "CryptoBackend", ",", "cfgdir", "string", ",", "agent", "*", "client", ".", "Client", ")", "(", "backend", ".", "Crypto", ",", "error", ")", "{", "ctx", "=", "client", ".", "WithClient", "(", "ctx", ",", "agent", ")", "\n", "ctx", "=", "ctxutil", ".", "WithConfigDir", "(", "ctx", ",", "cfgdir", ")", "\n", "crypto", ",", "err", ":=", "backend", ".", "NewCrypto", "(", "ctx", ",", "cb", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"unknown crypto backend\"", ")", "\n", "}", "\n", "return", "crypto", ",", "nil", "\n", "}" ]
// GetCryptoBackend initialized the correct crypto backend
[ "GetCryptoBackend", "initialized", "the", "correct", "crypto", "backend" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/crypto.go#L22-L30
train
gopasspw/gopass
pkg/action/generate.go
Generate
func (s *Action) Generate(ctx context.Context, c *cli.Context) error { force := c.Bool("force") edit := c.Bool("edit") args, kvps := parseArgs(c) name := args.Get(0) key, length := keyAndLength(args) // ask for name of the secret if it wasn't provided already if name == "" { var err error name, err = termio.AskForString(ctx, "Which name do you want to use?", "") if err != nil || name == "" { return ExitError(ctx, ExitNoName, err, "please provide a password name") } } ctx = s.Store.WithConfig(ctx, name) // ask for confirmation before overwriting existing entry if !force { // don't check if it's force anyway if s.Store.Exists(ctx, name) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("An entry already exists for %s. Overwrite the current password?", name)) { return ExitError(ctx, ExitAborted, nil, "user aborted. not overwriting your current password") } } // generate password password, err := s.generatePassword(ctx, c, length) if err != nil { return err } // write generated password to store ctx, err = s.generateSetPassword(ctx, name, key, password, kvps) if err != nil { return err } // if requested launch editor to add more data to the generated secret if (edit || ctxutil.IsAskForMore(ctx)) && termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add more data for %s?", name)) { if err := s.Edit(ctx, c); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to edit '%s': %s", name, err) } } // display or copy to clipboard return s.generateCopyOrPrint(ctx, c, name, key, password) }
go
func (s *Action) Generate(ctx context.Context, c *cli.Context) error { force := c.Bool("force") edit := c.Bool("edit") args, kvps := parseArgs(c) name := args.Get(0) key, length := keyAndLength(args) // ask for name of the secret if it wasn't provided already if name == "" { var err error name, err = termio.AskForString(ctx, "Which name do you want to use?", "") if err != nil || name == "" { return ExitError(ctx, ExitNoName, err, "please provide a password name") } } ctx = s.Store.WithConfig(ctx, name) // ask for confirmation before overwriting existing entry if !force { // don't check if it's force anyway if s.Store.Exists(ctx, name) && key == "" && !termio.AskForConfirmation(ctx, fmt.Sprintf("An entry already exists for %s. Overwrite the current password?", name)) { return ExitError(ctx, ExitAborted, nil, "user aborted. not overwriting your current password") } } // generate password password, err := s.generatePassword(ctx, c, length) if err != nil { return err } // write generated password to store ctx, err = s.generateSetPassword(ctx, name, key, password, kvps) if err != nil { return err } // if requested launch editor to add more data to the generated secret if (edit || ctxutil.IsAskForMore(ctx)) && termio.AskForConfirmation(ctx, fmt.Sprintf("Do you want to add more data for %s?", name)) { if err := s.Edit(ctx, c); err != nil { return ExitError(ctx, ExitUnknown, err, "failed to edit '%s': %s", name, err) } } // display or copy to clipboard return s.generateCopyOrPrint(ctx, c, name, key, password) }
[ "func", "(", "s", "*", "Action", ")", "Generate", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "edit", ":=", "c", ".", "Bool", "(", "\"edit\"", ")", "\n", "args", ",", "kvps", ":=", "parseArgs", "(", "c", ")", "\n", "name", ":=", "args", ".", "Get", "(", "0", ")", "\n", "key", ",", "length", ":=", "keyAndLength", "(", "args", ")", "\n", "if", "name", "==", "\"\"", "{", "var", "err", "error", "\n", "name", ",", "err", "=", "termio", ".", "AskForString", "(", "ctx", ",", "\"Which name do you want to use?\"", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "||", "name", "==", "\"\"", "{", "return", "ExitError", "(", "ctx", ",", "ExitNoName", ",", "err", ",", "\"please provide a password name\"", ")", "\n", "}", "\n", "}", "\n", "ctx", "=", "s", ".", "Store", ".", "WithConfig", "(", "ctx", ",", "name", ")", "\n", "if", "!", "force", "{", "if", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "name", ")", "&&", "key", "==", "\"\"", "&&", "!", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"An entry already exists for %s. Overwrite the current password?\"", ",", "name", ")", ")", "{", "return", "ExitError", "(", "ctx", ",", "ExitAborted", ",", "nil", ",", "\"user aborted. not overwriting your current password\"", ")", "\n", "}", "\n", "}", "\n", "password", ",", "err", ":=", "s", ".", "generatePassword", "(", "ctx", ",", "c", ",", "length", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "ctx", ",", "err", "=", "s", ".", "generateSetPassword", "(", "ctx", ",", "name", ",", "key", ",", "password", ",", "kvps", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "(", "edit", "||", "ctxutil", ".", "IsAskForMore", "(", "ctx", ")", ")", "&&", "termio", ".", "AskForConfirmation", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Do you want to add more data for %s?\"", ",", "name", ")", ")", "{", "if", "err", ":=", "s", ".", "Edit", "(", "ctx", ",", "c", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitUnknown", ",", "err", ",", "\"failed to edit '%s': %s\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "}", "\n", "return", "s", ".", "generateCopyOrPrint", "(", "ctx", ",", "c", ",", "name", ",", "key", ",", "password", ")", "\n", "}" ]
// Generate and save a password
[ "Generate", "and", "save", "a", "password" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L36-L83
train
gopasspw/gopass
pkg/action/generate.go
generateCopyOrPrint
func (s *Action) generateCopyOrPrint(ctx context.Context, c *cli.Context, name, key, password string) error { if ctxutil.IsAutoPrint(ctx) || c.Bool("print") { if key != "" { key = " " + key } out.Print( ctx, "The generated password for %s%s is:\n%s", name, key, color.YellowString(password), ) } if ctxutil.IsAutoClip(ctx) || c.Bool("clip") { if err := clipboard.CopyTo(ctx, name, []byte(password)); err != nil { return ExitError(ctx, ExitIO, err, "failed to copy to clipboard: %s", err) } } if c.Bool("print") || c.Bool("clip") { return nil } entry := name if key != "" { entry += ":" + key } out.Print(ctx, "Password for %s generated", entry) return nil }
go
func (s *Action) generateCopyOrPrint(ctx context.Context, c *cli.Context, name, key, password string) error { if ctxutil.IsAutoPrint(ctx) || c.Bool("print") { if key != "" { key = " " + key } out.Print( ctx, "The generated password for %s%s is:\n%s", name, key, color.YellowString(password), ) } if ctxutil.IsAutoClip(ctx) || c.Bool("clip") { if err := clipboard.CopyTo(ctx, name, []byte(password)); err != nil { return ExitError(ctx, ExitIO, err, "failed to copy to clipboard: %s", err) } } if c.Bool("print") || c.Bool("clip") { return nil } entry := name if key != "" { entry += ":" + key } out.Print(ctx, "Password for %s generated", entry) return nil }
[ "func", "(", "s", "*", "Action", ")", "generateCopyOrPrint", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "name", ",", "key", ",", "password", "string", ")", "error", "{", "if", "ctxutil", ".", "IsAutoPrint", "(", "ctx", ")", "||", "c", ".", "Bool", "(", "\"print\"", ")", "{", "if", "key", "!=", "\"\"", "{", "key", "=", "\" \"", "+", "key", "\n", "}", "\n", "out", ".", "Print", "(", "ctx", ",", "\"The generated password for %s%s is:\\n%s\"", ",", "\\n", ",", "name", ",", "key", ",", ")", "\n", "}", "\n", "color", ".", "YellowString", "(", "password", ")", "\n", "if", "ctxutil", ".", "IsAutoClip", "(", "ctx", ")", "||", "c", ".", "Bool", "(", "\"clip\"", ")", "{", "if", "err", ":=", "clipboard", ".", "CopyTo", "(", "ctx", ",", "name", ",", "[", "]", "byte", "(", "password", ")", ")", ";", "err", "!=", "nil", "{", "return", "ExitError", "(", "ctx", ",", "ExitIO", ",", "err", ",", "\"failed to copy to clipboard: %s\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "c", ".", "Bool", "(", "\"print\"", ")", "||", "c", ".", "Bool", "(", "\"clip\"", ")", "{", "return", "nil", "\n", "}", "\n", "entry", ":=", "name", "\n", "if", "key", "!=", "\"\"", "{", "entry", "+=", "\":\"", "+", "key", "\n", "}", "\n", "out", ".", "Print", "(", "ctx", ",", "\"Password for %s generated\"", ",", "entry", ")", "\n", "}" ]
// generateCopyOrPrint will print the password to the screen or copy to the // clipboard
[ "generateCopyOrPrint", "will", "print", "the", "password", "to", "the", "screen", "or", "copy", "to", "the", "clipboard" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L103-L131
train
gopasspw/gopass
pkg/action/generate.go
generatePassword
func (s *Action) generatePassword(ctx context.Context, c *cli.Context, length string) (string, error) { if c.Bool("xkcd") || c.IsSet("xkcdsep") { return s.generatePasswordXKCD(ctx, c, length) } symbols := ctxutil.IsUseSymbols(ctx) if c.IsSet("symbols") { symbols = c.Bool("symbols") } var pwlen int if length == "" { candidateLength := defaultLength question := "How long should the password be?" iv, err := termio.AskForInt(ctx, question, candidateLength) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number") } pwlen = iv } else { iv, err := strconv.Atoi(length) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number") } pwlen = iv } if pwlen < 1 { return "", ExitError(ctx, ExitUsage, nil, "password length must not be zero") } corp, err := termio.AskForBool(ctx, "Do you have strict rules to include different character classes?", false) if err != nil { return "", err } if corp { return pwgen.GeneratePasswordWithAllClasses(pwlen) } return pwgen.GeneratePassword(pwlen, symbols), nil }
go
func (s *Action) generatePassword(ctx context.Context, c *cli.Context, length string) (string, error) { if c.Bool("xkcd") || c.IsSet("xkcdsep") { return s.generatePasswordXKCD(ctx, c, length) } symbols := ctxutil.IsUseSymbols(ctx) if c.IsSet("symbols") { symbols = c.Bool("symbols") } var pwlen int if length == "" { candidateLength := defaultLength question := "How long should the password be?" iv, err := termio.AskForInt(ctx, question, candidateLength) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number") } pwlen = iv } else { iv, err := strconv.Atoi(length) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number") } pwlen = iv } if pwlen < 1 { return "", ExitError(ctx, ExitUsage, nil, "password length must not be zero") } corp, err := termio.AskForBool(ctx, "Do you have strict rules to include different character classes?", false) if err != nil { return "", err } if corp { return pwgen.GeneratePasswordWithAllClasses(pwlen) } return pwgen.GeneratePassword(pwlen, symbols), nil }
[ "func", "(", "s", "*", "Action", ")", "generatePassword", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "length", "string", ")", "(", "string", ",", "error", ")", "{", "if", "c", ".", "Bool", "(", "\"xkcd\"", ")", "||", "c", ".", "IsSet", "(", "\"xkcdsep\"", ")", "{", "return", "s", ".", "generatePasswordXKCD", "(", "ctx", ",", "c", ",", "length", ")", "\n", "}", "\n", "symbols", ":=", "ctxutil", ".", "IsUseSymbols", "(", "ctx", ")", "\n", "if", "c", ".", "IsSet", "(", "\"symbols\"", ")", "{", "symbols", "=", "c", ".", "Bool", "(", "\"symbols\"", ")", "\n", "}", "\n", "var", "pwlen", "int", "\n", "if", "length", "==", "\"\"", "{", "candidateLength", ":=", "defaultLength", "\n", "question", ":=", "\"How long should the password be?\"", "\n", "iv", ",", "err", ":=", "termio", ".", "AskForInt", "(", "ctx", ",", "question", ",", "candidateLength", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "err", ",", "\"password length must be a number\"", ")", "\n", "}", "\n", "pwlen", "=", "iv", "\n", "}", "else", "{", "iv", ",", "err", ":=", "strconv", ".", "Atoi", "(", "length", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "err", ",", "\"password length must be a number\"", ")", "\n", "}", "\n", "pwlen", "=", "iv", "\n", "}", "\n", "if", "pwlen", "<", "1", "{", "return", "\"\"", ",", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"password length must not be zero\"", ")", "\n", "}", "\n", "corp", ",", "err", ":=", "termio", ".", "AskForBool", "(", "ctx", ",", "\"Do you have strict rules to include different character classes?\"", ",", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "corp", "{", "return", "pwgen", ".", "GeneratePasswordWithAllClasses", "(", "pwlen", ")", "\n", "}", "\n", "return", "pwgen", ".", "GeneratePassword", "(", "pwlen", ",", "symbols", ")", ",", "nil", "\n", "}" ]
// generatePassword will run through the password generation steps
[ "generatePassword", "will", "run", "through", "the", "password", "generation", "steps" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L134-L174
train
gopasspw/gopass
pkg/action/generate.go
generatePasswordXKCD
func (s *Action) generatePasswordXKCD(ctx context.Context, c *cli.Context, length string) (string, error) { xkcdSeparator := " " if c.IsSet("xkcdsep") { xkcdSeparator = c.String("xkcdsep") } var pwlen int if length == "" { candidateLength := defaultXKCDLength question := "How many words should be combined to a password?" iv, err := termio.AskForInt(ctx, question, candidateLength) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number") } pwlen = iv } else { iv, err := strconv.Atoi(length) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number: %s", err) } pwlen = iv } if pwlen < 1 { return "", ExitError(ctx, ExitUsage, nil, "password length must not be zero") } return xkcdgen.RandomLengthDelim(pwlen, xkcdSeparator, c.String("xkcdlang")) }
go
func (s *Action) generatePasswordXKCD(ctx context.Context, c *cli.Context, length string) (string, error) { xkcdSeparator := " " if c.IsSet("xkcdsep") { xkcdSeparator = c.String("xkcdsep") } var pwlen int if length == "" { candidateLength := defaultXKCDLength question := "How many words should be combined to a password?" iv, err := termio.AskForInt(ctx, question, candidateLength) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number") } pwlen = iv } else { iv, err := strconv.Atoi(length) if err != nil { return "", ExitError(ctx, ExitUsage, err, "password length must be a number: %s", err) } pwlen = iv } if pwlen < 1 { return "", ExitError(ctx, ExitUsage, nil, "password length must not be zero") } return xkcdgen.RandomLengthDelim(pwlen, xkcdSeparator, c.String("xkcdlang")) }
[ "func", "(", "s", "*", "Action", ")", "generatePasswordXKCD", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ",", "length", "string", ")", "(", "string", ",", "error", ")", "{", "xkcdSeparator", ":=", "\" \"", "\n", "if", "c", ".", "IsSet", "(", "\"xkcdsep\"", ")", "{", "xkcdSeparator", "=", "c", ".", "String", "(", "\"xkcdsep\"", ")", "\n", "}", "\n", "var", "pwlen", "int", "\n", "if", "length", "==", "\"\"", "{", "candidateLength", ":=", "defaultXKCDLength", "\n", "question", ":=", "\"How many words should be combined to a password?\"", "\n", "iv", ",", "err", ":=", "termio", ".", "AskForInt", "(", "ctx", ",", "question", ",", "candidateLength", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "err", ",", "\"password length must be a number\"", ")", "\n", "}", "\n", "pwlen", "=", "iv", "\n", "}", "else", "{", "iv", ",", "err", ":=", "strconv", ".", "Atoi", "(", "length", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "err", ",", "\"password length must be a number: %s\"", ",", "err", ")", "\n", "}", "\n", "pwlen", "=", "iv", "\n", "}", "\n", "if", "pwlen", "<", "1", "{", "return", "\"\"", ",", "ExitError", "(", "ctx", ",", "ExitUsage", ",", "nil", ",", "\"password length must not be zero\"", ")", "\n", "}", "\n", "return", "xkcdgen", ".", "RandomLengthDelim", "(", "pwlen", ",", "xkcdSeparator", ",", "c", ".", "String", "(", "\"xkcdlang\"", ")", ")", "\n", "}" ]
// generatePasswordXKCD walks through the steps necessary to create an XKCD-style // password
[ "generatePasswordXKCD", "walks", "through", "the", "steps", "necessary", "to", "create", "an", "XKCD", "-", "style", "password" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L178-L206
train
gopasspw/gopass
pkg/action/generate.go
generateSetPassword
func (s *Action) generateSetPassword(ctx context.Context, name, key, password string, kvps map[string]string) (context.Context, error) { // set a single key in a yaml doc if key != "" { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) if err := sec.SetValue(key, password); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // replace password in existing secret if s.Store.Exists(ctx, name) { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) sec.SetPassword(password) if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // generate a completely new secret var err error sec := secret.New(password, "") if content, found := s.renderTemplate(ctx, name, []byte(password)); found { nSec, err := secret.Parse(content) if err == nil { sec = nSec } } ctx, err = s.Store.SetContext(sub.WithReason(ctx, "Generated Password"), name, sec) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to create '%s': %s", name, err) } return ctx, nil }
go
func (s *Action) generateSetPassword(ctx context.Context, name, key, password string, kvps map[string]string) (context.Context, error) { // set a single key in a yaml doc if key != "" { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) if err := sec.SetValue(key, password); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // replace password in existing secret if s.Store.Exists(ctx, name) { sec, ctx, err := s.Store.GetContext(ctx, name) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } setMetadata(sec, kvps) sec.SetPassword(password) if err := s.Store.Set(sub.WithReason(ctx, "Generated password for YAML key"), name, sec); err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set key '%s' of '%s': %s", key, name, err) } return ctx, nil } // generate a completely new secret var err error sec := secret.New(password, "") if content, found := s.renderTemplate(ctx, name, []byte(password)); found { nSec, err := secret.Parse(content) if err == nil { sec = nSec } } ctx, err = s.Store.SetContext(sub.WithReason(ctx, "Generated Password"), name, sec) if err != nil { return ctx, ExitError(ctx, ExitEncrypt, err, "failed to create '%s': %s", name, err) } return ctx, nil }
[ "func", "(", "s", "*", "Action", ")", "generateSetPassword", "(", "ctx", "context", ".", "Context", ",", "name", ",", "key", ",", "password", "string", ",", "kvps", "map", "[", "string", "]", "string", ")", "(", "context", ".", "Context", ",", "error", ")", "{", "if", "key", "!=", "\"\"", "{", "sec", ",", "ctx", ",", "err", ":=", "s", ".", "Store", ".", "GetContext", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"failed to set key '%s' of '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "setMetadata", "(", "sec", ",", "kvps", ")", "\n", "if", "err", ":=", "sec", ".", "SetValue", "(", "key", ",", "password", ")", ";", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"failed to set key '%s' of '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Set", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"Generated password for YAML key\"", ")", ",", "name", ",", "sec", ")", ";", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"failed to set key '%s' of '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ",", "nil", "\n", "}", "\n", "if", "s", ".", "Store", ".", "Exists", "(", "ctx", ",", "name", ")", "{", "sec", ",", "ctx", ",", "err", ":=", "s", ".", "Store", ".", "GetContext", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"failed to set key '%s' of '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "setMetadata", "(", "sec", ",", "kvps", ")", "\n", "sec", ".", "SetPassword", "(", "password", ")", "\n", "if", "err", ":=", "s", ".", "Store", ".", "Set", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"Generated password for YAML key\"", ")", ",", "name", ",", "sec", ")", ";", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"failed to set key '%s' of '%s': %s\"", ",", "key", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ",", "nil", "\n", "}", "\n", "var", "err", "error", "\n", "sec", ":=", "secret", ".", "New", "(", "password", ",", "\"\"", ")", "\n", "if", "content", ",", "found", ":=", "s", ".", "renderTemplate", "(", "ctx", ",", "name", ",", "[", "]", "byte", "(", "password", ")", ")", ";", "found", "{", "nSec", ",", "err", ":=", "secret", ".", "Parse", "(", "content", ")", "\n", "if", "err", "==", "nil", "{", "sec", "=", "nSec", "\n", "}", "\n", "}", "\n", "ctx", ",", "err", "=", "s", ".", "Store", ".", "SetContext", "(", "sub", ".", "WithReason", "(", "ctx", ",", "\"Generated Password\"", ")", ",", "name", ",", "sec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ctx", ",", "ExitError", "(", "ctx", ",", "ExitEncrypt", ",", "err", ",", "\"failed to create '%s': %s\"", ",", "name", ",", "err", ")", "\n", "}", "\n", "return", "ctx", ",", "nil", "\n", "}" ]
// generateSetPassword will update or create a secret
[ "generateSetPassword", "will", "update", "or", "create", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L209-L256
train
gopasspw/gopass
pkg/action/generate.go
CompleteGenerate
func (s *Action) CompleteGenerate(ctx context.Context, c *cli.Context) { args := c.Args() if len(args) < 1 { return } needle := args[0] _, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil if err != nil { out.Error(ctx, "Store not initialized: %s", err) return } list, err := s.Store.List(ctx, 0) if err != nil { return } if strings.Contains(needle, "/") { list = filterPrefix(uniq(extractEmails(list)), path.Base(needle)) } else { list = filterPrefix(uniq(extractDomains(list)), needle) } for _, v := range list { fmt.Fprintln(stdout, bashEscape(v)) } }
go
func (s *Action) CompleteGenerate(ctx context.Context, c *cli.Context) { args := c.Args() if len(args) < 1 { return } needle := args[0] _, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil if err != nil { out.Error(ctx, "Store not initialized: %s", err) return } list, err := s.Store.List(ctx, 0) if err != nil { return } if strings.Contains(needle, "/") { list = filterPrefix(uniq(extractEmails(list)), path.Base(needle)) } else { list = filterPrefix(uniq(extractDomains(list)), needle) } for _, v := range list { fmt.Fprintln(stdout, bashEscape(v)) } }
[ "func", "(", "s", "*", "Action", ")", "CompleteGenerate", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "{", "args", ":=", "c", ".", "Args", "(", ")", "\n", "if", "len", "(", "args", ")", "<", "1", "{", "return", "\n", "}", "\n", "needle", ":=", "args", "[", "0", "]", "\n", "_", ",", "err", ":=", "s", ".", "Store", ".", "Initialized", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Store not initialized: %s\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "list", ",", "err", ":=", "s", ".", "Store", ".", "List", "(", "ctx", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "needle", ",", "\"/\"", ")", "{", "list", "=", "filterPrefix", "(", "uniq", "(", "extractEmails", "(", "list", ")", ")", ",", "path", ".", "Base", "(", "needle", ")", ")", "\n", "}", "else", "{", "list", "=", "filterPrefix", "(", "uniq", "(", "extractDomains", "(", "list", ")", ")", ",", "needle", ")", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "list", "{", "fmt", ".", "Fprintln", "(", "stdout", ",", "bashEscape", "(", "v", ")", ")", "\n", "}", "\n", "}" ]
// CompleteGenerate implements the completion heuristic for the generate command
[ "CompleteGenerate", "implements", "the", "completion", "heuristic", "for", "the", "generate", "command" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/generate.go#L265-L291
train
gopasspw/gopass
pkg/editor/editor.go
Invoke
func Invoke(ctx context.Context, editor string, content []byte) ([]byte, error) { if !ctxutil.IsTerminal(ctx) { return nil, errors.New("need terminal") } tmpfile, err := tempfile.New(ctx, "gopass-edit") if err != nil { return []byte{}, errors.Errorf("failed to create tmpfile %s: %s", editor, err) } defer func() { if err := tmpfile.Remove(ctx); err != nil { color.Red("Failed to remove tempfile at %s: %s", tmpfile.Name(), err) } }() if _, err := tmpfile.Write(content); err != nil { return []byte{}, errors.Errorf("failed to write tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } if err := tmpfile.Close(); err != nil { return []byte{}, errors.Errorf("failed to close tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } cmdArgs, err := shellquote.Split(editor) if err != nil { return []byte{}, errors.Errorf("failed to parse EDITOR command `%s`", editor) } editor = cmdArgs[0] args := append(cmdArgs[1:], tmpfile.Name()) cmd := exec.Command(editor, args...) cmd.Stdin = Stdin cmd.Stdout = Stdout cmd.Stderr = Stderr if err := cmd.Run(); err != nil { out.Debug(ctx, "editor - cmd: %s %+v - error: %+v", cmd.Path, cmd.Args, err) return []byte{}, errors.Errorf("failed to run %s with %s file: %s", editor, tmpfile.Name(), err) } nContent, err := ioutil.ReadFile(tmpfile.Name()) if err != nil { return []byte{}, errors.Errorf("failed to read from tmpfile: %v", err) } // enforce unix line endings in the password store nContent = bytes.Replace(nContent, []byte("\r\n"), []byte("\n"), -1) nContent = bytes.Replace(nContent, []byte("\r"), []byte("\n"), -1) return nContent, nil }
go
func Invoke(ctx context.Context, editor string, content []byte) ([]byte, error) { if !ctxutil.IsTerminal(ctx) { return nil, errors.New("need terminal") } tmpfile, err := tempfile.New(ctx, "gopass-edit") if err != nil { return []byte{}, errors.Errorf("failed to create tmpfile %s: %s", editor, err) } defer func() { if err := tmpfile.Remove(ctx); err != nil { color.Red("Failed to remove tempfile at %s: %s", tmpfile.Name(), err) } }() if _, err := tmpfile.Write(content); err != nil { return []byte{}, errors.Errorf("failed to write tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } if err := tmpfile.Close(); err != nil { return []byte{}, errors.Errorf("failed to close tmpfile to start with %s %v: %s", editor, tmpfile.Name(), err) } cmdArgs, err := shellquote.Split(editor) if err != nil { return []byte{}, errors.Errorf("failed to parse EDITOR command `%s`", editor) } editor = cmdArgs[0] args := append(cmdArgs[1:], tmpfile.Name()) cmd := exec.Command(editor, args...) cmd.Stdin = Stdin cmd.Stdout = Stdout cmd.Stderr = Stderr if err := cmd.Run(); err != nil { out.Debug(ctx, "editor - cmd: %s %+v - error: %+v", cmd.Path, cmd.Args, err) return []byte{}, errors.Errorf("failed to run %s with %s file: %s", editor, tmpfile.Name(), err) } nContent, err := ioutil.ReadFile(tmpfile.Name()) if err != nil { return []byte{}, errors.Errorf("failed to read from tmpfile: %v", err) } // enforce unix line endings in the password store nContent = bytes.Replace(nContent, []byte("\r\n"), []byte("\n"), -1) nContent = bytes.Replace(nContent, []byte("\r"), []byte("\n"), -1) return nContent, nil }
[ "func", "Invoke", "(", "ctx", "context", ".", "Context", ",", "editor", "string", ",", "content", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "!", "ctxutil", ".", "IsTerminal", "(", "ctx", ")", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"need terminal\"", ")", "\n", "}", "\n", "tmpfile", ",", "err", ":=", "tempfile", ".", "New", "(", "ctx", ",", "\"gopass-edit\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"failed to create tmpfile %s: %s\"", ",", "editor", ",", "err", ")", "\n", "}", "\n", "defer", "func", "(", ")", "{", "if", "err", ":=", "tmpfile", ".", "Remove", "(", "ctx", ")", ";", "err", "!=", "nil", "{", "color", ".", "Red", "(", "\"Failed to remove tempfile at %s: %s\"", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n", "if", "_", ",", "err", ":=", "tmpfile", ".", "Write", "(", "content", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"failed to write tmpfile to start with %s %v: %s\"", ",", "editor", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "tmpfile", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"failed to close tmpfile to start with %s %v: %s\"", ",", "editor", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "cmdArgs", ",", "err", ":=", "shellquote", ".", "Split", "(", "editor", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"failed to parse EDITOR command `%s`\"", ",", "editor", ")", "\n", "}", "\n", "editor", "=", "cmdArgs", "[", "0", "]", "\n", "args", ":=", "append", "(", "cmdArgs", "[", "1", ":", "]", ",", "tmpfile", ".", "Name", "(", ")", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "editor", ",", "args", "...", ")", "\n", "cmd", ".", "Stdin", "=", "Stdin", "\n", "cmd", ".", "Stdout", "=", "Stdout", "\n", "cmd", ".", "Stderr", "=", "Stderr", "\n", "if", "err", ":=", "cmd", ".", "Run", "(", ")", ";", "err", "!=", "nil", "{", "out", ".", "Debug", "(", "ctx", ",", "\"editor - cmd: %s %+v - error: %+v\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ",", "err", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"failed to run %s with %s file: %s\"", ",", "editor", ",", "tmpfile", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "nContent", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "tmpfile", ".", "Name", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "errors", ".", "Errorf", "(", "\"failed to read from tmpfile: %v\"", ",", "err", ")", "\n", "}", "\n", "nContent", "=", "bytes", ".", "Replace", "(", "nContent", ",", "[", "]", "byte", "(", "\"\\r\\n\"", ")", ",", "\\r", ",", "\\n", ")", "\n", "[", "]", "byte", "(", "\"\\n\"", ")", "\n", "\\n", "\n", "}" ]
// Invoke will start the given editor and return the content
[ "Invoke", "will", "start", "the", "given", "editor", "and", "return", "the", "content" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/editor/editor.go#L30-L80
train
gopasspw/gopass
pkg/audit/audit.go
Batch
func Batch(ctx context.Context, secrets []string, secStore secretGetter) error { out.Print(ctx, "Checking %d secrets. This may take some time ...\n", len(secrets)) // Secrets that still need auditing. pending := make(chan string, 100) // Secrets that have been audited. checked := make(chan auditedSecret, 100) // Spawn workers that run the auditing of all secrets concurrently. validator := crunchy.NewValidator() maxJobs := runtime.NumCPU() done := make(chan struct{}, maxJobs) for jobs := 0; jobs < maxJobs; jobs++ { go audit(ctx, secStore, validator, pending, checked, done) } go func() { for _, secret := range secrets { pending <- secret } close(pending) }() go func() { for i := 0; i < maxJobs; i++ { <-done } close(checked) }() duplicates := make(map[string][]string) messages := make(map[string][]string) errors := make(map[string][]string) bar := &goprogressbar.ProgressBar{ Total: int64(len(secrets)), Width: 120, } if out.IsHidden(ctx) { old := goprogressbar.Stdout goprogressbar.Stdout = ioutil.Discard defer func() { goprogressbar.Stdout = old }() } i := 0 for secret := range checked { if secret.err != nil { errors[secret.err.Error()] = append(errors[secret.err.Error()], secret.name) } else { duplicates[secret.content] = append(duplicates[secret.content], secret.name) } if secret.message != "" { messages[secret.message] = append(messages[secret.message], secret.name) } i++ bar.Current = int64(i) bar.Text = fmt.Sprintf("%d of %d secrets checked", bar.Current, bar.Total) bar.LazyPrint() if i == len(secrets) { break } } fmt.Fprintln(goprogressbar.Stdout) // Print empty line after the progressbar. return auditPrintResults(ctx, duplicates, messages, errors) }
go
func Batch(ctx context.Context, secrets []string, secStore secretGetter) error { out.Print(ctx, "Checking %d secrets. This may take some time ...\n", len(secrets)) // Secrets that still need auditing. pending := make(chan string, 100) // Secrets that have been audited. checked := make(chan auditedSecret, 100) // Spawn workers that run the auditing of all secrets concurrently. validator := crunchy.NewValidator() maxJobs := runtime.NumCPU() done := make(chan struct{}, maxJobs) for jobs := 0; jobs < maxJobs; jobs++ { go audit(ctx, secStore, validator, pending, checked, done) } go func() { for _, secret := range secrets { pending <- secret } close(pending) }() go func() { for i := 0; i < maxJobs; i++ { <-done } close(checked) }() duplicates := make(map[string][]string) messages := make(map[string][]string) errors := make(map[string][]string) bar := &goprogressbar.ProgressBar{ Total: int64(len(secrets)), Width: 120, } if out.IsHidden(ctx) { old := goprogressbar.Stdout goprogressbar.Stdout = ioutil.Discard defer func() { goprogressbar.Stdout = old }() } i := 0 for secret := range checked { if secret.err != nil { errors[secret.err.Error()] = append(errors[secret.err.Error()], secret.name) } else { duplicates[secret.content] = append(duplicates[secret.content], secret.name) } if secret.message != "" { messages[secret.message] = append(messages[secret.message], secret.name) } i++ bar.Current = int64(i) bar.Text = fmt.Sprintf("%d of %d secrets checked", bar.Current, bar.Total) bar.LazyPrint() if i == len(secrets) { break } } fmt.Fprintln(goprogressbar.Stdout) // Print empty line after the progressbar. return auditPrintResults(ctx, duplicates, messages, errors) }
[ "func", "Batch", "(", "ctx", "context", ".", "Context", ",", "secrets", "[", "]", "string", ",", "secStore", "secretGetter", ")", "error", "{", "out", ".", "Print", "(", "ctx", ",", "\"Checking %d secrets. This may take some time ...\\n\"", ",", "\\n", ")", "\n", "len", "(", "secrets", ")", "\n", "pending", ":=", "make", "(", "chan", "string", ",", "100", ")", "\n", "checked", ":=", "make", "(", "chan", "auditedSecret", ",", "100", ")", "\n", "validator", ":=", "crunchy", ".", "NewValidator", "(", ")", "\n", "maxJobs", ":=", "runtime", ".", "NumCPU", "(", ")", "\n", "done", ":=", "make", "(", "chan", "struct", "{", "}", ",", "maxJobs", ")", "\n", "for", "jobs", ":=", "0", ";", "jobs", "<", "maxJobs", ";", "jobs", "++", "{", "go", "audit", "(", "ctx", ",", "secStore", ",", "validator", ",", "pending", ",", "checked", ",", "done", ")", "\n", "}", "\n", "go", "func", "(", ")", "{", "for", "_", ",", "secret", ":=", "range", "secrets", "{", "pending", "<-", "secret", "\n", "}", "\n", "close", "(", "pending", ")", "\n", "}", "(", ")", "\n", "go", "func", "(", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "maxJobs", ";", "i", "++", "{", "<-", "done", "\n", "}", "\n", "close", "(", "checked", ")", "\n", "}", "(", ")", "\n", "duplicates", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "messages", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "errors", ":=", "make", "(", "map", "[", "string", "]", "[", "]", "string", ")", "\n", "bar", ":=", "&", "goprogressbar", ".", "ProgressBar", "{", "Total", ":", "int64", "(", "len", "(", "secrets", ")", ")", ",", "Width", ":", "120", ",", "}", "\n", "if", "out", ".", "IsHidden", "(", "ctx", ")", "{", "old", ":=", "goprogressbar", ".", "Stdout", "\n", "goprogressbar", ".", "Stdout", "=", "ioutil", ".", "Discard", "\n", "defer", "func", "(", ")", "{", "goprogressbar", ".", "Stdout", "=", "old", "\n", "}", "(", ")", "\n", "}", "\n", "i", ":=", "0", "\n", "for", "secret", ":=", "range", "checked", "{", "if", "secret", ".", "err", "!=", "nil", "{", "errors", "[", "secret", ".", "err", ".", "Error", "(", ")", "]", "=", "append", "(", "errors", "[", "secret", ".", "err", ".", "Error", "(", ")", "]", ",", "secret", ".", "name", ")", "\n", "}", "else", "{", "duplicates", "[", "secret", ".", "content", "]", "=", "append", "(", "duplicates", "[", "secret", ".", "content", "]", ",", "secret", ".", "name", ")", "\n", "}", "\n", "if", "secret", ".", "message", "!=", "\"\"", "{", "messages", "[", "secret", ".", "message", "]", "=", "append", "(", "messages", "[", "secret", ".", "message", "]", ",", "secret", ".", "name", ")", "\n", "}", "\n", "i", "++", "\n", "bar", ".", "Current", "=", "int64", "(", "i", ")", "\n", "bar", ".", "Text", "=", "fmt", ".", "Sprintf", "(", "\"%d of %d secrets checked\"", ",", "bar", ".", "Current", ",", "bar", ".", "Total", ")", "\n", "bar", ".", "LazyPrint", "(", ")", "\n", "if", "i", "==", "len", "(", "secrets", ")", "{", "break", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "goprogressbar", ".", "Stdout", ")", "\n", "}" ]
// Batch runs a password strength audit on multiple secrets
[ "Batch", "runs", "a", "password", "strength", "audit", "on", "multiple", "secrets" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/audit/audit.go#L39-L108
train
gopasspw/gopass
pkg/audit/audit.go
Single
func Single(ctx context.Context, password string) { validator := crunchy.NewValidator() if err := validator.Check(password); err != nil { out.Cyan(ctx, fmt.Sprintf("Warning: %s", err)) } }
go
func Single(ctx context.Context, password string) { validator := crunchy.NewValidator() if err := validator.Check(password); err != nil { out.Cyan(ctx, fmt.Sprintf("Warning: %s", err)) } }
[ "func", "Single", "(", "ctx", "context", ".", "Context", ",", "password", "string", ")", "{", "validator", ":=", "crunchy", ".", "NewValidator", "(", ")", "\n", "if", "err", ":=", "validator", ".", "Check", "(", "password", ")", ";", "err", "!=", "nil", "{", "out", ".", "Cyan", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Warning: %s\"", ",", "err", ")", ")", "\n", "}", "\n", "}" ]
// Single runs a password strength audit on a single password
[ "Single", "runs", "a", "password", "strength", "audit", "on", "a", "single", "password" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/audit/audit.go#L155-L160
train
gopasspw/gopass
pkg/store/vault/secret.go
Bytes
func (s *Secret) Bytes() ([]byte, error) { if s.d == nil { return []byte{}, nil } buf := &bytes.Buffer{} if pw, found := s.d[passwordKey]; found { if sv, ok := pw.(string); ok { _, _ = buf.WriteString(sv) } } _, _ = buf.WriteString("\n") keys := make([]string, 0, len(s.d)) for k := range s.d { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { v := s.d[k] if k == passwordKey { continue } _, _ = buf.WriteString(k) _, _ = buf.WriteString(": ") if sv, ok := v.(string); ok { _, _ = buf.WriteString(sv) } _, _ = buf.WriteString("\n") } return buf.Bytes(), nil }
go
func (s *Secret) Bytes() ([]byte, error) { if s.d == nil { return []byte{}, nil } buf := &bytes.Buffer{} if pw, found := s.d[passwordKey]; found { if sv, ok := pw.(string); ok { _, _ = buf.WriteString(sv) } } _, _ = buf.WriteString("\n") keys := make([]string, 0, len(s.d)) for k := range s.d { keys = append(keys, k) } sort.Strings(keys) for _, k := range keys { v := s.d[k] if k == passwordKey { continue } _, _ = buf.WriteString(k) _, _ = buf.WriteString(": ") if sv, ok := v.(string); ok { _, _ = buf.WriteString(sv) } _, _ = buf.WriteString("\n") } return buf.Bytes(), nil }
[ "func", "(", "s", "*", "Secret", ")", "Bytes", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "s", ".", "d", "==", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "nil", "\n", "}", "\n", "buf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "if", "pw", ",", "found", ":=", "s", ".", "d", "[", "passwordKey", "]", ";", "found", "{", "if", "sv", ",", "ok", ":=", "pw", ".", "(", "string", ")", ";", "ok", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "sv", ")", "\n", "}", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"\\n\"", ")", "\n", "\\n", "\n", "keys", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "s", ".", "d", ")", ")", "\n", "for", "k", ":=", "range", "s", ".", "d", "{", "keys", "=", "append", "(", "keys", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "keys", ")", "\n", "for", "_", ",", "k", ":=", "range", "keys", "{", "v", ":=", "s", ".", "d", "[", "k", "]", "\n", "if", "k", "==", "passwordKey", "{", "continue", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "k", ")", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\": \"", ")", "\n", "if", "sv", ",", "ok", ":=", "v", ".", "(", "string", ")", ";", "ok", "{", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "sv", ")", "\n", "}", "\n", "_", ",", "_", "=", "buf", ".", "WriteString", "(", "\"\\n\"", ")", "\n", "}", "\n", "}" ]
// Bytes returns a list serialized copy of this secret
[ "Bytes", "returns", "a", "list", "serialized", "copy", "of", "this", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L23-L53
train
gopasspw/gopass
pkg/store/vault/secret.go
Data
func (s *Secret) Data() map[string]interface{} { if s.d == nil { s.d = make(map[string]interface{}) } return s.d }
go
func (s *Secret) Data() map[string]interface{} { if s.d == nil { s.d = make(map[string]interface{}) } return s.d }
[ "func", "(", "s", "*", "Secret", ")", "Data", "(", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "if", "s", ".", "d", "==", "nil", "{", "s", ".", "d", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "}", "\n", "return", "s", ".", "d", "\n", "}" ]
// Data returns the data map. Will never be nil
[ "Data", "returns", "the", "data", "map", ".", "Will", "never", "be", "nil" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L56-L61
train
gopasspw/gopass
pkg/store/vault/secret.go
DeleteKey
func (s *Secret) DeleteKey(key string) error { if s.d == nil { return nil } delete(s.d, key) return nil }
go
func (s *Secret) DeleteKey(key string) error { if s.d == nil { return nil } delete(s.d, key) return nil }
[ "func", "(", "s", "*", "Secret", ")", "DeleteKey", "(", "key", "string", ")", "error", "{", "if", "s", ".", "d", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "delete", "(", "s", ".", "d", ",", "key", ")", "\n", "return", "nil", "\n", "}" ]
// DeleteKey removes a single key
[ "DeleteKey", "removes", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L64-L70
train
gopasspw/gopass
pkg/store/vault/secret.go
Equal
func (s *Secret) Equal(other store.Secret) bool { b1, err := s.Bytes() if err != nil { return false } b2, err := other.Bytes() if err != nil { return false } return string(b1) == string(b2) }
go
func (s *Secret) Equal(other store.Secret) bool { b1, err := s.Bytes() if err != nil { return false } b2, err := other.Bytes() if err != nil { return false } return string(b1) == string(b2) }
[ "func", "(", "s", "*", "Secret", ")", "Equal", "(", "other", "store", ".", "Secret", ")", "bool", "{", "b1", ",", "err", ":=", "s", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "b2", ",", "err", ":=", "other", ".", "Bytes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "string", "(", "b1", ")", "==", "string", "(", "b2", ")", "\n", "}" ]
// Equal returns true if two secrets match
[ "Equal", "returns", "true", "if", "two", "secrets", "match" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L73-L83
train
gopasspw/gopass
pkg/store/vault/secret.go
Password
func (s *Secret) Password() string { v := s.d[passwordKey] if sv, ok := v.(string); ok { return sv } return "" }
go
func (s *Secret) Password() string { v := s.d[passwordKey] if sv, ok := v.(string); ok { return sv } return "" }
[ "func", "(", "s", "*", "Secret", ")", "Password", "(", ")", "string", "{", "v", ":=", "s", ".", "d", "[", "passwordKey", "]", "\n", "if", "sv", ",", "ok", ":=", "v", ".", "(", "string", ")", ";", "ok", "{", "return", "sv", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// Password returns the password
[ "Password", "returns", "the", "password" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L86-L92
train
gopasspw/gopass
pkg/store/vault/secret.go
SetValue
func (s *Secret) SetValue(key string, value string) error { s.d[key] = value return nil }
go
func (s *Secret) SetValue(key string, value string) error { s.d[key] = value return nil }
[ "func", "(", "s", "*", "Secret", ")", "SetValue", "(", "key", "string", ",", "value", "string", ")", "error", "{", "s", ".", "d", "[", "key", "]", "=", "value", "\n", "return", "nil", "\n", "}" ]
// SetValue sets a single key
[ "SetValue", "sets", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L105-L108
train
gopasspw/gopass
pkg/store/vault/secret.go
Value
func (s *Secret) Value(key string) (string, error) { v := s.d[key] if sv, ok := v.(string); ok { return sv, nil } return "", nil }
go
func (s *Secret) Value(key string) (string, error) { v := s.d[key] if sv, ok := v.(string); ok { return sv, nil } return "", nil }
[ "func", "(", "s", "*", "Secret", ")", "Value", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "v", ":=", "s", ".", "d", "[", "key", "]", "\n", "if", "sv", ",", "ok", ":=", "v", ".", "(", "string", ")", ";", "ok", "{", "return", "sv", ",", "nil", "\n", "}", "\n", "return", "\"\"", ",", "nil", "\n", "}" ]
// Value returns a single value
[ "Value", "returns", "a", "single", "value" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/vault/secret.go#L137-L143
train
gopasspw/gopass
pkg/store/sub/init.go
Initialized
func (s *Store) Initialized(ctx context.Context) bool { if s == nil || s.storage == nil { return false } return s.storage.Exists(ctx, s.idFile(ctx, "")) }
go
func (s *Store) Initialized(ctx context.Context) bool { if s == nil || s.storage == nil { return false } return s.storage.Exists(ctx, s.idFile(ctx, "")) }
[ "func", "(", "s", "*", "Store", ")", "Initialized", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "if", "s", "==", "nil", "||", "s", ".", "storage", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "s", ".", "storage", ".", "Exists", "(", "ctx", ",", "s", ".", "idFile", "(", "ctx", ",", "\"\"", ")", ")", "\n", "}" ]
// Initialized returns true if the store is properly initialized
[ "Initialized", "returns", "true", "if", "the", "store", "is", "properly", "initialized" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/init.go#L13-L18
train
gopasspw/gopass
pkg/store/root/list.go
List
func (r *Store) List(ctx context.Context, maxDepth int) ([]string, error) { t, err := r.Tree(ctx) if err != nil { return []string{}, err } return t.List(maxDepth), nil }
go
func (r *Store) List(ctx context.Context, maxDepth int) ([]string, error) { t, err := r.Tree(ctx) if err != nil { return []string{}, err } return t.List(maxDepth), nil }
[ "func", "(", "r", "*", "Store", ")", "List", "(", "ctx", "context", ".", "Context", ",", "maxDepth", "int", ")", "(", "[", "]", "string", ",", "error", ")", "{", "t", ",", "err", ":=", "r", ".", "Tree", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "return", "t", ".", "List", "(", "maxDepth", ")", ",", "nil", "\n", "}" ]
// List will return a flattened list of all tree entries
[ "List", "will", "return", "a", "flattened", "list", "of", "all", "tree", "entries" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/list.go#L17-L23
train
gopasspw/gopass
pkg/store/root/list.go
Tree
func (r *Store) Tree(ctx context.Context) (tree.Tree, error) { root := simple.New("gopass") addFileFunc := func(in ...string) { for _, f := range in { var ct string switch { case strings.HasSuffix(f, ".b64"): ct = "application/octet-stream" case strings.HasSuffix(f, ".yml"): ct = "text/yaml" case strings.HasSuffix(f, ".yaml"): ct = "text/yaml" default: ct = "text/plain" } if err := root.AddFile(f, ct); err != nil { out.Error(ctx, "Failed to add file %s to tree: %s", f, err) continue } } } addTplFunc := func(in ...string) { for _, f := range in { if err := root.AddTemplate(f); err != nil { out.Error(ctx, "Failed to add template %s to tree: %s", f, err) continue } } } sf, err := r.store.List(ctx, "") if err != nil { return nil, err } addFileFunc(sf...) addTplFunc(r.store.ListTemplates(ctx, "")...) mps := r.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { substore := r.mounts[alias] if substore == nil { continue } if err := root.AddMount(alias, substore.Path()); err != nil { return nil, errors.Errorf("failed to add mount: %s", err) } sf, err := substore.List(ctx, "") if err != nil { return nil, errors.Errorf("failed to add file: %s", err) } addFileFunc(sf...) addTplFunc(substore.ListTemplates(ctx, alias)...) } return root, nil }
go
func (r *Store) Tree(ctx context.Context) (tree.Tree, error) { root := simple.New("gopass") addFileFunc := func(in ...string) { for _, f := range in { var ct string switch { case strings.HasSuffix(f, ".b64"): ct = "application/octet-stream" case strings.HasSuffix(f, ".yml"): ct = "text/yaml" case strings.HasSuffix(f, ".yaml"): ct = "text/yaml" default: ct = "text/plain" } if err := root.AddFile(f, ct); err != nil { out.Error(ctx, "Failed to add file %s to tree: %s", f, err) continue } } } addTplFunc := func(in ...string) { for _, f := range in { if err := root.AddTemplate(f); err != nil { out.Error(ctx, "Failed to add template %s to tree: %s", f, err) continue } } } sf, err := r.store.List(ctx, "") if err != nil { return nil, err } addFileFunc(sf...) addTplFunc(r.store.ListTemplates(ctx, "")...) mps := r.MountPoints() sort.Sort(store.ByPathLen(mps)) for _, alias := range mps { substore := r.mounts[alias] if substore == nil { continue } if err := root.AddMount(alias, substore.Path()); err != nil { return nil, errors.Errorf("failed to add mount: %s", err) } sf, err := substore.List(ctx, "") if err != nil { return nil, errors.Errorf("failed to add file: %s", err) } addFileFunc(sf...) addTplFunc(substore.ListTemplates(ctx, alias)...) } return root, nil }
[ "func", "(", "r", "*", "Store", ")", "Tree", "(", "ctx", "context", ".", "Context", ")", "(", "tree", ".", "Tree", ",", "error", ")", "{", "root", ":=", "simple", ".", "New", "(", "\"gopass\"", ")", "\n", "addFileFunc", ":=", "func", "(", "in", "...", "string", ")", "{", "for", "_", ",", "f", ":=", "range", "in", "{", "var", "ct", "string", "\n", "switch", "{", "case", "strings", ".", "HasSuffix", "(", "f", ",", "\".b64\"", ")", ":", "ct", "=", "\"application/octet-stream\"", "\n", "case", "strings", ".", "HasSuffix", "(", "f", ",", "\".yml\"", ")", ":", "ct", "=", "\"text/yaml\"", "\n", "case", "strings", ".", "HasSuffix", "(", "f", ",", "\".yaml\"", ")", ":", "ct", "=", "\"text/yaml\"", "\n", "default", ":", "ct", "=", "\"text/plain\"", "\n", "}", "\n", "if", "err", ":=", "root", ".", "AddFile", "(", "f", ",", "ct", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Failed to add file %s to tree: %s\"", ",", "f", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "}", "\n", "addTplFunc", ":=", "func", "(", "in", "...", "string", ")", "{", "for", "_", ",", "f", ":=", "range", "in", "{", "if", "err", ":=", "root", ".", "AddTemplate", "(", "f", ")", ";", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"Failed to add template %s to tree: %s\"", ",", "f", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "}", "\n", "sf", ",", "err", ":=", "r", ".", "store", ".", "List", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "addFileFunc", "(", "sf", "...", ")", "\n", "addTplFunc", "(", "r", ".", "store", ".", "ListTemplates", "(", "ctx", ",", "\"\"", ")", "...", ")", "\n", "mps", ":=", "r", ".", "MountPoints", "(", ")", "\n", "sort", ".", "Sort", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", "\n", "for", "_", ",", "alias", ":=", "range", "mps", "{", "substore", ":=", "r", ".", "mounts", "[", "alias", "]", "\n", "if", "substore", "==", "nil", "{", "continue", "\n", "}", "\n", "if", "err", ":=", "root", ".", "AddMount", "(", "alias", ",", "substore", ".", "Path", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"failed to add mount: %s\"", ",", "err", ")", "\n", "}", "\n", "sf", ",", "err", ":=", "substore", ".", "List", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"failed to add file: %s\"", ",", "err", ")", "\n", "}", "\n", "addFileFunc", "(", "sf", "...", ")", "\n", "addTplFunc", "(", "substore", ".", "ListTemplates", "(", "ctx", ",", "alias", ")", "...", ")", "\n", "}", "\n", "return", "root", ",", "nil", "\n", "}" ]
// Tree returns the tree representation of the entries
[ "Tree", "returns", "the", "tree", "representation", "of", "the", "entries" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/list.go#L26-L82
train
gopasspw/gopass
pkg/action/hibp.go
HIBP
func (s *Action) HIBP(ctx context.Context, c *cli.Context) error { force := c.Bool("force") api := c.Bool("api") if api { return s.hibpAPI(ctx, force) } out.Yellow(ctx, "WARNING: Using the HIBPv2 dumps is very expensive. If you can condone leaking a few bits of entropy per secret you should probably use the '--api' flag.") dumps := c.StringSlice("dumps") return s.hibpDump(ctx, force, dumps) }
go
func (s *Action) HIBP(ctx context.Context, c *cli.Context) error { force := c.Bool("force") api := c.Bool("api") if api { return s.hibpAPI(ctx, force) } out.Yellow(ctx, "WARNING: Using the HIBPv2 dumps is very expensive. If you can condone leaking a few bits of entropy per secret you should probably use the '--api' flag.") dumps := c.StringSlice("dumps") return s.hibpDump(ctx, force, dumps) }
[ "func", "(", "s", "*", "Action", ")", "HIBP", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "force", ":=", "c", ".", "Bool", "(", "\"force\"", ")", "\n", "api", ":=", "c", ".", "Bool", "(", "\"api\"", ")", "\n", "if", "api", "{", "return", "s", ".", "hibpAPI", "(", "ctx", ",", "force", ")", "\n", "}", "\n", "out", ".", "Yellow", "(", "ctx", ",", "\"WARNING: Using the HIBPv2 dumps is very expensive. If you can condone leaking a few bits of entropy per secret you should probably use the '--api' flag.\"", ")", "\n", "dumps", ":=", "c", ".", "StringSlice", "(", "\"dumps\"", ")", "\n", "return", "s", ".", "hibpDump", "(", "ctx", ",", "force", ",", "dumps", ")", "\n", "}" ]
// HIBP compares all entries from the store against the provided SHA1 sum dumps
[ "HIBP", "compares", "all", "entries", "from", "the", "store", "against", "the", "provided", "SHA1", "sum", "dumps" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/hibp.go#L22-L34
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
RecipientIDs
func (x *XC) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { msg := &xcpb.Message{} if err := proto.Unmarshal(ciphertext, msg); err != nil { return nil, err } ids := make([]string, 0, len(msg.Header.Recipients)) for k := range msg.Header.Recipients { ids = append(ids, k) } sort.Strings(ids) return ids, nil }
go
func (x *XC) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) { msg := &xcpb.Message{} if err := proto.Unmarshal(ciphertext, msg); err != nil { return nil, err } ids := make([]string, 0, len(msg.Header.Recipients)) for k := range msg.Header.Recipients { ids = append(ids, k) } sort.Strings(ids) return ids, nil }
[ "func", "(", "x", "*", "XC", ")", "RecipientIDs", "(", "ctx", "context", ".", "Context", ",", "ciphertext", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "msg", ":=", "&", "xcpb", ".", "Message", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "ciphertext", ",", "msg", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "msg", ".", "Header", ".", "Recipients", ")", ")", "\n", "for", "k", ":=", "range", "msg", ".", "Header", ".", "Recipients", "{", "ids", "=", "append", "(", "ids", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ids", ")", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// RecipientIDs reads the header of the given file and extracts the // recipients IDs
[ "RecipientIDs", "reads", "the", "header", "of", "the", "given", "file", "and", "extracts", "the", "recipients", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L18-L30
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
ReadNamesFromKey
func (x *XC) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal public key: %s", err) } return []string{pk.Identity.Name}, nil }
go
func (x *XC) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return nil, errors.Wrapf(err, "failed to unmarshal public key: %s", err) } return []string{pk.Identity.Name}, nil }
[ "func", "(", "x", "*", "XC", ")", "ReadNamesFromKey", "(", "ctx", "context", ".", "Context", ",", "buf", "[", "]", "byte", ")", "(", "[", "]", "string", ",", "error", ")", "{", "pk", ":=", "&", "xcpb", ".", "PublicKey", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "pk", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to unmarshal public key: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "[", "]", "string", "{", "pk", ".", "Identity", ".", "Name", "}", ",", "nil", "\n", "}" ]
// ReadNamesFromKey unmarshals the given public key and returns the identities name
[ "ReadNamesFromKey", "unmarshals", "the", "given", "public", "key", "and", "returns", "the", "identities", "name" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L33-L40
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
ListPublicKeyIDs
func (x *XC) ListPublicKeyIDs(ctx context.Context) ([]string, error) { return x.pubring.KeyIDs(), nil }
go
func (x *XC) ListPublicKeyIDs(ctx context.Context) ([]string, error) { return x.pubring.KeyIDs(), nil }
[ "func", "(", "x", "*", "XC", ")", "ListPublicKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "x", ".", "pubring", ".", "KeyIDs", "(", ")", ",", "nil", "\n", "}" ]
// ListPublicKeyIDs lists all public key IDs
[ "ListPublicKeyIDs", "lists", "all", "public", "key", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L43-L45
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
ListPrivateKeyIDs
func (x *XC) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { return x.secring.KeyIDs(), nil }
go
func (x *XC) ListPrivateKeyIDs(ctx context.Context) ([]string, error) { return x.secring.KeyIDs(), nil }
[ "func", "(", "x", "*", "XC", ")", "ListPrivateKeyIDs", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "x", ".", "secring", ".", "KeyIDs", "(", ")", ",", "nil", "\n", "}" ]
// ListPrivateKeyIDs lists all private key IDs
[ "ListPrivateKeyIDs", "lists", "all", "private", "key", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L48-L50
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
FindPublicKeys
func (x *XC) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { ids := make([]string, 0, 1) candidates, _ := x.ListPublicKeyIDs(ctx) for _, needle := range search { for _, fp := range candidates { if strings.HasSuffix(fp, needle) { ids = append(ids, fp) } } } sort.Strings(ids) return ids, nil }
go
func (x *XC) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) { ids := make([]string, 0, 1) candidates, _ := x.ListPublicKeyIDs(ctx) for _, needle := range search { for _, fp := range candidates { if strings.HasSuffix(fp, needle) { ids = append(ids, fp) } } } sort.Strings(ids) return ids, nil }
[ "func", "(", "x", "*", "XC", ")", "FindPublicKeys", "(", "ctx", "context", ".", "Context", ",", "search", "...", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "1", ")", "\n", "candidates", ",", "_", ":=", "x", ".", "ListPublicKeyIDs", "(", "ctx", ")", "\n", "for", "_", ",", "needle", ":=", "range", "search", "{", "for", "_", ",", "fp", ":=", "range", "candidates", "{", "if", "strings", ".", "HasSuffix", "(", "fp", ",", "needle", ")", "{", "ids", "=", "append", "(", "ids", ",", "fp", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "sort", ".", "Strings", "(", "ids", ")", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// FindPublicKeys finds all matching public keys
[ "FindPublicKeys", "finds", "all", "matching", "public", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L53-L65
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
FormatKey
func (x *XC) FormatKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return id + " - " + key.Identity.ID() } if key := x.secring.Get(id); key != nil { return id + " - " + key.PublicKey.Identity.ID() } return id }
go
func (x *XC) FormatKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return id + " - " + key.Identity.ID() } if key := x.secring.Get(id); key != nil { return id + " - " + key.PublicKey.Identity.ID() } return id }
[ "func", "(", "x", "*", "XC", ")", "FormatKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "if", "key", ":=", "x", ".", "pubring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "id", "+", "\" - \"", "+", "key", ".", "Identity", ".", "ID", "(", ")", "\n", "}", "\n", "if", "key", ":=", "x", ".", "secring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "id", "+", "\" - \"", "+", "key", ".", "PublicKey", ".", "Identity", ".", "ID", "(", ")", "\n", "}", "\n", "return", "id", "\n", "}" ]
// FormatKey formats a key
[ "FormatKey", "formats", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L83-L91
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
NameFromKey
func (x *XC) NameFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Name } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Name } return id }
go
func (x *XC) NameFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Name } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Name } return id }
[ "func", "(", "x", "*", "XC", ")", "NameFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "if", "key", ":=", "x", ".", "pubring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "Identity", ".", "Name", "\n", "}", "\n", "if", "key", ":=", "x", ".", "secring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "PublicKey", ".", "Identity", ".", "Name", "\n", "}", "\n", "return", "id", "\n", "}" ]
// NameFromKey extracts the name from a key
[ "NameFromKey", "extracts", "the", "name", "from", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L94-L102
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
EmailFromKey
func (x *XC) EmailFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Email } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Email } return id }
go
func (x *XC) EmailFromKey(ctx context.Context, id string) string { if key := x.pubring.Get(id); key != nil { return key.Identity.Email } if key := x.secring.Get(id); key != nil { return key.PublicKey.Identity.Email } return id }
[ "func", "(", "x", "*", "XC", ")", "EmailFromKey", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "string", "{", "if", "key", ":=", "x", ".", "pubring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "Identity", ".", "Email", "\n", "}", "\n", "if", "key", ":=", "x", ".", "secring", ".", "Get", "(", "id", ")", ";", "key", "!=", "nil", "{", "return", "key", ".", "PublicKey", ".", "Identity", ".", "Email", "\n", "}", "\n", "return", "id", "\n", "}" ]
// EmailFromKey extracts the email from a key
[ "EmailFromKey", "extracts", "the", "email", "from", "a", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L105-L113
train
gopasspw/gopass
pkg/backend/crypto/xc/utils.go
CreatePrivateKeyBatch
func (x *XC) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error { k, err := keyring.GenerateKeypair(passphrase) if err != nil { return errors.Wrapf(err, "failed to generate keypair: %s", err) } k.Identity.Name = name k.Identity.Email = email if err := x.secring.Set(k); err != nil { return errors.Wrapf(err, "failed to set %v to secring: %s", k, err) } return x.secring.Save() }
go
func (x *XC) CreatePrivateKeyBatch(ctx context.Context, name, email, passphrase string) error { k, err := keyring.GenerateKeypair(passphrase) if err != nil { return errors.Wrapf(err, "failed to generate keypair: %s", err) } k.Identity.Name = name k.Identity.Email = email if err := x.secring.Set(k); err != nil { return errors.Wrapf(err, "failed to set %v to secring: %s", k, err) } return x.secring.Save() }
[ "func", "(", "x", "*", "XC", ")", "CreatePrivateKeyBatch", "(", "ctx", "context", ".", "Context", ",", "name", ",", "email", ",", "passphrase", "string", ")", "error", "{", "k", ",", "err", ":=", "keyring", ".", "GenerateKeypair", "(", "passphrase", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to generate keypair: %s\"", ",", "err", ")", "\n", "}", "\n", "k", ".", "Identity", ".", "Name", "=", "name", "\n", "k", ".", "Identity", ".", "Email", "=", "email", "\n", "if", "err", ":=", "x", ".", "secring", ".", "Set", "(", "k", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to set %v to secring: %s\"", ",", "k", ",", "err", ")", "\n", "}", "\n", "return", "x", ".", "secring", ".", "Save", "(", ")", "\n", "}" ]
// CreatePrivateKeyBatch creates a new keypair
[ "CreatePrivateKeyBatch", "creates", "a", "new", "keypair" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/utils.go#L121-L132
train
gopasspw/gopass
pkg/backend/crypto/gpg/context.go
WithAlwaysTrust
func WithAlwaysTrust(ctx context.Context, at bool) context.Context { return context.WithValue(ctx, ctxKeyAlwaysTrust, at) }
go
func WithAlwaysTrust(ctx context.Context, at bool) context.Context { return context.WithValue(ctx, ctxKeyAlwaysTrust, at) }
[ "func", "WithAlwaysTrust", "(", "ctx", "context", ".", "Context", ",", "at", "bool", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "ctxKeyAlwaysTrust", ",", "at", ")", "\n", "}" ]
// WithAlwaysTrust will return a context with the flag for always trust set
[ "WithAlwaysTrust", "will", "return", "a", "context", "with", "the", "flag", "for", "always", "trust", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/context.go#L12-L14
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
NewPubring
func NewPubring(sec *Secring) *Pubring { return &Pubring{ data: &xcpb.Pubring{ PublicKeys: make([]*xcpb.PublicKey, 0, 10), }, secring: sec, } }
go
func NewPubring(sec *Secring) *Pubring { return &Pubring{ data: &xcpb.Pubring{ PublicKeys: make([]*xcpb.PublicKey, 0, 10), }, secring: sec, } }
[ "func", "NewPubring", "(", "sec", "*", "Secring", ")", "*", "Pubring", "{", "return", "&", "Pubring", "{", "data", ":", "&", "xcpb", ".", "Pubring", "{", "PublicKeys", ":", "make", "(", "[", "]", "*", "xcpb", ".", "PublicKey", ",", "0", ",", "10", ")", ",", "}", ",", "secring", ":", "sec", ",", "}", "\n", "}" ]
// NewPubring initializes a new public key ring
[ "NewPubring", "initializes", "a", "new", "public", "key", "ring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L27-L34
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
LoadPubring
func LoadPubring(file string, sec *Secring) (*Pubring, error) { pr := NewPubring(sec) pr.File = file buf, err := ioutil.ReadFile(file) if os.IsNotExist(err) { return pr, nil } if err != nil { return nil, err } if err := proto.Unmarshal(buf, pr.data); err != nil { return nil, err } return pr, nil }
go
func LoadPubring(file string, sec *Secring) (*Pubring, error) { pr := NewPubring(sec) pr.File = file buf, err := ioutil.ReadFile(file) if os.IsNotExist(err) { return pr, nil } if err != nil { return nil, err } if err := proto.Unmarshal(buf, pr.data); err != nil { return nil, err } return pr, nil }
[ "func", "LoadPubring", "(", "file", "string", ",", "sec", "*", "Secring", ")", "(", "*", "Pubring", ",", "error", ")", "{", "pr", ":=", "NewPubring", "(", "sec", ")", "\n", "pr", ".", "File", "=", "file", "\n", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "file", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "pr", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "pr", ".", "data", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "pr", ",", "nil", "\n", "}" ]
// LoadPubring loads an existing keyring from disk. If the file is not // found an empty keyring is returned.
[ "LoadPubring", "loads", "an", "existing", "keyring", "from", "disk", ".", "If", "the", "file", "is", "not", "found", "an", "empty", "keyring", "is", "returned", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L38-L55
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Contains
func (p *Pubring) Contains(fp string) bool { p.Lock() defer p.Unlock() for _, pk := range p.data.PublicKeys { if pk.Fingerprint == fp { return true } } if p.secring == nil { return false } return p.secring.Contains(fp) }
go
func (p *Pubring) Contains(fp string) bool { p.Lock() defer p.Unlock() for _, pk := range p.data.PublicKeys { if pk.Fingerprint == fp { return true } } if p.secring == nil { return false } return p.secring.Contains(fp) }
[ "func", "(", "p", "*", "Pubring", ")", "Contains", "(", "fp", "string", ")", "bool", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "pk", ":=", "range", "p", ".", "data", ".", "PublicKeys", "{", "if", "pk", ".", "Fingerprint", "==", "fp", "{", "return", "true", "\n", "}", "\n", "}", "\n", "if", "p", ".", "secring", "==", "nil", "{", "return", "false", "\n", "}", "\n", "return", "p", ".", "secring", ".", "Contains", "(", "fp", ")", "\n", "}" ]
// Contains checks if a given key is in the keyring
[ "Contains", "checks", "if", "a", "given", "key", "is", "in", "the", "keyring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L67-L82
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
KeyIDs
func (p *Pubring) KeyIDs() []string { p.Lock() defer p.Unlock() ids := make([]string, 0, len(p.data.PublicKeys)) for _, pk := range p.data.PublicKeys { ids = append(ids, pk.Fingerprint) } if p.secring != nil { ids = append(ids, p.secring.KeyIDs()...) } sort.Strings(ids) return ids }
go
func (p *Pubring) KeyIDs() []string { p.Lock() defer p.Unlock() ids := make([]string, 0, len(p.data.PublicKeys)) for _, pk := range p.data.PublicKeys { ids = append(ids, pk.Fingerprint) } if p.secring != nil { ids = append(ids, p.secring.KeyIDs()...) } sort.Strings(ids) return ids }
[ "func", "(", "p", "*", "Pubring", ")", "KeyIDs", "(", ")", "[", "]", "string", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "ids", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "p", ".", "data", ".", "PublicKeys", ")", ")", "\n", "for", "_", ",", "pk", ":=", "range", "p", ".", "data", ".", "PublicKeys", "{", "ids", "=", "append", "(", "ids", ",", "pk", ".", "Fingerprint", ")", "\n", "}", "\n", "if", "p", ".", "secring", "!=", "nil", "{", "ids", "=", "append", "(", "ids", ",", "p", ".", "secring", ".", "KeyIDs", "(", ")", "...", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "ids", ")", "\n", "return", "ids", "\n", "}" ]
// KeyIDs returns a list of all key IDs
[ "KeyIDs", "returns", "a", "list", "of", "all", "key", "IDs" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L85-L98
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Export
func (p *Pubring) Export(id string) ([]byte, error) { p.Lock() defer p.Unlock() xpk := p.fetch(id) if xpk == nil { if p.secring != nil { return p.secring.Export(id, false) } return nil, fmt.Errorf("key not found") } return proto.Marshal(xpk) }
go
func (p *Pubring) Export(id string) ([]byte, error) { p.Lock() defer p.Unlock() xpk := p.fetch(id) if xpk == nil { if p.secring != nil { return p.secring.Export(id, false) } return nil, fmt.Errorf("key not found") } return proto.Marshal(xpk) }
[ "func", "(", "p", "*", "Pubring", ")", "Export", "(", "id", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "xpk", ":=", "p", ".", "fetch", "(", "id", ")", "\n", "if", "xpk", "==", "nil", "{", "if", "p", ".", "secring", "!=", "nil", "{", "return", "p", ".", "secring", ".", "Export", "(", "id", ",", "false", ")", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"key not found\"", ")", "\n", "}", "\n", "return", "proto", ".", "Marshal", "(", "xpk", ")", "\n", "}" ]
// Export marshals a single key
[ "Export", "marshals", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L101-L114
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Import
func (p *Pubring) Import(buf []byte) error { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return err } p.insert(pk) return nil }
go
func (p *Pubring) Import(buf []byte) error { pk := &xcpb.PublicKey{} if err := proto.Unmarshal(buf, pk); err != nil { return err } p.insert(pk) return nil }
[ "func", "(", "p", "*", "Pubring", ")", "Import", "(", "buf", "[", "]", "byte", ")", "error", "{", "pk", ":=", "&", "xcpb", ".", "PublicKey", "{", "}", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "pk", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ".", "insert", "(", "pk", ")", "\n", "return", "nil", "\n", "}" ]
// Import unmarshals and inserts and previously exported key
[ "Import", "unmarshals", "and", "inserts", "and", "previously", "exported", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L144-L152
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Set
func (p *Pubring) Set(pk *PublicKey) error { p.Lock() defer p.Unlock() p.insert(pubKRToPB(pk)) return nil }
go
func (p *Pubring) Set(pk *PublicKey) error { p.Lock() defer p.Unlock() p.insert(pubKRToPB(pk)) return nil }
[ "func", "(", "p", "*", "Pubring", ")", "Set", "(", "pk", "*", "PublicKey", ")", "error", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "p", ".", "insert", "(", "pubKRToPB", "(", "pk", ")", ")", "\n", "return", "nil", "\n", "}" ]
// Set inserts a key, possibly overwriting and existing entry
[ "Set", "inserts", "a", "key", "possibly", "overwriting", "and", "existing", "entry" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L155-L161
train
gopasspw/gopass
pkg/backend/crypto/xc/keyring/pubring.go
Remove
func (p *Pubring) Remove(id string) error { p.Lock() defer p.Unlock() match := -1 for i, pk := range p.data.PublicKeys { if pk.Fingerprint == id { match = i break } } if match < 0 || match > len(p.data.PublicKeys) { return fmt.Errorf("not found") } p.data.PublicKeys = append(p.data.PublicKeys[:match], p.data.PublicKeys[match+1:]...) return nil }
go
func (p *Pubring) Remove(id string) error { p.Lock() defer p.Unlock() match := -1 for i, pk := range p.data.PublicKeys { if pk.Fingerprint == id { match = i break } } if match < 0 || match > len(p.data.PublicKeys) { return fmt.Errorf("not found") } p.data.PublicKeys = append(p.data.PublicKeys[:match], p.data.PublicKeys[match+1:]...) return nil }
[ "func", "(", "p", "*", "Pubring", ")", "Remove", "(", "id", "string", ")", "error", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n", "match", ":=", "-", "1", "\n", "for", "i", ",", "pk", ":=", "range", "p", ".", "data", ".", "PublicKeys", "{", "if", "pk", ".", "Fingerprint", "==", "id", "{", "match", "=", "i", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "match", "<", "0", "||", "match", ">", "len", "(", "p", ".", "data", ".", "PublicKeys", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"not found\"", ")", "\n", "}", "\n", "p", ".", "data", ".", "PublicKeys", "=", "append", "(", "p", ".", "data", ".", "PublicKeys", "[", ":", "match", "]", ",", "p", ".", "data", ".", "PublicKeys", "[", "match", "+", "1", ":", "]", "...", ")", "\n", "return", "nil", "\n", "}" ]
// Remove deletes a single key
[ "Remove", "deletes", "a", "single", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/xc/keyring/pubring.go#L175-L191
train
gopasspw/gopass
pkg/config/store_config.go
ConfigMap
func (c *StoreConfig) ConfigMap() map[string]string { m := make(map[string]string, 20) o := reflect.ValueOf(c).Elem() for i := 0; i < o.NumField(); i++ { jsonArg := o.Type().Field(i).Tag.Get("yaml") if jsonArg == "" || jsonArg == "-" { continue } f := o.Field(i) var strVal string switch f.Kind() { case reflect.String: strVal = f.String() case reflect.Bool: strVal = fmt.Sprintf("%t", f.Bool()) case reflect.Int: strVal = fmt.Sprintf("%d", f.Int()) case reflect.Ptr: switch bup := f.Interface().(type) { case *backend.URL: if bup == nil { continue } strVal = bup.String() } default: continue } m[jsonArg] = strVal } return m }
go
func (c *StoreConfig) ConfigMap() map[string]string { m := make(map[string]string, 20) o := reflect.ValueOf(c).Elem() for i := 0; i < o.NumField(); i++ { jsonArg := o.Type().Field(i).Tag.Get("yaml") if jsonArg == "" || jsonArg == "-" { continue } f := o.Field(i) var strVal string switch f.Kind() { case reflect.String: strVal = f.String() case reflect.Bool: strVal = fmt.Sprintf("%t", f.Bool()) case reflect.Int: strVal = fmt.Sprintf("%d", f.Int()) case reflect.Ptr: switch bup := f.Interface().(type) { case *backend.URL: if bup == nil { continue } strVal = bup.String() } default: continue } m[jsonArg] = strVal } return m }
[ "func", "(", "c", "*", "StoreConfig", ")", "ConfigMap", "(", ")", "map", "[", "string", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "20", ")", "\n", "o", ":=", "reflect", ".", "ValueOf", "(", "c", ")", ".", "Elem", "(", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "o", ".", "NumField", "(", ")", ";", "i", "++", "{", "jsonArg", ":=", "o", ".", "Type", "(", ")", ".", "Field", "(", "i", ")", ".", "Tag", ".", "Get", "(", "\"yaml\"", ")", "\n", "if", "jsonArg", "==", "\"\"", "||", "jsonArg", "==", "\"-\"", "{", "continue", "\n", "}", "\n", "f", ":=", "o", ".", "Field", "(", "i", ")", "\n", "var", "strVal", "string", "\n", "switch", "f", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "String", ":", "strVal", "=", "f", ".", "String", "(", ")", "\n", "case", "reflect", ".", "Bool", ":", "strVal", "=", "fmt", ".", "Sprintf", "(", "\"%t\"", ",", "f", ".", "Bool", "(", ")", ")", "\n", "case", "reflect", ".", "Int", ":", "strVal", "=", "fmt", ".", "Sprintf", "(", "\"%d\"", ",", "f", ".", "Int", "(", ")", ")", "\n", "case", "reflect", ".", "Ptr", ":", "switch", "bup", ":=", "f", ".", "Interface", "(", ")", ".", "(", "type", ")", "{", "case", "*", "backend", ".", "URL", ":", "if", "bup", "==", "nil", "{", "continue", "\n", "}", "\n", "strVal", "=", "bup", ".", "String", "(", ")", "\n", "}", "\n", "default", ":", "continue", "\n", "}", "\n", "m", "[", "jsonArg", "]", "=", "strVal", "\n", "}", "\n", "return", "m", "\n", "}" ]
// ConfigMap returns a map of stringified config values for easy printing
[ "ConfigMap", "returns", "a", "map", "of", "stringified", "config", "values", "for", "easy", "printing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/config/store_config.go#L52-L83
train
gopasspw/gopass
pkg/store/root/mount.go
RemoveMount
func (r *Store) RemoveMount(ctx context.Context, alias string) error { if _, found := r.mounts[alias]; !found { return errors.Errorf("%s is not mounted", alias) } if _, found := r.mounts[alias]; !found { out.Yellow(ctx, "%s is not initialized", alias) } delete(r.mounts, alias) delete(r.cfg.Mounts, alias) return nil }
go
func (r *Store) RemoveMount(ctx context.Context, alias string) error { if _, found := r.mounts[alias]; !found { return errors.Errorf("%s is not mounted", alias) } if _, found := r.mounts[alias]; !found { out.Yellow(ctx, "%s is not initialized", alias) } delete(r.mounts, alias) delete(r.cfg.Mounts, alias) return nil }
[ "func", "(", "r", "*", "Store", ")", "RemoveMount", "(", "ctx", "context", ".", "Context", ",", "alias", "string", ")", "error", "{", "if", "_", ",", "found", ":=", "r", ".", "mounts", "[", "alias", "]", ";", "!", "found", "{", "return", "errors", ".", "Errorf", "(", "\"%s is not mounted\"", ",", "alias", ")", "\n", "}", "\n", "if", "_", ",", "found", ":=", "r", ".", "mounts", "[", "alias", "]", ";", "!", "found", "{", "out", ".", "Yellow", "(", "ctx", ",", "\"%s is not initialized\"", ",", "alias", ")", "\n", "}", "\n", "delete", "(", "r", ".", "mounts", ",", "alias", ")", "\n", "delete", "(", "r", ".", "cfg", ".", "Mounts", ",", "alias", ")", "\n", "return", "nil", "\n", "}" ]
// RemoveMount removes and existing mount
[ "RemoveMount", "removes", "and", "existing", "mount" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L128-L138
train
gopasspw/gopass
pkg/store/root/mount.go
Mounts
func (r *Store) Mounts() map[string]string { m := make(map[string]string, len(r.mounts)) for alias, sub := range r.mounts { m[alias] = sub.Path() } return m }
go
func (r *Store) Mounts() map[string]string { m := make(map[string]string, len(r.mounts)) for alias, sub := range r.mounts { m[alias] = sub.Path() } return m }
[ "func", "(", "r", "*", "Store", ")", "Mounts", "(", ")", "map", "[", "string", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "r", ".", "mounts", ")", ")", "\n", "for", "alias", ",", "sub", ":=", "range", "r", ".", "mounts", "{", "m", "[", "alias", "]", "=", "sub", ".", "Path", "(", ")", "\n", "}", "\n", "return", "m", "\n", "}" ]
// Mounts returns a map of mounts with their paths
[ "Mounts", "returns", "a", "map", "of", "mounts", "with", "their", "paths" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L141-L147
train
gopasspw/gopass
pkg/store/root/mount.go
MountPoints
func (r *Store) MountPoints() []string { mps := make([]string, 0, len(r.mounts)) for k := range r.mounts { mps = append(mps, k) } sort.Sort(sort.Reverse(store.ByPathLen(mps))) return mps }
go
func (r *Store) MountPoints() []string { mps := make([]string, 0, len(r.mounts)) for k := range r.mounts { mps = append(mps, k) } sort.Sort(sort.Reverse(store.ByPathLen(mps))) return mps }
[ "func", "(", "r", "*", "Store", ")", "MountPoints", "(", ")", "[", "]", "string", "{", "mps", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "r", ".", "mounts", ")", ")", "\n", "for", "k", ":=", "range", "r", ".", "mounts", "{", "mps", "=", "append", "(", "mps", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "sort", ".", "Reverse", "(", "store", ".", "ByPathLen", "(", "mps", ")", ")", ")", "\n", "return", "mps", "\n", "}" ]
// MountPoints returns a sorted list of mount points. It encodes the logic that // the longer a mount point the more specific it is. This allows to "shadow" a // shorter mount point by a longer one.
[ "MountPoints", "returns", "a", "sorted", "list", "of", "mount", "points", ".", "It", "encodes", "the", "logic", "that", "the", "longer", "a", "mount", "point", "the", "more", "specific", "it", "is", ".", "This", "allows", "to", "shadow", "a", "shorter", "mount", "point", "by", "a", "longer", "one", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L152-L159
train
gopasspw/gopass
pkg/store/root/mount.go
MountPoint
func (r *Store) MountPoint(name string) string { for _, mp := range r.MountPoints() { if strings.HasPrefix(name+"/", mp+"/") { return mp } } return "" }
go
func (r *Store) MountPoint(name string) string { for _, mp := range r.MountPoints() { if strings.HasPrefix(name+"/", mp+"/") { return mp } } return "" }
[ "func", "(", "r", "*", "Store", ")", "MountPoint", "(", "name", "string", ")", "string", "{", "for", "_", ",", "mp", ":=", "range", "r", ".", "MountPoints", "(", ")", "{", "if", "strings", ".", "HasPrefix", "(", "name", "+", "\"/\"", ",", "mp", "+", "\"/\"", ")", "{", "return", "mp", "\n", "}", "\n", "}", "\n", "return", "\"\"", "\n", "}" ]
// MountPoint returns the most-specific mount point for the given key
[ "MountPoint", "returns", "the", "most", "-", "specific", "mount", "point", "for", "the", "given", "key" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L162-L169
train
gopasspw/gopass
pkg/store/root/mount.go
getStore
func (r *Store) getStore(ctx context.Context, name string) (context.Context, store.Store, string) { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if sub, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx), sub, strings.TrimPrefix(name, sub.Alias()) } return r.cfg.Root.WithContext(ctx), r.store, name }
go
func (r *Store) getStore(ctx context.Context, name string) (context.Context, store.Store, string) { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if sub, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx), sub, strings.TrimPrefix(name, sub.Alias()) } return r.cfg.Root.WithContext(ctx), r.store, name }
[ "func", "(", "r", "*", "Store", ")", "getStore", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "context", ".", "Context", ",", "store", ".", "Store", ",", "string", ")", "{", "name", "=", "strings", ".", "TrimSuffix", "(", "name", ",", "\"/\"", ")", "\n", "mp", ":=", "r", ".", "MountPoint", "(", "name", ")", "\n", "if", "sub", ",", "found", ":=", "r", ".", "mounts", "[", "mp", "]", ";", "found", "{", "return", "r", ".", "cfg", ".", "Mounts", "[", "mp", "]", ".", "WithContext", "(", "ctx", ")", ",", "sub", ",", "strings", ".", "TrimPrefix", "(", "name", ",", "sub", ".", "Alias", "(", ")", ")", "\n", "}", "\n", "return", "r", ".", "cfg", ".", "Root", ".", "WithContext", "(", "ctx", ")", ",", "r", ".", "store", ",", "name", "\n", "}" ]
// getStore returns the Store object at the most-specific mount point for the // given key // context with sub store options set, sub store reference, truncated path to secret
[ "getStore", "returns", "the", "Store", "object", "at", "the", "most", "-", "specific", "mount", "point", "for", "the", "given", "key", "context", "with", "sub", "store", "options", "set", "sub", "store", "reference", "truncated", "path", "to", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L174-L181
train
gopasspw/gopass
pkg/store/root/mount.go
WithConfig
func (r *Store) WithConfig(ctx context.Context, name string) context.Context { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if _, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx) } return r.cfg.Root.WithContext(ctx) }
go
func (r *Store) WithConfig(ctx context.Context, name string) context.Context { name = strings.TrimSuffix(name, "/") mp := r.MountPoint(name) if _, found := r.mounts[mp]; found { return r.cfg.Mounts[mp].WithContext(ctx) } return r.cfg.Root.WithContext(ctx) }
[ "func", "(", "r", "*", "Store", ")", "WithConfig", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "context", ".", "Context", "{", "name", "=", "strings", ".", "TrimSuffix", "(", "name", ",", "\"/\"", ")", "\n", "mp", ":=", "r", ".", "MountPoint", "(", "name", ")", "\n", "if", "_", ",", "found", ":=", "r", ".", "mounts", "[", "mp", "]", ";", "found", "{", "return", "r", ".", "cfg", ".", "Mounts", "[", "mp", "]", ".", "WithContext", "(", "ctx", ")", "\n", "}", "\n", "return", "r", ".", "cfg", ".", "Root", ".", "WithContext", "(", "ctx", ")", "\n", "}" ]
// WithConfig populates the context with the substore config
[ "WithConfig", "populates", "the", "context", "with", "the", "substore", "config" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L184-L191
train
gopasspw/gopass
pkg/store/root/mount.go
GetSubStore
func (r *Store) GetSubStore(name string) (store.Store, error) { if name == "" { return r.store, nil } if sub, found := r.mounts[name]; found { return sub, nil } return nil, errors.Errorf("no such mount point '%s'", name) }
go
func (r *Store) GetSubStore(name string) (store.Store, error) { if name == "" { return r.store, nil } if sub, found := r.mounts[name]; found { return sub, nil } return nil, errors.Errorf("no such mount point '%s'", name) }
[ "func", "(", "r", "*", "Store", ")", "GetSubStore", "(", "name", "string", ")", "(", "store", ".", "Store", ",", "error", ")", "{", "if", "name", "==", "\"\"", "{", "return", "r", ".", "store", ",", "nil", "\n", "}", "\n", "if", "sub", ",", "found", ":=", "r", ".", "mounts", "[", "name", "]", ";", "found", "{", "return", "sub", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"no such mount point '%s'\"", ",", "name", ")", "\n", "}" ]
// GetSubStore returns an exact match for a mount point or an error if this // mount point does not exist
[ "GetSubStore", "returns", "an", "exact", "match", "for", "a", "mount", "point", "or", "an", "error", "if", "this", "mount", "point", "does", "not", "exist" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L195-L203
train
gopasspw/gopass
pkg/store/root/mount.go
checkMounts
func (r *Store) checkMounts() error { paths := make(map[string]string, len(r.mounts)) for k, v := range r.mounts { if _, found := paths[v.Path()]; found { return errors.Errorf("Doubly mounted path at %s: %s", v.Path(), k) } paths[v.Path()] = k } return nil }
go
func (r *Store) checkMounts() error { paths := make(map[string]string, len(r.mounts)) for k, v := range r.mounts { if _, found := paths[v.Path()]; found { return errors.Errorf("Doubly mounted path at %s: %s", v.Path(), k) } paths[v.Path()] = k } return nil }
[ "func", "(", "r", "*", "Store", ")", "checkMounts", "(", ")", "error", "{", "paths", ":=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "r", ".", "mounts", ")", ")", "\n", "for", "k", ",", "v", ":=", "range", "r", ".", "mounts", "{", "if", "_", ",", "found", ":=", "paths", "[", "v", ".", "Path", "(", ")", "]", ";", "found", "{", "return", "errors", ".", "Errorf", "(", "\"Doubly mounted path at %s: %s\"", ",", "v", ".", "Path", "(", ")", ",", "k", ")", "\n", "}", "\n", "paths", "[", "v", ".", "Path", "(", ")", "]", "=", "k", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// checkMounts performs some sanity checks on our mounts. At the moment it // only checks if some path is mounted twice.
[ "checkMounts", "performs", "some", "sanity", "checks", "on", "our", "mounts", ".", "At", "the", "moment", "it", "only", "checks", "if", "some", "path", "is", "mounted", "twice", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/root/mount.go#L207-L216
train
gopasspw/gopass
pkg/action/version.go
Version
func (s *Action) Version(ctx context.Context, c *cli.Context) error { version := make(chan string, 1) go s.checkVersion(ctx, version) _ = s.Initialized(ctx, c) cli.VersionPrinter(c) cryptoVer := versionInfo(ctx, s.Store.Crypto(ctx, "")) rcsVer := versionInfo(ctx, s.Store.RCS(ctx, "")) storageVer := versionInfo(ctx, s.Store.Storage(ctx, "")) tpl := "%-10s - %10s - %10s - %10s\n" fmt.Fprintf(stdout, tpl, "<root>", cryptoVer, rcsVer, storageVer) // report all used crypto, sync and fs backends for _, mp := range s.Store.MountPoints() { cv := versionInfo(ctx, s.Store.Crypto(ctx, mp)) rv := versionInfo(ctx, s.Store.RCS(ctx, mp)) sv := versionInfo(ctx, s.Store.Storage(ctx, mp)) if cv != cryptoVer || rv != rcsVer || sv != storageVer { fmt.Fprintf(stdout, tpl, mp, cv, rv, sv) } } fmt.Fprintf(stdout, "Available Crypto Backends: %s\n", strings.Join(backend.CryptoBackends(), ", ")) fmt.Fprintf(stdout, "Available RCS Backends: %s\n", strings.Join(backend.RCSBackends(), ", ")) fmt.Fprintf(stdout, "Available Storage Backends: %s\n", strings.Join(backend.StorageBackends(), ", ")) select { case vi := <-version: if vi != "" { fmt.Fprintln(stdout, vi) } case <-time.After(2 * time.Second): out.Error(ctx, "Version check timed out") case <-ctx.Done(): return ExitError(ctx, ExitAborted, nil, "user aborted") } return nil }
go
func (s *Action) Version(ctx context.Context, c *cli.Context) error { version := make(chan string, 1) go s.checkVersion(ctx, version) _ = s.Initialized(ctx, c) cli.VersionPrinter(c) cryptoVer := versionInfo(ctx, s.Store.Crypto(ctx, "")) rcsVer := versionInfo(ctx, s.Store.RCS(ctx, "")) storageVer := versionInfo(ctx, s.Store.Storage(ctx, "")) tpl := "%-10s - %10s - %10s - %10s\n" fmt.Fprintf(stdout, tpl, "<root>", cryptoVer, rcsVer, storageVer) // report all used crypto, sync and fs backends for _, mp := range s.Store.MountPoints() { cv := versionInfo(ctx, s.Store.Crypto(ctx, mp)) rv := versionInfo(ctx, s.Store.RCS(ctx, mp)) sv := versionInfo(ctx, s.Store.Storage(ctx, mp)) if cv != cryptoVer || rv != rcsVer || sv != storageVer { fmt.Fprintf(stdout, tpl, mp, cv, rv, sv) } } fmt.Fprintf(stdout, "Available Crypto Backends: %s\n", strings.Join(backend.CryptoBackends(), ", ")) fmt.Fprintf(stdout, "Available RCS Backends: %s\n", strings.Join(backend.RCSBackends(), ", ")) fmt.Fprintf(stdout, "Available Storage Backends: %s\n", strings.Join(backend.StorageBackends(), ", ")) select { case vi := <-version: if vi != "" { fmt.Fprintln(stdout, vi) } case <-time.After(2 * time.Second): out.Error(ctx, "Version check timed out") case <-ctx.Done(): return ExitError(ctx, ExitAborted, nil, "user aborted") } return nil }
[ "func", "(", "s", "*", "Action", ")", "Version", "(", "ctx", "context", ".", "Context", ",", "c", "*", "cli", ".", "Context", ")", "error", "{", "version", ":=", "make", "(", "chan", "string", ",", "1", ")", "\n", "go", "s", ".", "checkVersion", "(", "ctx", ",", "version", ")", "\n", "_", "=", "s", ".", "Initialized", "(", "ctx", ",", "c", ")", "\n", "cli", ".", "VersionPrinter", "(", "c", ")", "\n", "cryptoVer", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Crypto", "(", "ctx", ",", "\"\"", ")", ")", "\n", "rcsVer", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "RCS", "(", "ctx", ",", "\"\"", ")", ")", "\n", "storageVer", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Storage", "(", "ctx", ",", "\"\"", ")", ")", "\n", "tpl", ":=", "\"%-10s - %10s - %10s - %10s\\n\"", "\n", "\\n", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "tpl", ",", "\"<root>\"", ",", "cryptoVer", ",", "rcsVer", ",", "storageVer", ")", "\n", "for", "_", ",", "mp", ":=", "range", "s", ".", "Store", ".", "MountPoints", "(", ")", "{", "cv", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Crypto", "(", "ctx", ",", "mp", ")", ")", "\n", "rv", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "RCS", "(", "ctx", ",", "mp", ")", ")", "\n", "sv", ":=", "versionInfo", "(", "ctx", ",", "s", ".", "Store", ".", "Storage", "(", "ctx", ",", "mp", ")", ")", "\n", "if", "cv", "!=", "cryptoVer", "||", "rv", "!=", "rcsVer", "||", "sv", "!=", "storageVer", "{", "fmt", ".", "Fprintf", "(", "stdout", ",", "tpl", ",", "mp", ",", "cv", ",", "rv", ",", "sv", ")", "\n", "}", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "\"Available Crypto Backends: %s\\n\"", ",", "\\n", ")", "\n", "strings", ".", "Join", "(", "backend", ".", "CryptoBackends", "(", ")", ",", "\", \"", ")", "\n", "fmt", ".", "Fprintf", "(", "stdout", ",", "\"Available RCS Backends: %s\\n\"", ",", "\\n", ")", "\n", "strings", ".", "Join", "(", "backend", ".", "RCSBackends", "(", ")", ",", "\", \"", ")", "\n", "}" ]
// Version prints the gopass version
[ "Version", "prints", "the", "gopass", "version" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/action/version.go#L21-L63
train
gopasspw/gopass
pkg/clipboard/kill_ps.go
killPrecedessors
func killPrecedessors() error { procs, err := ps.Processes() if err != nil { return err } for _, proc := range procs { walkFn(proc.Pid(), killProc) } return nil }
go
func killPrecedessors() error { procs, err := ps.Processes() if err != nil { return err } for _, proc := range procs { walkFn(proc.Pid(), killProc) } return nil }
[ "func", "killPrecedessors", "(", ")", "error", "{", "procs", ",", "err", ":=", "ps", ".", "Processes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "_", ",", "proc", ":=", "range", "procs", "{", "walkFn", "(", "proc", ".", "Pid", "(", ")", ",", "killProc", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// killPrecedessors will kill any previous "gopass unclip" invokations to avoid // erasing the clipboard prematurely in case the the same content is copied to // the clipboard repeatedly
[ "killPrecedessors", "will", "kill", "any", "previous", "gopass", "unclip", "invokations", "to", "avoid", "erasing", "the", "clipboard", "prematurely", "in", "case", "the", "the", "same", "content", "is", "copied", "to", "the", "clipboard", "repeatedly" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/clipboard/kill_ps.go#L12-L21
train
gopasspw/gopass
pkg/tpl/template.go
Execute
func Execute(ctx context.Context, tpl, name string, content []byte, s kvstore) ([]byte, error) { funcs := funcMap(ctx, s) pl := payload{ Dir: filepath.Dir(name), Path: name, Name: filepath.Base(name), Content: string(content), } tmpl, err := template.New(tpl).Funcs(funcs).Parse(tpl) if err != nil { return []byte{}, err } buff := &bytes.Buffer{} if err := tmpl.Execute(buff, pl); err != nil { return []byte{}, err } return buff.Bytes(), nil }
go
func Execute(ctx context.Context, tpl, name string, content []byte, s kvstore) ([]byte, error) { funcs := funcMap(ctx, s) pl := payload{ Dir: filepath.Dir(name), Path: name, Name: filepath.Base(name), Content: string(content), } tmpl, err := template.New(tpl).Funcs(funcs).Parse(tpl) if err != nil { return []byte{}, err } buff := &bytes.Buffer{} if err := tmpl.Execute(buff, pl); err != nil { return []byte{}, err } return buff.Bytes(), nil }
[ "func", "Execute", "(", "ctx", "context", ".", "Context", ",", "tpl", ",", "name", "string", ",", "content", "[", "]", "byte", ",", "s", "kvstore", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "funcs", ":=", "funcMap", "(", "ctx", ",", "s", ")", "\n", "pl", ":=", "payload", "{", "Dir", ":", "filepath", ".", "Dir", "(", "name", ")", ",", "Path", ":", "name", ",", "Name", ":", "filepath", ".", "Base", "(", "name", ")", ",", "Content", ":", "string", "(", "content", ")", ",", "}", "\n", "tmpl", ",", "err", ":=", "template", ".", "New", "(", "tpl", ")", ".", "Funcs", "(", "funcs", ")", ".", "Parse", "(", "tpl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "buff", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "if", "err", ":=", "tmpl", ".", "Execute", "(", "buff", ",", "pl", ")", ";", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "return", "buff", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// Execute executes the given template
[ "Execute", "executes", "the", "given", "template" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tpl/template.go#L24-L44
train
gopasspw/gopass
pkg/store/secret/yaml.go
Value
func (s *Secret) Value(key string) (string, error) { s.Lock() defer s.Unlock() if s.data == nil { if !strings.HasPrefix(s.body, "---\n") { return "", store.ErrYAMLNoMark } if err := s.decode(); err != nil { return "", err } } if v, found := s.data[key]; found { return fmt.Sprintf("%v", v), nil } return "", store.ErrYAMLNoKey }
go
func (s *Secret) Value(key string) (string, error) { s.Lock() defer s.Unlock() if s.data == nil { if !strings.HasPrefix(s.body, "---\n") { return "", store.ErrYAMLNoMark } if err := s.decode(); err != nil { return "", err } } if v, found := s.data[key]; found { return fmt.Sprintf("%v", v), nil } return "", store.ErrYAMLNoKey }
[ "func", "(", "s", "*", "Secret", ")", "Value", "(", "key", "string", ")", "(", "string", ",", "error", ")", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "data", "==", "nil", "{", "if", "!", "strings", ".", "HasPrefix", "(", "s", ".", "body", ",", "\"---\\n\"", ")", "\\n", "\n", "{", "return", "\"\"", ",", "store", ".", "ErrYAMLNoMark", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "s", ".", "decode", "(", ")", ";", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "if", "v", ",", "found", ":=", "s", ".", "data", "[", "key", "]", ";", "found", "{", "return", "fmt", ".", "Sprintf", "(", "\"%v\"", ",", "v", ")", ",", "nil", "\n", "}", "\n", "}" ]
// Value returns the value of the given key if the body contained valid // YAML
[ "Value", "returns", "the", "value", "of", "the", "given", "key", "if", "the", "body", "contained", "valid", "YAML" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L14-L30
train
gopasspw/gopass
pkg/store/secret/yaml.go
SetValue
func (s *Secret) SetValue(key, value string) error { s.Lock() defer s.Unlock() if s.body == "" && s.data == nil { s.data = make(map[string]interface{}, 1) } if s.data == nil { return store.ErrYAMLNoMark } s.data[key] = value return s.encode() }
go
func (s *Secret) SetValue(key, value string) error { s.Lock() defer s.Unlock() if s.body == "" && s.data == nil { s.data = make(map[string]interface{}, 1) } if s.data == nil { return store.ErrYAMLNoMark } s.data[key] = value return s.encode() }
[ "func", "(", "s", "*", "Secret", ")", "SetValue", "(", "key", ",", "value", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "body", "==", "\"\"", "&&", "s", ".", "data", "==", "nil", "{", "s", ".", "data", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ",", "1", ")", "\n", "}", "\n", "if", "s", ".", "data", "==", "nil", "{", "return", "store", ".", "ErrYAMLNoMark", "\n", "}", "\n", "s", ".", "data", "[", "key", "]", "=", "value", "\n", "return", "s", ".", "encode", "(", ")", "\n", "}" ]
// SetValue sets a key to a given value. Will fail if an non-empty body exists
[ "SetValue", "sets", "a", "key", "to", "a", "given", "value", ".", "Will", "fail", "if", "an", "non", "-", "empty", "body", "exists" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L33-L45
train
gopasspw/gopass
pkg/store/secret/yaml.go
DeleteKey
func (s *Secret) DeleteKey(key string) error { s.Lock() defer s.Unlock() if s.data == nil { return store.ErrYAMLNoMark } delete(s.data, key) return s.encode() }
go
func (s *Secret) DeleteKey(key string) error { s.Lock() defer s.Unlock() if s.data == nil { return store.ErrYAMLNoMark } delete(s.data, key) return s.encode() }
[ "func", "(", "s", "*", "Secret", ")", "DeleteKey", "(", "key", "string", ")", "error", "{", "s", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "Unlock", "(", ")", "\n", "if", "s", ".", "data", "==", "nil", "{", "return", "store", ".", "ErrYAMLNoMark", "\n", "}", "\n", "delete", "(", "s", ".", "data", ",", "key", ")", "\n", "return", "s", ".", "encode", "(", ")", "\n", "}" ]
// DeleteKey key will delete a single key from an decoded map
[ "DeleteKey", "key", "will", "delete", "a", "single", "key", "from", "an", "decoded", "map" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L48-L57
train
gopasspw/gopass
pkg/store/secret/yaml.go
decodeYAML
func (s *Secret) decodeYAML() (bool, error) { if !strings.HasPrefix(s.body, "---\n") && s.password != "---" { return false, nil } d := make(map[string]interface{}) err := yaml.Unmarshal([]byte(s.body), &d) if err != nil { return true, err } s.data = d return true, nil }
go
func (s *Secret) decodeYAML() (bool, error) { if !strings.HasPrefix(s.body, "---\n") && s.password != "---" { return false, nil } d := make(map[string]interface{}) err := yaml.Unmarshal([]byte(s.body), &d) if err != nil { return true, err } s.data = d return true, nil }
[ "func", "(", "s", "*", "Secret", ")", "decodeYAML", "(", ")", "(", "bool", ",", "error", ")", "{", "if", "!", "strings", ".", "HasPrefix", "(", "s", ".", "body", ",", "\"---\\n\"", ")", "&&", "\\n", "s", ".", "password", "!=", "\"---\"", "\n", "{", "return", "false", ",", "nil", "\n", "}", "\n", "d", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "err", ":=", "yaml", ".", "Unmarshal", "(", "[", "]", "byte", "(", "s", ".", "body", ")", ",", "&", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "true", ",", "err", "\n", "}", "\n", "s", ".", "data", "=", "d", "\n", "}" ]
// decodeYAML attempts to decode an optional YAML part of a secret
[ "decodeYAML", "attempts", "to", "decode", "an", "optional", "YAML", "part", "of", "a", "secret" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/secret/yaml.go#L60-L71
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/keyring.go
ListPublicKeyIDs
func (g *GPG) ListPublicKeyIDs(context.Context) ([]string, error) { if g.pubring == nil { return nil, fmt.Errorf("pubring is not initialized") } ids := listKeyIDs(g.pubring) if g.secring != nil { ids = append(ids, listKeyIDs(g.secring)...) } return ids, nil }
go
func (g *GPG) ListPublicKeyIDs(context.Context) ([]string, error) { if g.pubring == nil { return nil, fmt.Errorf("pubring is not initialized") } ids := listKeyIDs(g.pubring) if g.secring != nil { ids = append(ids, listKeyIDs(g.secring)...) } return ids, nil }
[ "func", "(", "g", "*", "GPG", ")", "ListPublicKeyIDs", "(", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "g", ".", "pubring", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"pubring is not initialized\"", ")", "\n", "}", "\n", "ids", ":=", "listKeyIDs", "(", "g", ".", "pubring", ")", "\n", "if", "g", ".", "secring", "!=", "nil", "{", "ids", "=", "append", "(", "ids", ",", "listKeyIDs", "(", "g", ".", "secring", ")", "...", ")", "\n", "}", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// ListPublicKeyIDs does nothing
[ "ListPublicKeyIDs", "does", "nothing" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/keyring.go#L15-L24
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/keyring.go
KeysByIdUsage
func (g *GPG) KeysByIdUsage(id uint64, requiredUsage byte) []openpgp.Key { return append(g.secring.KeysByIdUsage(id, requiredUsage), g.pubring.KeysByIdUsage(id, requiredUsage)...) }
go
func (g *GPG) KeysByIdUsage(id uint64, requiredUsage byte) []openpgp.Key { return append(g.secring.KeysByIdUsage(id, requiredUsage), g.pubring.KeysByIdUsage(id, requiredUsage)...) }
[ "func", "(", "g", "*", "GPG", ")", "KeysByIdUsage", "(", "id", "uint64", ",", "requiredUsage", "byte", ")", "[", "]", "openpgp", ".", "Key", "{", "return", "append", "(", "g", ".", "secring", ".", "KeysByIdUsage", "(", "id", ",", "requiredUsage", ")", ",", "g", ".", "pubring", ".", "KeysByIdUsage", "(", "id", ",", "requiredUsage", ")", "...", ")", "\n", "}" ]
// KeysByIdUsage implements openpgp.Keyring
[ "KeysByIdUsage", "implements", "openpgp", ".", "Keyring" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/keyring.go#L137-L139
train
gopasspw/gopass
pkg/backend/crypto/gpg/openpgp/keyring.go
SigningKeys
func (g *GPG) SigningKeys() []openpgp.Key { keys := []openpgp.Key{} for _, e := range g.secring { for _, subKey := range e.Subkeys { if subKey.PrivateKey != nil && (!subKey.Sig.FlagsValid || subKey.Sig.FlagSign) { keys = append(keys, openpgp.Key{ Entity: e, PublicKey: subKey.PublicKey, PrivateKey: subKey.PrivateKey, SelfSignature: subKey.Sig, }) } } } return keys }
go
func (g *GPG) SigningKeys() []openpgp.Key { keys := []openpgp.Key{} for _, e := range g.secring { for _, subKey := range e.Subkeys { if subKey.PrivateKey != nil && (!subKey.Sig.FlagsValid || subKey.Sig.FlagSign) { keys = append(keys, openpgp.Key{ Entity: e, PublicKey: subKey.PublicKey, PrivateKey: subKey.PrivateKey, SelfSignature: subKey.Sig, }) } } } return keys }
[ "func", "(", "g", "*", "GPG", ")", "SigningKeys", "(", ")", "[", "]", "openpgp", ".", "Key", "{", "keys", ":=", "[", "]", "openpgp", ".", "Key", "{", "}", "\n", "for", "_", ",", "e", ":=", "range", "g", ".", "secring", "{", "for", "_", ",", "subKey", ":=", "range", "e", ".", "Subkeys", "{", "if", "subKey", ".", "PrivateKey", "!=", "nil", "&&", "(", "!", "subKey", ".", "Sig", ".", "FlagsValid", "||", "subKey", ".", "Sig", ".", "FlagSign", ")", "{", "keys", "=", "append", "(", "keys", ",", "openpgp", ".", "Key", "{", "Entity", ":", "e", ",", "PublicKey", ":", "subKey", ".", "PublicKey", ",", "PrivateKey", ":", "subKey", ".", "PrivateKey", ",", "SelfSignature", ":", "subKey", ".", "Sig", ",", "}", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// SigningKeys returns a list of signing keys
[ "SigningKeys", "returns", "a", "list", "of", "signing", "keys" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/backend/crypto/gpg/openpgp/keyring.go#L149-L164
train
gopasspw/gopass
pkg/jsonapi/helpers.go
isPublicSuffix
func isPublicSuffix(host string) bool { suffix, _ := publicsuffix.PublicSuffix(host) return host == suffix }
go
func isPublicSuffix(host string) bool { suffix, _ := publicsuffix.PublicSuffix(host) return host == suffix }
[ "func", "isPublicSuffix", "(", "host", "string", ")", "bool", "{", "suffix", ",", "_", ":=", "publicsuffix", ".", "PublicSuffix", "(", "host", ")", "\n", "return", "host", "==", "suffix", "\n", "}" ]
// isPublicSuffix returns true if this host is one users can or could directly // register names
[ "isPublicSuffix", "returns", "true", "if", "this", "host", "is", "one", "users", "can", "or", "could", "directly", "register", "names" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/jsonapi/helpers.go#L12-L15
train
gopasspw/gopass
pkg/store/sub/recipients.go
Recipients
func (s *Store) Recipients(ctx context.Context) []string { rs, err := s.GetRecipients(ctx, "") if err != nil { out.Error(ctx, "failed to read recipient list: %s", err) } return rs }
go
func (s *Store) Recipients(ctx context.Context) []string { rs, err := s.GetRecipients(ctx, "") if err != nil { out.Error(ctx, "failed to read recipient list: %s", err) } return rs }
[ "func", "(", "s", "*", "Store", ")", "Recipients", "(", "ctx", "context", ".", "Context", ")", "[", "]", "string", "{", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Error", "(", "ctx", ",", "\"failed to read recipient list: %s\"", ",", "err", ")", "\n", "}", "\n", "return", "rs", "\n", "}" ]
// Recipients returns the list of recipients of this store
[ "Recipients", "returns", "the", "list", "of", "recipients", "of", "this", "store" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L30-L36
train
gopasspw/gopass
pkg/store/sub/recipients.go
AddRecipient
func (s *Store) AddRecipient(ctx context.Context, id string) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } for _, k := range rs { if k == id { return errors.Errorf("Recipient already in store") } } rs = append(rs, id) if err := s.saveRecipients(ctx, rs, "Added Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } out.Cyan(ctx, "Reencrypting existing secrets. This may take some time ...") return s.reencrypt(WithReason(ctx, "Added Recipient "+id)) }
go
func (s *Store) AddRecipient(ctx context.Context, id string) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } for _, k := range rs { if k == id { return errors.Errorf("Recipient already in store") } } rs = append(rs, id) if err := s.saveRecipients(ctx, rs, "Added Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } out.Cyan(ctx, "Reencrypting existing secrets. This may take some time ...") return s.reencrypt(WithReason(ctx, "Added Recipient "+id)) }
[ "func", "(", "s", "*", "Store", ")", "AddRecipient", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "error", "{", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to read recipient list\"", ")", "\n", "}", "\n", "for", "_", ",", "k", ":=", "range", "rs", "{", "if", "k", "==", "id", "{", "return", "errors", ".", "Errorf", "(", "\"Recipient already in store\"", ")", "\n", "}", "\n", "}", "\n", "rs", "=", "append", "(", "rs", ",", "id", ")", "\n", "if", "err", ":=", "s", ".", "saveRecipients", "(", "ctx", ",", "rs", ",", "\"Added Recipient \"", "+", "id", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to save recipients\"", ")", "\n", "}", "\n", "out", ".", "Cyan", "(", "ctx", ",", "\"Reencrypting existing secrets. This may take some time ...\"", ")", "\n", "return", "s", ".", "reencrypt", "(", "WithReason", "(", "ctx", ",", "\"Added Recipient \"", "+", "id", ")", ")", "\n", "}" ]
// AddRecipient adds a new recipient to the list
[ "AddRecipient", "adds", "a", "new", "recipient", "to", "the", "list" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L39-L59
train
gopasspw/gopass
pkg/store/sub/recipients.go
SaveRecipients
func (s *Store) SaveRecipients(ctx context.Context) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to get recipients") } return s.saveRecipients(ctx, rs, "Save Recipients", true) }
go
func (s *Store) SaveRecipients(ctx context.Context) error { rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to get recipients") } return s.saveRecipients(ctx, rs, "Save Recipients", true) }
[ "func", "(", "s", "*", "Store", ")", "SaveRecipients", "(", "ctx", "context", ".", "Context", ")", "error", "{", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to get recipients\"", ")", "\n", "}", "\n", "return", "s", ".", "saveRecipients", "(", "ctx", ",", "rs", ",", "\"Save Recipients\"", ",", "true", ")", "\n", "}" ]
// SaveRecipients persists the current recipients on disk
[ "SaveRecipients", "persists", "the", "current", "recipients", "on", "disk" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L62-L68
train
gopasspw/gopass
pkg/store/sub/recipients.go
SetRecipients
func (s *Store) SetRecipients(ctx context.Context, rs []string) error { return s.saveRecipients(ctx, rs, "Set Recipients", true) }
go
func (s *Store) SetRecipients(ctx context.Context, rs []string) error { return s.saveRecipients(ctx, rs, "Set Recipients", true) }
[ "func", "(", "s", "*", "Store", ")", "SetRecipients", "(", "ctx", "context", ".", "Context", ",", "rs", "[", "]", "string", ")", "error", "{", "return", "s", ".", "saveRecipients", "(", "ctx", ",", "rs", ",", "\"Set Recipients\"", ",", "true", ")", "\n", "}" ]
// SetRecipients will update the stored recipients and the associated checksum
[ "SetRecipients", "will", "update", "the", "stored", "recipients", "and", "the", "associated", "checksum" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L71-L73
train
gopasspw/gopass
pkg/store/sub/recipients.go
RemoveRecipient
func (s *Store) RemoveRecipient(ctx context.Context, id string) error { keys, err := s.crypto.FindPublicKeys(ctx, id) if err != nil { out.Cyan(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err) } rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } nk := make([]string, 0, len(rs)-1) RECIPIENTS: for _, k := range rs { if k == id { continue RECIPIENTS } // if the key is available locally we can also match the id against // the fingerprint for _, key := range keys { if strings.HasSuffix(key, k) { continue RECIPIENTS } } nk = append(nk, k) } if len(rs) == len(nk) { return errors.Errorf("recipient not in store") } if err := s.saveRecipients(ctx, nk, "Removed Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } return s.reencrypt(WithReason(ctx, "Removed Recipient "+id)) }
go
func (s *Store) RemoveRecipient(ctx context.Context, id string) error { keys, err := s.crypto.FindPublicKeys(ctx, id) if err != nil { out.Cyan(ctx, "Warning: Failed to get GPG Key Info for %s: %s", id, err) } rs, err := s.GetRecipients(ctx, "") if err != nil { return errors.Wrapf(err, "failed to read recipient list") } nk := make([]string, 0, len(rs)-1) RECIPIENTS: for _, k := range rs { if k == id { continue RECIPIENTS } // if the key is available locally we can also match the id against // the fingerprint for _, key := range keys { if strings.HasSuffix(key, k) { continue RECIPIENTS } } nk = append(nk, k) } if len(rs) == len(nk) { return errors.Errorf("recipient not in store") } if err := s.saveRecipients(ctx, nk, "Removed Recipient "+id, true); err != nil { return errors.Wrapf(err, "failed to save recipients") } return s.reencrypt(WithReason(ctx, "Removed Recipient "+id)) }
[ "func", "(", "s", "*", "Store", ")", "RemoveRecipient", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "error", "{", "keys", ",", "err", ":=", "s", ".", "crypto", ".", "FindPublicKeys", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "out", ".", "Cyan", "(", "ctx", ",", "\"Warning: Failed to get GPG Key Info for %s: %s\"", ",", "id", ",", "err", ")", "\n", "}", "\n", "rs", ",", "err", ":=", "s", ".", "GetRecipients", "(", "ctx", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to read recipient list\"", ")", "\n", "}", "\n", "nk", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "rs", ")", "-", "1", ")", "\n", "RECIPIENTS", ":", "for", "_", ",", "k", ":=", "range", "rs", "{", "if", "k", "==", "id", "{", "continue", "RECIPIENTS", "\n", "}", "\n", "for", "_", ",", "key", ":=", "range", "keys", "{", "if", "strings", ".", "HasSuffix", "(", "key", ",", "k", ")", "{", "continue", "RECIPIENTS", "\n", "}", "\n", "}", "\n", "nk", "=", "append", "(", "nk", ",", "k", ")", "\n", "}", "\n", "if", "len", "(", "rs", ")", "==", "len", "(", "nk", ")", "{", "return", "errors", ".", "Errorf", "(", "\"recipient not in store\"", ")", "\n", "}", "\n", "if", "err", ":=", "s", ".", "saveRecipients", "(", "ctx", ",", "nk", ",", "\"Removed Recipient \"", "+", "id", ",", "true", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to save recipients\"", ")", "\n", "}", "\n", "return", "s", ".", "reencrypt", "(", "WithReason", "(", "ctx", ",", "\"Removed Recipient \"", "+", "id", ")", ")", "\n", "}" ]
// RemoveRecipient will remove the given recipient from the store // but if this key is not available on this machine we // just try to remove it literally
[ "RemoveRecipient", "will", "remove", "the", "given", "recipient", "from", "the", "store", "but", "if", "this", "key", "is", "not", "available", "on", "this", "machine", "we", "just", "try", "to", "remove", "it", "literally" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L78-L114
train
gopasspw/gopass
pkg/store/sub/recipients.go
ExportMissingPublicKeys
func (s *Store) ExportMissingPublicKeys(ctx context.Context, rs []string) (bool, error) { ok := true exported := false for _, r := range rs { if r == "" { continue } path, err := s.exportPublicKey(ctx, r) if err != nil { ok = false out.Error(ctx, "failed to export public key for '%s': %s", r, err) continue } if path == "" { continue } // at least one key has been exported exported = true if err := s.rcs.Add(ctx, path); err != nil { if errors.Cause(err) == store.ErrGitNotInit { continue } ok = false out.Error(ctx, "failed to add public key for '%s' to git: %s", r, err) continue } if err := s.rcs.Commit(ctx, fmt.Sprintf("Exported Public Keys %s", r)); err != nil && err != store.ErrGitNothingToCommit { ok = false out.Error(ctx, "Failed to git commit: %s", err) continue } } if !ok { return exported, errors.New("some keys failed") } return exported, nil }
go
func (s *Store) ExportMissingPublicKeys(ctx context.Context, rs []string) (bool, error) { ok := true exported := false for _, r := range rs { if r == "" { continue } path, err := s.exportPublicKey(ctx, r) if err != nil { ok = false out.Error(ctx, "failed to export public key for '%s': %s", r, err) continue } if path == "" { continue } // at least one key has been exported exported = true if err := s.rcs.Add(ctx, path); err != nil { if errors.Cause(err) == store.ErrGitNotInit { continue } ok = false out.Error(ctx, "failed to add public key for '%s' to git: %s", r, err) continue } if err := s.rcs.Commit(ctx, fmt.Sprintf("Exported Public Keys %s", r)); err != nil && err != store.ErrGitNothingToCommit { ok = false out.Error(ctx, "Failed to git commit: %s", err) continue } } if !ok { return exported, errors.New("some keys failed") } return exported, nil }
[ "func", "(", "s", "*", "Store", ")", "ExportMissingPublicKeys", "(", "ctx", "context", ".", "Context", ",", "rs", "[", "]", "string", ")", "(", "bool", ",", "error", ")", "{", "ok", ":=", "true", "\n", "exported", ":=", "false", "\n", "for", "_", ",", "r", ":=", "range", "rs", "{", "if", "r", "==", "\"\"", "{", "continue", "\n", "}", "\n", "path", ",", "err", ":=", "s", ".", "exportPublicKey", "(", "ctx", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "ok", "=", "false", "\n", "out", ".", "Error", "(", "ctx", ",", "\"failed to export public key for '%s': %s\"", ",", "r", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "path", "==", "\"\"", "{", "continue", "\n", "}", "\n", "exported", "=", "true", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Add", "(", "ctx", ",", "path", ")", ";", "err", "!=", "nil", "{", "if", "errors", ".", "Cause", "(", "err", ")", "==", "store", ".", "ErrGitNotInit", "{", "continue", "\n", "}", "\n", "ok", "=", "false", "\n", "out", ".", "Error", "(", "ctx", ",", "\"failed to add public key for '%s' to git: %s\"", ",", "r", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "if", "err", ":=", "s", ".", "rcs", ".", "Commit", "(", "ctx", ",", "fmt", ".", "Sprintf", "(", "\"Exported Public Keys %s\"", ",", "r", ")", ")", ";", "err", "!=", "nil", "&&", "err", "!=", "store", ".", "ErrGitNothingToCommit", "{", "ok", "=", "false", "\n", "out", ".", "Error", "(", "ctx", ",", "\"Failed to git commit: %s\"", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "}", "\n", "if", "!", "ok", "{", "return", "exported", ",", "errors", ".", "New", "(", "\"some keys failed\"", ")", "\n", "}", "\n", "return", "exported", ",", "nil", "\n", "}" ]
// ExportMissingPublicKeys will export any possibly missing public keys to the // stores .public-keys directory
[ "ExportMissingPublicKeys", "will", "export", "any", "possibly", "missing", "public", "keys", "to", "the", "stores", ".", "public", "-", "keys", "directory" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L179-L215
train
gopasspw/gopass
pkg/store/sub/recipients.go
unmarshalRecipients
func unmarshalRecipients(buf []byte) []string { m := make(map[string]struct{}, 5) scanner := bufio.NewScanner(bytes.NewReader(buf)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if line != "" { // deduplicate m[line] = struct{}{} } } lst := make([]string, 0, len(m)) for k := range m { lst = append(lst, k) } // sort sort.Strings(lst) return lst }
go
func unmarshalRecipients(buf []byte) []string { m := make(map[string]struct{}, 5) scanner := bufio.NewScanner(bytes.NewReader(buf)) for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) if line != "" { // deduplicate m[line] = struct{}{} } } lst := make([]string, 0, len(m)) for k := range m { lst = append(lst, k) } // sort sort.Strings(lst) return lst }
[ "func", "unmarshalRecipients", "(", "buf", "[", "]", "byte", ")", "[", "]", "string", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "struct", "{", "}", ",", "5", ")", "\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "for", "scanner", ".", "Scan", "(", ")", "{", "line", ":=", "strings", ".", "TrimSpace", "(", "scanner", ".", "Text", "(", ")", ")", "\n", "if", "line", "!=", "\"\"", "{", "m", "[", "line", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "\n", "lst", ":=", "make", "(", "[", "]", "string", ",", "0", ",", "len", "(", "m", ")", ")", "\n", "for", "k", ":=", "range", "m", "{", "lst", "=", "append", "(", "lst", ",", "k", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "lst", ")", "\n", "return", "lst", "\n", "}" ]
// unmarshal Recipients line by line from a io.Reader.
[ "unmarshal", "Recipients", "line", "by", "line", "from", "a", "io", ".", "Reader", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/store/sub/recipients.go#L302-L322
train
gopasspw/gopass
pkg/out/print.go
Print
func Print(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprintf(Stdout, Prefix(ctx)+format+newline(ctx), args...) }
go
func Print(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprintf(Stdout, Prefix(ctx)+format+newline(ctx), args...) }
[ "func", "Print", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "Stdout", ",", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", "\n", "}" ]
// Print formats and prints the given string
[ "Print", "formats", "and", "prints", "the", "given", "string" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L31-L36
train
gopasspw/gopass
pkg/out/print.go
Debug
func Debug(ctx context.Context, format string, args ...interface{}) { if !ctxutil.IsDebug(ctx) { return } var loc string if _, file, line, ok := runtime.Caller(1); ok { file = file[strings.Index(file, "pkg/"):] file = strings.TrimPrefix(file, "pkg/") loc = fmt.Sprintf("%s:%d ", file, line) } fmt.Fprintf(Stdout, Prefix(ctx)+"[DEBUG] "+loc+format+newline(ctx), args...) }
go
func Debug(ctx context.Context, format string, args ...interface{}) { if !ctxutil.IsDebug(ctx) { return } var loc string if _, file, line, ok := runtime.Caller(1); ok { file = file[strings.Index(file, "pkg/"):] file = strings.TrimPrefix(file, "pkg/") loc = fmt.Sprintf("%s:%d ", file, line) } fmt.Fprintf(Stdout, Prefix(ctx)+"[DEBUG] "+loc+format+newline(ctx), args...) }
[ "func", "Debug", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "var", "loc", "string", "\n", "if", "_", ",", "file", ",", "line", ",", "ok", ":=", "runtime", ".", "Caller", "(", "1", ")", ";", "ok", "{", "file", "=", "file", "[", "strings", ".", "Index", "(", "file", ",", "\"pkg/\"", ")", ":", "]", "\n", "file", "=", "strings", ".", "TrimPrefix", "(", "file", ",", "\"pkg/\"", ")", "\n", "loc", "=", "fmt", ".", "Sprintf", "(", "\"%s:%d \"", ",", "file", ",", "line", ")", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "Stdout", ",", "Prefix", "(", "ctx", ")", "+", "\"[DEBUG] \"", "+", "loc", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", "\n", "}" ]
// Debug prints the given string if the debug flag is set
[ "Debug", "prints", "the", "given", "string", "if", "the", "debug", "flag", "is", "set" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L39-L52
train
gopasspw/gopass
pkg/out/print.go
Black
func Black(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlackString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Black(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlackString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Black", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "BlackString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Black prints the string in black
[ "Black", "prints", "the", "string", "in", "black" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L55-L60
train
gopasspw/gopass
pkg/out/print.go
Blue
func Blue(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlueString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Blue(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.BlueString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Blue", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "BlueString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Blue prints the string in blue
[ "Blue", "prints", "the", "string", "in", "blue" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L63-L68
train
gopasspw/gopass
pkg/out/print.go
Cyan
func Cyan(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.CyanString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Cyan(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.CyanString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Cyan", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "CyanString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Cyan prints the string in cyan
[ "Cyan", "prints", "the", "string", "in", "cyan" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L71-L76
train
gopasspw/gopass
pkg/out/print.go
Green
func Green(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.GreenString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Green(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.GreenString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Green", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "GreenString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Green prints the string in green
[ "Green", "prints", "the", "string", "in", "green" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L79-L84
train
gopasspw/gopass
pkg/out/print.go
Magenta
func Magenta(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.MagentaString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Magenta(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.MagentaString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Magenta", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "MagentaString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Magenta prints the string in magenta
[ "Magenta", "prints", "the", "string", "in", "magenta" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L87-L92
train
gopasspw/gopass
pkg/out/print.go
Red
func Red(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Red(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Red", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "RedString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Red prints the string in red
[ "Red", "prints", "the", "string", "in", "red" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L95-L100
train
gopasspw/gopass
pkg/out/print.go
Error
func Error(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stderr, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Error(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stderr, color.RedString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Error", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stderr", ",", "color", ".", "RedString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Error prints the string in red to stderr
[ "Error", "prints", "the", "string", "in", "red", "to", "stderr" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L103-L108
train
gopasspw/gopass
pkg/out/print.go
White
func White(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.WhiteString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func White(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.WhiteString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "White", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "WhiteString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// White prints the string in white
[ "White", "prints", "the", "string", "in", "white" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L111-L116
train
gopasspw/gopass
pkg/out/print.go
Yellow
func Yellow(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.YellowString(Prefix(ctx)+format+newline(ctx), args...)) }
go
func Yellow(ctx context.Context, format string, args ...interface{}) { if IsHidden(ctx) && !ctxutil.IsDebug(ctx) { return } fmt.Fprint(Stdout, color.YellowString(Prefix(ctx)+format+newline(ctx), args...)) }
[ "func", "Yellow", "(", "ctx", "context", ".", "Context", ",", "format", "string", ",", "args", "...", "interface", "{", "}", ")", "{", "if", "IsHidden", "(", "ctx", ")", "&&", "!", "ctxutil", ".", "IsDebug", "(", "ctx", ")", "{", "return", "\n", "}", "\n", "fmt", ".", "Fprint", "(", "Stdout", ",", "color", ".", "YellowString", "(", "Prefix", "(", "ctx", ")", "+", "format", "+", "newline", "(", "ctx", ")", ",", "args", "...", ")", ")", "\n", "}" ]
// Yellow prints the string in yellow
[ "Yellow", "prints", "the", "string", "in", "yellow" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/out/print.go#L119-L124
train
gopasspw/gopass
pkg/tree/simple/folder.go
Len
func (f *Folder) Len() int { l := len(f.Files) for _, f := range f.Folders { l += f.Len() } return l }
go
func (f *Folder) Len() int { l := len(f.Files) for _, f := range f.Folders { l += f.Len() } return l }
[ "func", "(", "f", "*", "Folder", ")", "Len", "(", ")", "int", "{", "l", ":=", "len", "(", "f", ".", "Files", ")", "\n", "for", "_", ",", "f", ":=", "range", "f", ".", "Folders", "{", "l", "+=", "f", ".", "Len", "(", ")", "\n", "}", "\n", "return", "l", "\n", "}" ]
// Len returns the number of entries in this folder and all subfolder including // this folder itself
[ "Len", "returns", "the", "number", "of", "entries", "in", "this", "folder", "and", "all", "subfolder", "including", "this", "folder", "itself" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L26-L32
train
gopasspw/gopass
pkg/tree/simple/folder.go
Format
func (f *Folder) Format(maxDepth int) string { return f.format("", true, maxDepth, 0) }
go
func (f *Folder) Format(maxDepth int) string { return f.format("", true, maxDepth, 0) }
[ "func", "(", "f", "*", "Folder", ")", "Format", "(", "maxDepth", "int", ")", "string", "{", "return", "f", ".", "format", "(", "\"\"", ",", "true", ",", "maxDepth", ",", "0", ")", "\n", "}" ]
// Format returns a pretty printed tree
[ "Format", "returns", "a", "pretty", "printed", "tree" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L48-L50
train
gopasspw/gopass
pkg/tree/simple/folder.go
AddFile
func (f *Folder) AddFile(name string, contentType string) error { return f.addFile(strings.Split(name, sep), contentType) }
go
func (f *Folder) AddFile(name string, contentType string) error { return f.addFile(strings.Split(name, sep), contentType) }
[ "func", "(", "f", "*", "Folder", ")", "AddFile", "(", "name", "string", ",", "contentType", "string", ")", "error", "{", "return", "f", ".", "addFile", "(", "strings", ".", "Split", "(", "name", ",", "sep", ")", ",", "contentType", ")", "\n", "}" ]
// AddFile adds a new file
[ "AddFile", "adds", "a", "new", "file" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L58-L60
train
gopasspw/gopass
pkg/tree/simple/folder.go
AddTemplate
func (f *Folder) AddTemplate(name string) error { return f.addTemplate(strings.Split(name, sep)) }
go
func (f *Folder) AddTemplate(name string) error { return f.addTemplate(strings.Split(name, sep)) }
[ "func", "(", "f", "*", "Folder", ")", "AddTemplate", "(", "name", "string", ")", "error", "{", "return", "f", ".", "addTemplate", "(", "strings", ".", "Split", "(", "name", ",", "sep", ")", ")", "\n", "}" ]
// AddTemplate adds a new template
[ "AddTemplate", "adds", "a", "new", "template" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L68-L70
train
gopasspw/gopass
pkg/tree/simple/folder.go
newFolder
func newFolder(name string) *Folder { return &Folder{ Name: name, Path: "", Folders: make(map[string]*Folder, 10), Files: make(map[string]*File, 10), } }
go
func newFolder(name string) *Folder { return &Folder{ Name: name, Path: "", Folders: make(map[string]*Folder, 10), Files: make(map[string]*File, 10), } }
[ "func", "newFolder", "(", "name", "string", ")", "*", "Folder", "{", "return", "&", "Folder", "{", "Name", ":", "name", ",", "Path", ":", "\"\"", ",", "Folders", ":", "make", "(", "map", "[", "string", "]", "*", "Folder", ",", "10", ")", ",", "Files", ":", "make", "(", "map", "[", "string", "]", "*", "File", ",", "10", ")", ",", "}", "\n", "}" ]
// newFolder creates a new, initialized folder
[ "newFolder", "creates", "a", "new", "initialized", "folder" ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L73-L80
train
gopasspw/gopass
pkg/tree/simple/folder.go
getFolder
func (f *Folder) getFolder(name string) *Folder { if next, found := f.Folders[name]; found { return next } next := newFolder(name) f.Folders[name] = next return next }
go
func (f *Folder) getFolder(name string) *Folder { if next, found := f.Folders[name]; found { return next } next := newFolder(name) f.Folders[name] = next return next }
[ "func", "(", "f", "*", "Folder", ")", "getFolder", "(", "name", "string", ")", "*", "Folder", "{", "if", "next", ",", "found", ":=", "f", ".", "Folders", "[", "name", "]", ";", "found", "{", "return", "next", "\n", "}", "\n", "next", ":=", "newFolder", "(", "name", ")", "\n", "f", ".", "Folders", "[", "name", "]", "=", "next", "\n", "return", "next", "\n", "}" ]
// getFolder returns a direct sub-folder within this folder. // name MUST NOT include filepath separators. If there is no // such folder a new one is created with that name.
[ "getFolder", "returns", "a", "direct", "sub", "-", "folder", "within", "this", "folder", ".", "name", "MUST", "NOT", "include", "filepath", "separators", ".", "If", "there", "is", "no", "such", "folder", "a", "new", "one", "is", "created", "with", "that", "name", "." ]
fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4
https://github.com/gopasspw/gopass/blob/fe4e21d62182f0f2e4ef9a0ca8168d849dc52bd4/pkg/tree/simple/folder.go#L193-L200
train