id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
1,700 | manifoldco/torus-cli | pathexp/pathexp.go | Contains | func (pe *PathExp) Contains(other *PathExp) bool {
return pe.Org.Contains(other.Org.String()) &&
pe.Project.Contains(other.Project.String()) &&
pe.Envs.Contains(other.Envs.String()) &&
pe.Services.Contains(other.Services.String()) &&
pe.Identities.Contains(other.Identities.String()) &&
pe.Instances.Contains(other.Instances.String())
} | go | func (pe *PathExp) Contains(other *PathExp) bool {
return pe.Org.Contains(other.Org.String()) &&
pe.Project.Contains(other.Project.String()) &&
pe.Envs.Contains(other.Envs.String()) &&
pe.Services.Contains(other.Services.String()) &&
pe.Identities.Contains(other.Identities.String()) &&
pe.Instances.Contains(other.Instances.String())
} | [
"func",
"(",
"pe",
"*",
"PathExp",
")",
"Contains",
"(",
"other",
"*",
"PathExp",
")",
"bool",
"{",
"return",
"pe",
".",
"Org",
".",
"Contains",
"(",
"other",
".",
"Org",
".",
"String",
"(",
")",
")",
"&&",
"pe",
".",
"Project",
".",
"Contains",
"(",
"other",
".",
"Project",
".",
"String",
"(",
")",
")",
"&&",
"pe",
".",
"Envs",
".",
"Contains",
"(",
"other",
".",
"Envs",
".",
"String",
"(",
")",
")",
"&&",
"pe",
".",
"Services",
".",
"Contains",
"(",
"other",
".",
"Services",
".",
"String",
"(",
")",
")",
"&&",
"pe",
".",
"Identities",
".",
"Contains",
"(",
"other",
".",
"Identities",
".",
"String",
"(",
")",
")",
"&&",
"pe",
".",
"Instances",
".",
"Contains",
"(",
"other",
".",
"Instances",
".",
"String",
"(",
")",
")",
"\n",
"}"
] | // Contains returns whether this path contains the subject. A path Contains
// another if it resolves to the other or they are equal. | [
"Contains",
"returns",
"whether",
"this",
"path",
"contains",
"the",
"subject",
".",
"A",
"path",
"Contains",
"another",
"if",
"it",
"resolves",
"to",
"the",
"other",
"or",
"they",
"are",
"equal",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L548-L555 |
1,701 | manifoldco/torus-cli | pathexp/pathexp.go | UnmarshalText | func (pe *PathExp) UnmarshalText(b []byte) error {
o, err := Parse(string(b))
if err != nil {
return err
}
pe.Org = o.Org
pe.Project = o.Project
pe.Envs = o.Envs
pe.Services = o.Services
pe.Instances = o.Instances
pe.Identities = o.Identities
return nil
} | go | func (pe *PathExp) UnmarshalText(b []byte) error {
o, err := Parse(string(b))
if err != nil {
return err
}
pe.Org = o.Org
pe.Project = o.Project
pe.Envs = o.Envs
pe.Services = o.Services
pe.Instances = o.Instances
pe.Identities = o.Identities
return nil
} | [
"func",
"(",
"pe",
"*",
"PathExp",
")",
"UnmarshalText",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"o",
",",
"err",
":=",
"Parse",
"(",
"string",
"(",
"b",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"pe",
".",
"Org",
"=",
"o",
".",
"Org",
"\n",
"pe",
".",
"Project",
"=",
"o",
".",
"Project",
"\n",
"pe",
".",
"Envs",
"=",
"o",
".",
"Envs",
"\n",
"pe",
".",
"Services",
"=",
"o",
".",
"Services",
"\n",
"pe",
".",
"Instances",
"=",
"o",
".",
"Instances",
"\n",
"pe",
".",
"Identities",
"=",
"o",
".",
"Identities",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // UnmarshalText implements the encoding.TextUnmarshaler interface.
// This will be used in json decoding. | [
"UnmarshalText",
"implements",
"the",
"encoding",
".",
"TextUnmarshaler",
"interface",
".",
"This",
"will",
"be",
"used",
"in",
"json",
"decoding",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L559-L573 |
1,702 | manifoldco/torus-cli | daemon/socket/proxy.go | Listen | func (p *AuthProxy) Listen() error {
mux := bone.New()
proxy := &httputil.ReverseProxy{
Transport: p.t,
Director: func(r *http.Request) {
r.URL.Scheme = p.u.Scheme
r.URL.Host = p.u.Host
r.Host = p.u.Host
r.URL.Path = r.URL.Path[6:]
if p.sess.HasToken() {
tok := string(p.sess.Token())
r.Header["Authorization"] = []string{"Bearer " + tok}
}
r.Header["User-Agent"] = []string{"Torus-Daemon/" + p.c.Version}
r.Header["X-Registry-Version"] = []string{p.c.APIVersion}
},
}
go p.o.Start()
mux.HandleFunc("/proxy/", proxyCanceler(proxy))
mux.SubRoute("/v1", routes.NewRouteMux(p.c, p.sess, p.db, p.t, p.o, p.client, p.logic, p.updates))
h := httpdown.HTTP{}
p.s = h.Serve(&http.Server{Handler: requestIDHandler(loggingHandler(mux))}, p.l)
return p.s.Wait()
} | go | func (p *AuthProxy) Listen() error {
mux := bone.New()
proxy := &httputil.ReverseProxy{
Transport: p.t,
Director: func(r *http.Request) {
r.URL.Scheme = p.u.Scheme
r.URL.Host = p.u.Host
r.Host = p.u.Host
r.URL.Path = r.URL.Path[6:]
if p.sess.HasToken() {
tok := string(p.sess.Token())
r.Header["Authorization"] = []string{"Bearer " + tok}
}
r.Header["User-Agent"] = []string{"Torus-Daemon/" + p.c.Version}
r.Header["X-Registry-Version"] = []string{p.c.APIVersion}
},
}
go p.o.Start()
mux.HandleFunc("/proxy/", proxyCanceler(proxy))
mux.SubRoute("/v1", routes.NewRouteMux(p.c, p.sess, p.db, p.t, p.o, p.client, p.logic, p.updates))
h := httpdown.HTTP{}
p.s = h.Serve(&http.Server{Handler: requestIDHandler(loggingHandler(mux))}, p.l)
return p.s.Wait()
} | [
"func",
"(",
"p",
"*",
"AuthProxy",
")",
"Listen",
"(",
")",
"error",
"{",
"mux",
":=",
"bone",
".",
"New",
"(",
")",
"\n",
"proxy",
":=",
"&",
"httputil",
".",
"ReverseProxy",
"{",
"Transport",
":",
"p",
".",
"t",
",",
"Director",
":",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"r",
".",
"URL",
".",
"Scheme",
"=",
"p",
".",
"u",
".",
"Scheme",
"\n",
"r",
".",
"URL",
".",
"Host",
"=",
"p",
".",
"u",
".",
"Host",
"\n",
"r",
".",
"Host",
"=",
"p",
".",
"u",
".",
"Host",
"\n",
"r",
".",
"URL",
".",
"Path",
"=",
"r",
".",
"URL",
".",
"Path",
"[",
"6",
":",
"]",
"\n\n",
"if",
"p",
".",
"sess",
".",
"HasToken",
"(",
")",
"{",
"tok",
":=",
"string",
"(",
"p",
".",
"sess",
".",
"Token",
"(",
")",
")",
"\n",
"r",
".",
"Header",
"[",
"\"",
"\"",
"]",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"+",
"tok",
"}",
"\n",
"}",
"\n\n",
"r",
".",
"Header",
"[",
"\"",
"\"",
"]",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"+",
"p",
".",
"c",
".",
"Version",
"}",
"\n",
"r",
".",
"Header",
"[",
"\"",
"\"",
"]",
"=",
"[",
"]",
"string",
"{",
"p",
".",
"c",
".",
"APIVersion",
"}",
"\n",
"}",
",",
"}",
"\n\n",
"go",
"p",
".",
"o",
".",
"Start",
"(",
")",
"\n\n",
"mux",
".",
"HandleFunc",
"(",
"\"",
"\"",
",",
"proxyCanceler",
"(",
"proxy",
")",
")",
"\n",
"mux",
".",
"SubRoute",
"(",
"\"",
"\"",
",",
"routes",
".",
"NewRouteMux",
"(",
"p",
".",
"c",
",",
"p",
".",
"sess",
",",
"p",
".",
"db",
",",
"p",
".",
"t",
",",
"p",
".",
"o",
",",
"p",
".",
"client",
",",
"p",
".",
"logic",
",",
"p",
".",
"updates",
")",
")",
"\n\n",
"h",
":=",
"httpdown",
".",
"HTTP",
"{",
"}",
"\n",
"p",
".",
"s",
"=",
"h",
".",
"Serve",
"(",
"&",
"http",
".",
"Server",
"{",
"Handler",
":",
"requestIDHandler",
"(",
"loggingHandler",
"(",
"mux",
")",
")",
"}",
",",
"p",
".",
"l",
")",
"\n\n",
"return",
"p",
".",
"s",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Listen starts the main loop of the AuthProxy. It returns on error, or when
// the AuthProxy is closed. | [
"Listen",
"starts",
"the",
"main",
"loop",
"of",
"the",
"AuthProxy",
".",
"It",
"returns",
"on",
"error",
"or",
"when",
"the",
"AuthProxy",
"is",
"closed",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/socket/proxy.go#L78-L107 |
1,703 | manifoldco/torus-cli | daemon/socket/proxy.go | Close | func (p *AuthProxy) Close() error {
p.o.Stop()
return p.s.Stop()
} | go | func (p *AuthProxy) Close() error {
p.o.Stop()
return p.s.Stop()
} | [
"func",
"(",
"p",
"*",
"AuthProxy",
")",
"Close",
"(",
")",
"error",
"{",
"p",
".",
"o",
".",
"Stop",
"(",
")",
"\n",
"return",
"p",
".",
"s",
".",
"Stop",
"(",
")",
"\n",
"}"
] | // Close gracefully closes the socket, ensuring all requests are finished
// within the timeout. | [
"Close",
"gracefully",
"closes",
"the",
"socket",
"ensuring",
"all",
"requests",
"are",
"finished",
"within",
"the",
"timeout",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/socket/proxy.go#L111-L114 |
1,704 | manifoldco/torus-cli | daemon/socket/proxy.go | proxyCanceler | func proxyCanceler(proxy http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
defer cancelFunc()
cw := cancelingProxyResponseWriter{
redirect: false,
written: false,
rw: w,
}
r = r.WithContext(ctx)
done := make(chan bool)
go func() {
proxy.ServeHTTP(&cw, r)
close(done)
}()
select {
case <-done:
return
case <-ctx.Done():
if ctx.Err() != context.DeadlineExceeded {
return
}
cw.redirect = true
if !cw.written {
w.WriteHeader(http.StatusRequestTimeout)
enc := json.NewEncoder(w)
err := enc.Encode(&apitypes.Error{
Type: "request_timeout",
Err: []string{"Request timed out"},
})
if err != nil {
log.Printf("Error writing response timeout: %s", err)
}
}
}
}
} | go | func proxyCanceler(proxy http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
defer cancelFunc()
cw := cancelingProxyResponseWriter{
redirect: false,
written: false,
rw: w,
}
r = r.WithContext(ctx)
done := make(chan bool)
go func() {
proxy.ServeHTTP(&cw, r)
close(done)
}()
select {
case <-done:
return
case <-ctx.Done():
if ctx.Err() != context.DeadlineExceeded {
return
}
cw.redirect = true
if !cw.written {
w.WriteHeader(http.StatusRequestTimeout)
enc := json.NewEncoder(w)
err := enc.Encode(&apitypes.Error{
Type: "request_timeout",
Err: []string{"Request timed out"},
})
if err != nil {
log.Printf("Error writing response timeout: %s", err)
}
}
}
}
} | [
"func",
"proxyCanceler",
"(",
"proxy",
"http",
".",
"Handler",
")",
"http",
".",
"HandlerFunc",
"{",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"ctx",
",",
"cancelFunc",
":=",
"context",
".",
"WithTimeout",
"(",
"context",
".",
"Background",
"(",
")",
",",
"60",
"*",
"time",
".",
"Second",
")",
"\n",
"defer",
"cancelFunc",
"(",
")",
"\n\n",
"cw",
":=",
"cancelingProxyResponseWriter",
"{",
"redirect",
":",
"false",
",",
"written",
":",
"false",
",",
"rw",
":",
"w",
",",
"}",
"\n\n",
"r",
"=",
"r",
".",
"WithContext",
"(",
"ctx",
")",
"\n",
"done",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"proxy",
".",
"ServeHTTP",
"(",
"&",
"cw",
",",
"r",
")",
"\n",
"close",
"(",
"done",
")",
"\n",
"}",
"(",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"done",
":",
"return",
"\n",
"case",
"<-",
"ctx",
".",
"Done",
"(",
")",
":",
"if",
"ctx",
".",
"Err",
"(",
")",
"!=",
"context",
".",
"DeadlineExceeded",
"{",
"return",
"\n",
"}",
"\n\n",
"cw",
".",
"redirect",
"=",
"true",
"\n",
"if",
"!",
"cw",
".",
"written",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusRequestTimeout",
")",
"\n\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"&",
"apitypes",
".",
"Error",
"{",
"Type",
":",
"\"",
"\"",
",",
"Err",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // proxyCanceler supports canceling proxied requests via a timeout, and
// returning a custom error response. | [
"proxyCanceler",
"supports",
"canceling",
"proxied",
"requests",
"via",
"a",
"timeout",
"and",
"returning",
"a",
"custom",
"error",
"response",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/socket/proxy.go#L144-L185 |
1,705 | manifoldco/torus-cli | cmd/credential_set.go | Add | func (c credentialSet) Add(cred apitypes.CredentialEnvelope) error {
if (*cred.Body).GetValue() == nil {
return errors.New("Cannot add an unset credential")
}
name := (*cred.Body).GetName()
if existing, ok := c[name]; ok {
// The new credential is either as specific, or less specific than
// the existing one. Keep the existing one.
eBody := *existing.Body
if (*cred.Body).GetPathExp().CompareSpecificity(eBody.GetPathExp()) != 1 {
return nil
}
}
c[name] = &cred
return nil
} | go | func (c credentialSet) Add(cred apitypes.CredentialEnvelope) error {
if (*cred.Body).GetValue() == nil {
return errors.New("Cannot add an unset credential")
}
name := (*cred.Body).GetName()
if existing, ok := c[name]; ok {
// The new credential is either as specific, or less specific than
// the existing one. Keep the existing one.
eBody := *existing.Body
if (*cred.Body).GetPathExp().CompareSpecificity(eBody.GetPathExp()) != 1 {
return nil
}
}
c[name] = &cred
return nil
} | [
"func",
"(",
"c",
"credentialSet",
")",
"Add",
"(",
"cred",
"apitypes",
".",
"CredentialEnvelope",
")",
"error",
"{",
"if",
"(",
"*",
"cred",
".",
"Body",
")",
".",
"GetValue",
"(",
")",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"name",
":=",
"(",
"*",
"cred",
".",
"Body",
")",
".",
"GetName",
"(",
")",
"\n",
"if",
"existing",
",",
"ok",
":=",
"c",
"[",
"name",
"]",
";",
"ok",
"{",
"// The new credential is either as specific, or less specific than",
"// the existing one. Keep the existing one.",
"eBody",
":=",
"*",
"existing",
".",
"Body",
"\n",
"if",
"(",
"*",
"cred",
".",
"Body",
")",
".",
"GetPathExp",
"(",
")",
".",
"CompareSpecificity",
"(",
"eBody",
".",
"GetPathExp",
"(",
")",
")",
"!=",
"1",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
"[",
"name",
"]",
"=",
"&",
"cred",
"\n",
"return",
"nil",
"\n",
"}"
] | // Add adds a credential to the credentialSet, replacing an existing credential
// of the same name, if the new credential is more specific.
//
// If the added credential is an unset value, it is ignored. | [
"Add",
"adds",
"a",
"credential",
"to",
"the",
"credentialSet",
"replacing",
"an",
"existing",
"credential",
"of",
"the",
"same",
"name",
"if",
"the",
"new",
"credential",
"is",
"more",
"specific",
".",
"If",
"the",
"added",
"credential",
"is",
"an",
"unset",
"value",
"it",
"is",
"ignored",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/credential_set.go#L22-L39 |
1,706 | manifoldco/torus-cli | cmd/credential_set.go | ToSlice | func (c credentialSet) ToSlice() []apitypes.CredentialEnvelope {
creds := make([]apitypes.CredentialEnvelope, len(c))
i := 0
for _, cred := range c {
creds[i] = *cred
i++
}
sort.Sort(credSorter(creds))
return creds
} | go | func (c credentialSet) ToSlice() []apitypes.CredentialEnvelope {
creds := make([]apitypes.CredentialEnvelope, len(c))
i := 0
for _, cred := range c {
creds[i] = *cred
i++
}
sort.Sort(credSorter(creds))
return creds
} | [
"func",
"(",
"c",
"credentialSet",
")",
"ToSlice",
"(",
")",
"[",
"]",
"apitypes",
".",
"CredentialEnvelope",
"{",
"creds",
":=",
"make",
"(",
"[",
"]",
"apitypes",
".",
"CredentialEnvelope",
",",
"len",
"(",
"c",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"_",
",",
"cred",
":=",
"range",
"c",
"{",
"creds",
"[",
"i",
"]",
"=",
"*",
"cred",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"sort",
".",
"Sort",
"(",
"credSorter",
"(",
"creds",
")",
")",
"\n",
"return",
"creds",
"\n",
"}"
] | // ToSlice returns a slice of the credentials in the set, in lexicographically
// sorted order by name. | [
"ToSlice",
"returns",
"a",
"slice",
"of",
"the",
"credentials",
"in",
"the",
"set",
"in",
"lexicographically",
"sorted",
"order",
"by",
"name",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/credential_set.go#L43-L53 |
1,707 | manifoldco/torus-cli | hints/hints.go | Display | func Display(possible ...Cmd) {
hint := randHint(possible)
if hint != "" {
ui.Hint(hint, false, nil)
}
} | go | func Display(possible ...Cmd) {
hint := randHint(possible)
if hint != "" {
ui.Hint(hint, false, nil)
}
} | [
"func",
"Display",
"(",
"possible",
"...",
"Cmd",
")",
"{",
"hint",
":=",
"randHint",
"(",
"possible",
")",
"\n",
"if",
"hint",
"!=",
"\"",
"\"",
"{",
"ui",
".",
"Hint",
"(",
"hint",
",",
"false",
",",
"nil",
")",
"\n",
"}",
"\n",
"}"
] | // Display chooses a random hint from the allotted commands and displays it | [
"Display",
"chooses",
"a",
"random",
"hint",
"from",
"the",
"allotted",
"commands",
"and",
"displays",
"it"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/hints/hints.go#L137-L142 |
1,708 | manifoldco/torus-cli | hints/hints.go | randHint | func randHint(possible []Cmd) string {
l := len(possible)
if l == 0 {
return ""
}
// Seed random integer
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
i := r.Intn(l)
cmd := possible[i]
if hints, ok := commandHints[cmd]; ok {
item := r.Intn(len(hints))
if len(hints) > item {
return hints[item]
}
}
return ""
} | go | func randHint(possible []Cmd) string {
l := len(possible)
if l == 0 {
return ""
}
// Seed random integer
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
i := r.Intn(l)
cmd := possible[i]
if hints, ok := commandHints[cmd]; ok {
item := r.Intn(len(hints))
if len(hints) > item {
return hints[item]
}
}
return ""
} | [
"func",
"randHint",
"(",
"possible",
"[",
"]",
"Cmd",
")",
"string",
"{",
"l",
":=",
"len",
"(",
"possible",
")",
"\n",
"if",
"l",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Seed random integer",
"r",
":=",
"rand",
".",
"New",
"(",
"rand",
".",
"NewSource",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
".",
"UnixNano",
"(",
")",
")",
")",
"\n",
"i",
":=",
"r",
".",
"Intn",
"(",
"l",
")",
"\n",
"cmd",
":=",
"possible",
"[",
"i",
"]",
"\n",
"if",
"hints",
",",
"ok",
":=",
"commandHints",
"[",
"cmd",
"]",
";",
"ok",
"{",
"item",
":=",
"r",
".",
"Intn",
"(",
"len",
"(",
"hints",
")",
")",
"\n",
"if",
"len",
"(",
"hints",
")",
">",
"item",
"{",
"return",
"hints",
"[",
"item",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // randHint returns random hint from chosen command's list | [
"randHint",
"returns",
"random",
"hint",
"from",
"chosen",
"command",
"s",
"list"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/hints/hints.go#L145-L162 |
1,709 | manifoldco/torus-cli | api/credentials.go | Search | func (c *CredentialsClient) Search(ctx context.Context, pathexp string, teamIDs []identity.ID, p ProgressFunc) ([]apitypes.CredentialEnvelope, error) {
v := &url.Values{}
v.Set("pathexp", pathexp)
v.Set("skip-decryption", "true")
for _, id := range teamIDs {
v.Add("team_id", id.String())
}
return c.listWorker(ctx, v, p)
} | go | func (c *CredentialsClient) Search(ctx context.Context, pathexp string, teamIDs []identity.ID, p ProgressFunc) ([]apitypes.CredentialEnvelope, error) {
v := &url.Values{}
v.Set("pathexp", pathexp)
v.Set("skip-decryption", "true")
for _, id := range teamIDs {
v.Add("team_id", id.String())
}
return c.listWorker(ctx, v, p)
} | [
"func",
"(",
"c",
"*",
"CredentialsClient",
")",
"Search",
"(",
"ctx",
"context",
".",
"Context",
",",
"pathexp",
"string",
",",
"teamIDs",
"[",
"]",
"identity",
".",
"ID",
",",
"p",
"ProgressFunc",
")",
"(",
"[",
"]",
"apitypes",
".",
"CredentialEnvelope",
",",
"error",
")",
"{",
"v",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"pathexp",
")",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"for",
"_",
",",
"id",
":=",
"range",
"teamIDs",
"{",
"v",
".",
"Add",
"(",
"\"",
"\"",
",",
"id",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"listWorker",
"(",
"ctx",
",",
"v",
",",
"p",
")",
"\n",
"}"
] | // Search returns all credentials at the given pathexp in an undecrypted state | [
"Search",
"returns",
"all",
"credentials",
"at",
"the",
"given",
"pathexp",
"in",
"an",
"undecrypted",
"state"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/credentials.go#L20-L30 |
1,710 | manifoldco/torus-cli | api/credentials.go | Get | func (c *CredentialsClient) Get(ctx context.Context, path string, p ProgressFunc) ([]apitypes.CredentialEnvelope, error) {
v := &url.Values{}
v.Set("path", path)
return c.listWorker(ctx, v, p)
} | go | func (c *CredentialsClient) Get(ctx context.Context, path string, p ProgressFunc) ([]apitypes.CredentialEnvelope, error) {
v := &url.Values{}
v.Set("path", path)
return c.listWorker(ctx, v, p)
} | [
"func",
"(",
"c",
"*",
"CredentialsClient",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
",",
"p",
"ProgressFunc",
")",
"(",
"[",
"]",
"apitypes",
".",
"CredentialEnvelope",
",",
"error",
")",
"{",
"v",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"path",
")",
"\n\n",
"return",
"c",
".",
"listWorker",
"(",
"ctx",
",",
"v",
",",
"p",
")",
"\n",
"}"
] | // Get returns all credentials at the given path. | [
"Get",
"returns",
"all",
"credentials",
"at",
"the",
"given",
"path",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/credentials.go#L33-L38 |
1,711 | manifoldco/torus-cli | api/credentials.go | Create | func (c *CredentialsClient) Create(ctx context.Context, creds []*apitypes.CredentialEnvelope,
progress ProgressFunc) ([]apitypes.CredentialEnvelope, error) {
resp := []apitypes.CredentialResp{}
err := c.client.DaemonRoundTrip(ctx, "POST", "/credentials", nil, creds, &resp, progress)
if err != nil {
return nil, err
}
return createEnvelopesFromResp(resp)
} | go | func (c *CredentialsClient) Create(ctx context.Context, creds []*apitypes.CredentialEnvelope,
progress ProgressFunc) ([]apitypes.CredentialEnvelope, error) {
resp := []apitypes.CredentialResp{}
err := c.client.DaemonRoundTrip(ctx, "POST", "/credentials", nil, creds, &resp, progress)
if err != nil {
return nil, err
}
return createEnvelopesFromResp(resp)
} | [
"func",
"(",
"c",
"*",
"CredentialsClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"creds",
"[",
"]",
"*",
"apitypes",
".",
"CredentialEnvelope",
",",
"progress",
"ProgressFunc",
")",
"(",
"[",
"]",
"apitypes",
".",
"CredentialEnvelope",
",",
"error",
")",
"{",
"resp",
":=",
"[",
"]",
"apitypes",
".",
"CredentialResp",
"{",
"}",
"\n",
"err",
":=",
"c",
".",
"client",
".",
"DaemonRoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"creds",
",",
"&",
"resp",
",",
"progress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"createEnvelopesFromResp",
"(",
"resp",
")",
"\n",
"}"
] | // Create creates the given credential | [
"Create",
"creates",
"the",
"given",
"credential"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/credentials.go#L51-L61 |
1,712 | manifoldco/torus-cli | identity/identity.go | NewMutable | func NewMutable(body Mutable) (ID, error) {
id := ID{idVersion, body.Type()}
_, err := rand.Read(id[2:])
if err != nil {
return ID{}, err
}
return id, nil
} | go | func NewMutable(body Mutable) (ID, error) {
id := ID{idVersion, body.Type()}
_, err := rand.Read(id[2:])
if err != nil {
return ID{}, err
}
return id, nil
} | [
"func",
"NewMutable",
"(",
"body",
"Mutable",
")",
"(",
"ID",
",",
"error",
")",
"{",
"id",
":=",
"ID",
"{",
"idVersion",
",",
"body",
".",
"Type",
"(",
")",
"}",
"\n",
"_",
",",
"err",
":=",
"rand",
".",
"Read",
"(",
"id",
"[",
"2",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ID",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"id",
",",
"nil",
"\n",
"}"
] | // NewMutable returns a new ID for a mutable object. | [
"NewMutable",
"returns",
"a",
"new",
"ID",
"for",
"a",
"mutable",
"object",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/identity/identity.go#L49-L56 |
1,713 | manifoldco/torus-cli | identity/identity.go | DeriveMutable | func DeriveMutable(body Mutable, base *ID, derivableType byte) ID {
id := ID{idVersion, body.Type(), derivableType}
copy(id[3:], base[2:17])
return id
} | go | func DeriveMutable(body Mutable, base *ID, derivableType byte) ID {
id := ID{idVersion, body.Type(), derivableType}
copy(id[3:], base[2:17])
return id
} | [
"func",
"DeriveMutable",
"(",
"body",
"Mutable",
",",
"base",
"*",
"ID",
",",
"derivableType",
"byte",
")",
"ID",
"{",
"id",
":=",
"ID",
"{",
"idVersion",
",",
"body",
".",
"Type",
"(",
")",
",",
"derivableType",
"}",
"\n",
"copy",
"(",
"id",
"[",
"3",
":",
"]",
",",
"base",
"[",
"2",
":",
"17",
"]",
")",
"\n\n",
"return",
"id",
"\n",
"}"
] | // DeriveMutable returns a ID for a mutable object based on another ID. | [
"DeriveMutable",
"returns",
"a",
"ID",
"for",
"a",
"mutable",
"object",
"based",
"on",
"another",
"ID",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/identity/identity.go#L59-L64 |
1,714 | manifoldco/torus-cli | identity/identity.go | NewImmutable | func NewImmutable(body Immutable, sig interface{}) (ID, error) {
h, err := blake2b.New(&blake2b.Config{Size: 16})
if err != nil {
return ID{}, err
}
h.Write([]byte(strconv.Itoa(body.Version())))
b, err := json.Marshal(body)
if err != nil {
return ID{}, err
}
h.Write(b)
b, err = json.Marshal(sig)
if err != nil {
return ID{}, err
}
h.Write(b)
id := ID{idVersion, body.Type()}
copy(id[2:], h.Sum(nil))
return id, nil
} | go | func NewImmutable(body Immutable, sig interface{}) (ID, error) {
h, err := blake2b.New(&blake2b.Config{Size: 16})
if err != nil {
return ID{}, err
}
h.Write([]byte(strconv.Itoa(body.Version())))
b, err := json.Marshal(body)
if err != nil {
return ID{}, err
}
h.Write(b)
b, err = json.Marshal(sig)
if err != nil {
return ID{}, err
}
h.Write(b)
id := ID{idVersion, body.Type()}
copy(id[2:], h.Sum(nil))
return id, nil
} | [
"func",
"NewImmutable",
"(",
"body",
"Immutable",
",",
"sig",
"interface",
"{",
"}",
")",
"(",
"ID",
",",
"error",
")",
"{",
"h",
",",
"err",
":=",
"blake2b",
".",
"New",
"(",
"&",
"blake2b",
".",
"Config",
"{",
"Size",
":",
"16",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ID",
"{",
"}",
",",
"err",
"\n",
"}",
"\n\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"strconv",
".",
"Itoa",
"(",
"body",
".",
"Version",
"(",
")",
")",
")",
")",
"\n\n",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ID",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"h",
".",
"Write",
"(",
"b",
")",
"\n\n",
"b",
",",
"err",
"=",
"json",
".",
"Marshal",
"(",
"sig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ID",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"h",
".",
"Write",
"(",
"b",
")",
"\n\n",
"id",
":=",
"ID",
"{",
"idVersion",
",",
"body",
".",
"Type",
"(",
")",
"}",
"\n\n",
"copy",
"(",
"id",
"[",
"2",
":",
"]",
",",
"h",
".",
"Sum",
"(",
"nil",
")",
")",
"\n\n",
"return",
"id",
",",
"nil",
"\n",
"}"
] | // NewImmutable returns a new signed ID for an immutable object.
//
// sig should be a registry.Signature type | [
"NewImmutable",
"returns",
"a",
"new",
"signed",
"ID",
"for",
"an",
"immutable",
"object",
".",
"sig",
"should",
"be",
"a",
"registry",
".",
"Signature",
"type"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/identity/identity.go#L69-L94 |
1,715 | manifoldco/torus-cli | identity/identity.go | UnmarshalJSON | func (id *ID) UnmarshalJSON(b []byte) error {
if len(b) < 2 || b[0] != byte('"') || b[len(b)-1] != byte('"') {
return errors.New("value is not a string")
}
return id.fillID(b[1 : len(b)-1])
} | go | func (id *ID) UnmarshalJSON(b []byte) error {
if len(b) < 2 || b[0] != byte('"') || b[len(b)-1] != byte('"') {
return errors.New("value is not a string")
}
return id.fillID(b[1 : len(b)-1])
} | [
"func",
"(",
"id",
"*",
"ID",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"b",
")",
"<",
"2",
"||",
"b",
"[",
"0",
"]",
"!=",
"byte",
"(",
"'\"'",
")",
"||",
"b",
"[",
"len",
"(",
"b",
")",
"-",
"1",
"]",
"!=",
"byte",
"(",
"'\"'",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"id",
".",
"fillID",
"(",
"b",
"[",
"1",
":",
"len",
"(",
"b",
")",
"-",
"1",
"]",
")",
"\n",
"}"
] | // UnmarshalJSON implements the json.Unmarshaler interface for IDs. | [
"UnmarshalJSON",
"implements",
"the",
"json",
".",
"Unmarshaler",
"interface",
"for",
"IDs",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/identity/identity.go#L125-L131 |
1,716 | manifoldco/torus-cli | gatekeeper/gatekeeper.go | New | func New(org, team, certpath, keypath string, cfg *config.Config) (g *http.Gatekeeper, err error) {
api := api.NewClient(cfg)
http, err := http.NewGatekeeper(org, team, certpath, keypath, cfg, api)
if err != nil {
return nil, err
}
return http, nil
} | go | func New(org, team, certpath, keypath string, cfg *config.Config) (g *http.Gatekeeper, err error) {
api := api.NewClient(cfg)
http, err := http.NewGatekeeper(org, team, certpath, keypath, cfg, api)
if err != nil {
return nil, err
}
return http, nil
} | [
"func",
"New",
"(",
"org",
",",
"team",
",",
"certpath",
",",
"keypath",
"string",
",",
"cfg",
"*",
"config",
".",
"Config",
")",
"(",
"g",
"*",
"http",
".",
"Gatekeeper",
",",
"err",
"error",
")",
"{",
"api",
":=",
"api",
".",
"NewClient",
"(",
"cfg",
")",
"\n",
"http",
",",
"err",
":=",
"http",
".",
"NewGatekeeper",
"(",
"org",
",",
"team",
",",
"certpath",
",",
"keypath",
",",
"cfg",
",",
"api",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"http",
",",
"nil",
"\n",
"}"
] | // New returns a new Gatekeeper | [
"New",
"returns",
"a",
"new",
"Gatekeeper"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/gatekeeper/gatekeeper.go#L12-L20 |
1,717 | manifoldco/torus-cli | registry/policies.go | Create | func (p *PoliciesClient) Create(ctx context.Context, policy *primitive.Policy) (*envelope.Policy, error) {
ID, err := identity.NewMutable(policy)
if err != nil {
return nil, err
}
env := envelope.Policy{
ID: &ID,
Version: 1,
Body: policy,
}
res := envelope.Policy{}
err = p.client.RoundTrip(ctx, "POST", "/policies", nil, env, &res)
return &res, err
} | go | func (p *PoliciesClient) Create(ctx context.Context, policy *primitive.Policy) (*envelope.Policy, error) {
ID, err := identity.NewMutable(policy)
if err != nil {
return nil, err
}
env := envelope.Policy{
ID: &ID,
Version: 1,
Body: policy,
}
res := envelope.Policy{}
err = p.client.RoundTrip(ctx, "POST", "/policies", nil, env, &res)
return &res, err
} | [
"func",
"(",
"p",
"*",
"PoliciesClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"policy",
"*",
"primitive",
".",
"Policy",
")",
"(",
"*",
"envelope",
".",
"Policy",
",",
"error",
")",
"{",
"ID",
",",
"err",
":=",
"identity",
".",
"NewMutable",
"(",
"policy",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"env",
":=",
"envelope",
".",
"Policy",
"{",
"ID",
":",
"&",
"ID",
",",
"Version",
":",
"1",
",",
"Body",
":",
"policy",
",",
"}",
"\n\n",
"res",
":=",
"envelope",
".",
"Policy",
"{",
"}",
"\n",
"err",
"=",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"env",
",",
"&",
"res",
")",
"\n",
"return",
"&",
"res",
",",
"err",
"\n",
"}"
] | // Create creates a new policy | [
"Create",
"creates",
"a",
"new",
"policy"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/policies.go#L18-L34 |
1,718 | manifoldco/torus-cli | registry/policies.go | Delete | func (p *PoliciesClient) Delete(ctx context.Context, policyID *identity.ID) error {
url := "/policies/" + policyID.String()
return p.client.RoundTrip(ctx, "DELETE", url, nil, nil, nil)
} | go | func (p *PoliciesClient) Delete(ctx context.Context, policyID *identity.ID) error {
url := "/policies/" + policyID.String()
return p.client.RoundTrip(ctx, "DELETE", url, nil, nil, nil)
} | [
"func",
"(",
"p",
"*",
"PoliciesClient",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"policyID",
"*",
"identity",
".",
"ID",
")",
"error",
"{",
"url",
":=",
"\"",
"\"",
"+",
"policyID",
".",
"String",
"(",
")",
"\n",
"return",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"url",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // Delete destroys the policy for the given ID | [
"Delete",
"destroys",
"the",
"policy",
"for",
"the",
"given",
"ID"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/policies.go#L37-L40 |
1,719 | manifoldco/torus-cli | registry/policies.go | Attach | func (p *PoliciesClient) Attach(ctx context.Context, org, policy, team *identity.ID) error {
attachment := primitive.PolicyAttachment{
OrgID: org,
OwnerID: team,
PolicyID: policy,
}
ID, err := identity.NewMutable(&attachment)
if err != nil {
return err
}
env := envelope.PolicyAttachment{
ID: &ID,
Version: 1,
Body: &attachment,
}
return p.client.RoundTrip(ctx, "POST", "/policy-attachments", nil, &env, nil)
} | go | func (p *PoliciesClient) Attach(ctx context.Context, org, policy, team *identity.ID) error {
attachment := primitive.PolicyAttachment{
OrgID: org,
OwnerID: team,
PolicyID: policy,
}
ID, err := identity.NewMutable(&attachment)
if err != nil {
return err
}
env := envelope.PolicyAttachment{
ID: &ID,
Version: 1,
Body: &attachment,
}
return p.client.RoundTrip(ctx, "POST", "/policy-attachments", nil, &env, nil)
} | [
"func",
"(",
"p",
"*",
"PoliciesClient",
")",
"Attach",
"(",
"ctx",
"context",
".",
"Context",
",",
"org",
",",
"policy",
",",
"team",
"*",
"identity",
".",
"ID",
")",
"error",
"{",
"attachment",
":=",
"primitive",
".",
"PolicyAttachment",
"{",
"OrgID",
":",
"org",
",",
"OwnerID",
":",
"team",
",",
"PolicyID",
":",
"policy",
",",
"}",
"\n\n",
"ID",
",",
"err",
":=",
"identity",
".",
"NewMutable",
"(",
"&",
"attachment",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"env",
":=",
"envelope",
".",
"PolicyAttachment",
"{",
"ID",
":",
"&",
"ID",
",",
"Version",
":",
"1",
",",
"Body",
":",
"&",
"attachment",
",",
"}",
"\n\n",
"return",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"env",
",",
"nil",
")",
"\n",
"}"
] | // Attach attaches a policy to a team | [
"Attach",
"attaches",
"a",
"policy",
"to",
"a",
"team"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/policies.go#L58-L77 |
1,720 | manifoldco/torus-cli | registry/policies.go | Detach | func (p *PoliciesClient) Detach(ctx context.Context, attachmentID *identity.ID) error {
return p.client.RoundTrip(ctx, "DELETE", "/policy-attachments/"+attachmentID.String(), nil, nil, nil)
} | go | func (p *PoliciesClient) Detach(ctx context.Context, attachmentID *identity.ID) error {
return p.client.RoundTrip(ctx, "DELETE", "/policy-attachments/"+attachmentID.String(), nil, nil, nil)
} | [
"func",
"(",
"p",
"*",
"PoliciesClient",
")",
"Detach",
"(",
"ctx",
"context",
".",
"Context",
",",
"attachmentID",
"*",
"identity",
".",
"ID",
")",
"error",
"{",
"return",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"attachmentID",
".",
"String",
"(",
")",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // Detach deletes a specific attachment | [
"Detach",
"deletes",
"a",
"specific",
"attachment"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/policies.go#L80-L82 |
1,721 | manifoldco/torus-cli | registry/policies.go | AttachmentsList | func (p *PoliciesClient) AttachmentsList(ctx context.Context, orgID, ownerID, policyID *identity.ID) ([]envelope.PolicyAttachment, error) {
v := &url.Values{}
if orgID != nil {
v.Set("org_id", orgID.String())
}
if ownerID != nil {
v.Set("owner_id", ownerID.String())
}
if policyID != nil {
v.Set("policy_id", policyID.String())
}
attachments := []envelope.PolicyAttachment{}
err := p.client.RoundTrip(ctx, "GET", "/policy-attachments", v, nil, &attachments)
return attachments, err
} | go | func (p *PoliciesClient) AttachmentsList(ctx context.Context, orgID, ownerID, policyID *identity.ID) ([]envelope.PolicyAttachment, error) {
v := &url.Values{}
if orgID != nil {
v.Set("org_id", orgID.String())
}
if ownerID != nil {
v.Set("owner_id", ownerID.String())
}
if policyID != nil {
v.Set("policy_id", policyID.String())
}
attachments := []envelope.PolicyAttachment{}
err := p.client.RoundTrip(ctx, "GET", "/policy-attachments", v, nil, &attachments)
return attachments, err
} | [
"func",
"(",
"p",
"*",
"PoliciesClient",
")",
"AttachmentsList",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
",",
"ownerID",
",",
"policyID",
"*",
"identity",
".",
"ID",
")",
"(",
"[",
"]",
"envelope",
".",
"PolicyAttachment",
",",
"error",
")",
"{",
"v",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"if",
"orgID",
"!=",
"nil",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"orgID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"ownerID",
"!=",
"nil",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"ownerID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"policyID",
"!=",
"nil",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"policyID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"attachments",
":=",
"[",
"]",
"envelope",
".",
"PolicyAttachment",
"{",
"}",
"\n",
"err",
":=",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"v",
",",
"nil",
",",
"&",
"attachments",
")",
"\n",
"return",
"attachments",
",",
"err",
"\n",
"}"
] | // AttachmentsList retrieves all policy attachments for an org | [
"AttachmentsList",
"retrieves",
"all",
"policy",
"attachments",
"for",
"an",
"org"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/policies.go#L85-L100 |
1,722 | manifoldco/torus-cli | cmd/allow.go | parseRawPath | func parseRawPath(rawPath string) (*pathexp.PathExp, *string, error) {
idx := strings.LastIndex(rawPath, "/")
if idx == -1 {
return nil, nil, errs.NewExitError("resource path format is incorrect.")
}
secret := rawPath[idx+1:]
path := rawPath[:idx]
if secret == "**" {
path = rawPath
secret = "*"
}
// Ensure that the secret name is valid
if !pathexp.ValidSecret(secret) {
return nil, nil, errs.NewExitError("Invalid secret name " + secret)
}
pe, err := parsePathExp(path)
if err != nil {
return nil, nil, errs.NewErrorExitError("Invalid path expression", err)
}
return pe, &secret, nil
} | go | func parseRawPath(rawPath string) (*pathexp.PathExp, *string, error) {
idx := strings.LastIndex(rawPath, "/")
if idx == -1 {
return nil, nil, errs.NewExitError("resource path format is incorrect.")
}
secret := rawPath[idx+1:]
path := rawPath[:idx]
if secret == "**" {
path = rawPath
secret = "*"
}
// Ensure that the secret name is valid
if !pathexp.ValidSecret(secret) {
return nil, nil, errs.NewExitError("Invalid secret name " + secret)
}
pe, err := parsePathExp(path)
if err != nil {
return nil, nil, errs.NewErrorExitError("Invalid path expression", err)
}
return pe, &secret, nil
} | [
"func",
"parseRawPath",
"(",
"rawPath",
"string",
")",
"(",
"*",
"pathexp",
".",
"PathExp",
",",
"*",
"string",
",",
"error",
")",
"{",
"idx",
":=",
"strings",
".",
"LastIndex",
"(",
"rawPath",
",",
"\"",
"\"",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"return",
"nil",
",",
"nil",
",",
"errs",
".",
"NewExitError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"secret",
":=",
"rawPath",
"[",
"idx",
"+",
"1",
":",
"]",
"\n",
"path",
":=",
"rawPath",
"[",
":",
"idx",
"]",
"\n\n",
"if",
"secret",
"==",
"\"",
"\"",
"{",
"path",
"=",
"rawPath",
"\n",
"secret",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"// Ensure that the secret name is valid",
"if",
"!",
"pathexp",
".",
"ValidSecret",
"(",
"secret",
")",
"{",
"return",
"nil",
",",
"nil",
",",
"errs",
".",
"NewExitError",
"(",
"\"",
"\"",
"+",
"secret",
")",
"\n",
"}",
"\n\n",
"pe",
",",
"err",
":=",
"parsePathExp",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errs",
".",
"NewErrorExitError",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"pe",
",",
"&",
"secret",
",",
"nil",
"\n",
"}"
] | // parseRawPath parses and validates a raw path, possibly including a secret.
// The secret portion is also validated. | [
"parseRawPath",
"parses",
"and",
"validates",
"a",
"raw",
"path",
"possibly",
"including",
"a",
"secret",
".",
"The",
"secret",
"portion",
"is",
"also",
"validated",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/allow.go#L166-L189 |
1,723 | manifoldco/torus-cli | api/keypairs.go | Revoke | func (k *KeyPairsClient) Revoke(ctx context.Context, orgID *identity.ID, output ProgressFunc) error {
return k.worker(ctx, "revoke", orgID, output)
} | go | func (k *KeyPairsClient) Revoke(ctx context.Context, orgID *identity.ID, output ProgressFunc) error {
return k.worker(ctx, "revoke", orgID, output)
} | [
"func",
"(",
"k",
"*",
"KeyPairsClient",
")",
"Revoke",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
",",
"output",
"ProgressFunc",
")",
"error",
"{",
"return",
"k",
".",
"worker",
"(",
"ctx",
",",
"\"",
"\"",
",",
"orgID",
",",
"output",
")",
"\n",
"}"
] | // Revoke revokes the existing keypairs for the user in the given org. | [
"Revoke",
"revokes",
"the",
"existing",
"keypairs",
"for",
"the",
"user",
"in",
"the",
"given",
"org",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/keypairs.go#L31-L33 |
1,724 | manifoldco/torus-cli | registry/tokens.go | PostLogin | func (t *TokensClient) PostLogin(ctx context.Context, creds apitypes.LoginCredential) (
*base64.Value, *envelope.Token, error) {
respBody := loginTokenResponse{}
var body interface{}
switch creds.Type() {
case apitypes.UserSession:
body = &loginTokenUserRequest{
Type: primitive.LoginToken,
Email: creds.Identifier(),
}
case apitypes.MachineSession:
body = &loginTokenMachineRequest{
Type: primitive.LoginToken,
TokenID: creds.Identifier(),
}
}
err := tokenRoundTrip(ctx, t.client, "", "POST", "/tokens", nil, body, &respBody)
if err != nil {
return nil, nil, err
}
return respBody.Salt, respBody.Token, nil
} | go | func (t *TokensClient) PostLogin(ctx context.Context, creds apitypes.LoginCredential) (
*base64.Value, *envelope.Token, error) {
respBody := loginTokenResponse{}
var body interface{}
switch creds.Type() {
case apitypes.UserSession:
body = &loginTokenUserRequest{
Type: primitive.LoginToken,
Email: creds.Identifier(),
}
case apitypes.MachineSession:
body = &loginTokenMachineRequest{
Type: primitive.LoginToken,
TokenID: creds.Identifier(),
}
}
err := tokenRoundTrip(ctx, t.client, "", "POST", "/tokens", nil, body, &respBody)
if err != nil {
return nil, nil, err
}
return respBody.Salt, respBody.Token, nil
} | [
"func",
"(",
"t",
"*",
"TokensClient",
")",
"PostLogin",
"(",
"ctx",
"context",
".",
"Context",
",",
"creds",
"apitypes",
".",
"LoginCredential",
")",
"(",
"*",
"base64",
".",
"Value",
",",
"*",
"envelope",
".",
"Token",
",",
"error",
")",
"{",
"respBody",
":=",
"loginTokenResponse",
"{",
"}",
"\n\n",
"var",
"body",
"interface",
"{",
"}",
"\n",
"switch",
"creds",
".",
"Type",
"(",
")",
"{",
"case",
"apitypes",
".",
"UserSession",
":",
"body",
"=",
"&",
"loginTokenUserRequest",
"{",
"Type",
":",
"primitive",
".",
"LoginToken",
",",
"Email",
":",
"creds",
".",
"Identifier",
"(",
")",
",",
"}",
"\n",
"case",
"apitypes",
".",
"MachineSession",
":",
"body",
"=",
"&",
"loginTokenMachineRequest",
"{",
"Type",
":",
"primitive",
".",
"LoginToken",
",",
"TokenID",
":",
"creds",
".",
"Identifier",
"(",
")",
",",
"}",
"\n",
"}",
"\n\n",
"err",
":=",
"tokenRoundTrip",
"(",
"ctx",
",",
"t",
".",
"client",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"body",
",",
"&",
"respBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"respBody",
".",
"Salt",
",",
"respBody",
".",
"Token",
",",
"nil",
"\n",
"}"
] | // PostLogin requests a login token from the registry for the provided email
// address. | [
"PostLogin",
"requests",
"a",
"login",
"token",
"from",
"the",
"registry",
"for",
"the",
"provided",
"email",
"address",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/tokens.go#L56-L80 |
1,725 | manifoldco/torus-cli | registry/tokens.go | PostEdDSAAuth | func (t *TokensClient) PostEdDSAAuth(ctx context.Context, token string,
sig *base64.Value) (*envelope.Token, error) {
authReq := authTokenEdDSARequest{Type: primitive.AuthToken, TokenSig: sig}
return t.postAuthWorker(ctx, token, &authReq)
} | go | func (t *TokensClient) PostEdDSAAuth(ctx context.Context, token string,
sig *base64.Value) (*envelope.Token, error) {
authReq := authTokenEdDSARequest{Type: primitive.AuthToken, TokenSig: sig}
return t.postAuthWorker(ctx, token, &authReq)
} | [
"func",
"(",
"t",
"*",
"TokensClient",
")",
"PostEdDSAAuth",
"(",
"ctx",
"context",
".",
"Context",
",",
"token",
"string",
",",
"sig",
"*",
"base64",
".",
"Value",
")",
"(",
"*",
"envelope",
".",
"Token",
",",
"error",
")",
"{",
"authReq",
":=",
"authTokenEdDSARequest",
"{",
"Type",
":",
"primitive",
".",
"AuthToken",
",",
"TokenSig",
":",
"sig",
"}",
"\n",
"return",
"t",
".",
"postAuthWorker",
"(",
"ctx",
",",
"token",
",",
"&",
"authReq",
")",
"\n",
"}"
] | // PostEdDSAAuth requests an auth token from the registry for the provided login
// token value, and it's signature. | [
"PostEdDSAAuth",
"requests",
"an",
"auth",
"token",
"from",
"the",
"registry",
"for",
"the",
"provided",
"login",
"token",
"value",
"and",
"it",
"s",
"signature",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/tokens.go#L84-L88 |
1,726 | manifoldco/torus-cli | registry/tokens.go | PostUpgradeEdDSAAuth | func (t *TokensClient) PostUpgradeEdDSAAuth(ctx context.Context, token, hmac string,
sig, publicKey *base64.Value) (*envelope.Token, error) {
authReq := authTokenUpgradeEdDSARequest{
Type: primitive.AuthToken,
TokenSig: sig,
PublicKey: publicKey,
TokenHMAC: hmac,
}
return t.postAuthWorker(ctx, token, &authReq)
} | go | func (t *TokensClient) PostUpgradeEdDSAAuth(ctx context.Context, token, hmac string,
sig, publicKey *base64.Value) (*envelope.Token, error) {
authReq := authTokenUpgradeEdDSARequest{
Type: primitive.AuthToken,
TokenSig: sig,
PublicKey: publicKey,
TokenHMAC: hmac,
}
return t.postAuthWorker(ctx, token, &authReq)
} | [
"func",
"(",
"t",
"*",
"TokensClient",
")",
"PostUpgradeEdDSAAuth",
"(",
"ctx",
"context",
".",
"Context",
",",
"token",
",",
"hmac",
"string",
",",
"sig",
",",
"publicKey",
"*",
"base64",
".",
"Value",
")",
"(",
"*",
"envelope",
".",
"Token",
",",
"error",
")",
"{",
"authReq",
":=",
"authTokenUpgradeEdDSARequest",
"{",
"Type",
":",
"primitive",
".",
"AuthToken",
",",
"TokenSig",
":",
"sig",
",",
"PublicKey",
":",
"publicKey",
",",
"TokenHMAC",
":",
"hmac",
",",
"}",
"\n\n",
"return",
"t",
".",
"postAuthWorker",
"(",
"ctx",
",",
"token",
",",
"&",
"authReq",
")",
"\n",
"}"
] | // PostUpgradeEdDSAAuth requests an auth token from the registry while
// upgrading the user from HMAC based authentication to EdDSA | [
"PostUpgradeEdDSAAuth",
"requests",
"an",
"auth",
"token",
"from",
"the",
"registry",
"while",
"upgrading",
"the",
"user",
"from",
"HMAC",
"based",
"authentication",
"to",
"EdDSA"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/tokens.go#L92-L102 |
1,727 | manifoldco/torus-cli | registry/tokens.go | Delete | func (t *TokensClient) Delete(ctx context.Context, token string) error {
return tokenRoundTrip(ctx, t.client, token, "DELETE", "/tokens/"+token, nil, nil, nil)
} | go | func (t *TokensClient) Delete(ctx context.Context, token string) error {
return tokenRoundTrip(ctx, t.client, token, "DELETE", "/tokens/"+token, nil, nil, nil)
} | [
"func",
"(",
"t",
"*",
"TokensClient",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"token",
"string",
")",
"error",
"{",
"return",
"tokenRoundTrip",
"(",
"ctx",
",",
"t",
".",
"client",
",",
"token",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"token",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // Delete deletes the token with the provided value from the registry. This
// effectively logs a user out. | [
"Delete",
"deletes",
"the",
"token",
"with",
"the",
"provided",
"value",
"from",
"the",
"registry",
".",
"This",
"effectively",
"logs",
"a",
"user",
"out",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/tokens.go#L117-L119 |
1,728 | manifoldco/torus-cli | daemon/db/db.go | NewDB | func NewDB(path string) (*DB, error) {
db := &DB{}
valid, err := db.initBolt(path)
if valid && err == nil {
return db, nil
}
if !valid {
log.Print("DB schema version is incorrect. Clearing db")
}
err = os.Remove(path)
if err != nil {
return nil, fmt.Errorf("Unable to remove db! Please manually remove %s",
path)
}
valid, err = db.initBolt(path)
if err != nil {
return nil, err
}
if !valid {
return nil, fmt.Errorf("Fatal error initializing db schema version")
}
return db, nil
} | go | func NewDB(path string) (*DB, error) {
db := &DB{}
valid, err := db.initBolt(path)
if valid && err == nil {
return db, nil
}
if !valid {
log.Print("DB schema version is incorrect. Clearing db")
}
err = os.Remove(path)
if err != nil {
return nil, fmt.Errorf("Unable to remove db! Please manually remove %s",
path)
}
valid, err = db.initBolt(path)
if err != nil {
return nil, err
}
if !valid {
return nil, fmt.Errorf("Fatal error initializing db schema version")
}
return db, nil
} | [
"func",
"NewDB",
"(",
"path",
"string",
")",
"(",
"*",
"DB",
",",
"error",
")",
"{",
"db",
":=",
"&",
"DB",
"{",
"}",
"\n\n",
"valid",
",",
"err",
":=",
"db",
".",
"initBolt",
"(",
"path",
")",
"\n",
"if",
"valid",
"&&",
"err",
"==",
"nil",
"{",
"return",
"db",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"!",
"valid",
"{",
"log",
".",
"Print",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"os",
".",
"Remove",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n\n",
"valid",
",",
"err",
"=",
"db",
".",
"initBolt",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"valid",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"db",
",",
"nil",
"\n",
"}"
] | // NewDB creates a new db or opens an existing db at the given path.
// If the db already exists but has a mismatched version, it will be cleared
// before being returned. | [
"NewDB",
"creates",
"a",
"new",
"db",
"or",
"opens",
"an",
"existing",
"db",
"at",
"the",
"given",
"path",
".",
"If",
"the",
"db",
"already",
"exists",
"but",
"has",
"a",
"mismatched",
"version",
"it",
"will",
"be",
"cleared",
"before",
"being",
"returned",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/db/db.go#L29-L57 |
1,729 | manifoldco/torus-cli | daemon/db/db.go | initBolt | func (db *DB) initBolt(path string) (bool, error) {
var err error
db.db, err = bolt.Open(path, 0600, nil)
if err != nil {
return false, err
}
return db.checkMeta()
} | go | func (db *DB) initBolt(path string) (bool, error) {
var err error
db.db, err = bolt.Open(path, 0600, nil)
if err != nil {
return false, err
}
return db.checkMeta()
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"initBolt",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"db",
".",
"db",
",",
"err",
"=",
"bolt",
".",
"Open",
"(",
"path",
",",
"0600",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"db",
".",
"checkMeta",
"(",
")",
"\n",
"}"
] | // initBolt initializes the backing bolt db, checking that the metadata schema
// version matches what we expect | [
"initBolt",
"initializes",
"the",
"backing",
"bolt",
"db",
"checking",
"that",
"the",
"metadata",
"schema",
"version",
"matches",
"what",
"we",
"expect"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/db/db.go#L66-L74 |
1,730 | manifoldco/torus-cli | daemon/db/db.go | checkMeta | func (db *DB) checkMeta() (bool, error) {
var version []byte
err := db.db.Update(func(tx *bolt.Tx) error {
meta, err := tx.CreateBucketIfNotExists([]byte("meta"))
if err != nil {
return err
}
version = meta.Get([]byte("version"))
if version != nil {
return nil
}
err = meta.Put([]byte("version"), schemaVersion)
if err != nil {
return err
}
version = schemaVersion
return nil
})
return bytes.Equal(version, schemaVersion), err
} | go | func (db *DB) checkMeta() (bool, error) {
var version []byte
err := db.db.Update(func(tx *bolt.Tx) error {
meta, err := tx.CreateBucketIfNotExists([]byte("meta"))
if err != nil {
return err
}
version = meta.Get([]byte("version"))
if version != nil {
return nil
}
err = meta.Put([]byte("version"), schemaVersion)
if err != nil {
return err
}
version = schemaVersion
return nil
})
return bytes.Equal(version, schemaVersion), err
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"checkMeta",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"version",
"[",
"]",
"byte",
"\n",
"err",
":=",
"db",
".",
"db",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"meta",
",",
"err",
":=",
"tx",
".",
"CreateBucketIfNotExists",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"version",
"=",
"meta",
".",
"Get",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"version",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"err",
"=",
"meta",
".",
"Put",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"schemaVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"version",
"=",
"schemaVersion",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n\n",
"return",
"bytes",
".",
"Equal",
"(",
"version",
",",
"schemaVersion",
")",
",",
"err",
"\n",
"}"
] | // checkMeta check's the db's metadata, ensuring the version of the db is
// correct, or setting it if it does not exist. | [
"checkMeta",
"check",
"s",
"the",
"db",
"s",
"metadata",
"ensuring",
"the",
"version",
"of",
"the",
"db",
"is",
"correct",
"or",
"setting",
"it",
"if",
"it",
"does",
"not",
"exist",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/db/db.go#L78-L100 |
1,731 | manifoldco/torus-cli | daemon/db/db.go | Set | func (db *DB) Set(envs ...envelope.Envelope) error {
return db.db.Update(func(tx *bolt.Tx) error {
for _, env := range envs {
id := env.GetID()
b, err := json.Marshal(env)
if err != nil {
return err
}
bucket, err := tx.CreateBucketIfNotExists([]byte{id.Type()})
if err != nil {
return err
}
err = bucket.Put(id[:], b)
if err != nil {
return err
}
}
return nil
})
} | go | func (db *DB) Set(envs ...envelope.Envelope) error {
return db.db.Update(func(tx *bolt.Tx) error {
for _, env := range envs {
id := env.GetID()
b, err := json.Marshal(env)
if err != nil {
return err
}
bucket, err := tx.CreateBucketIfNotExists([]byte{id.Type()})
if err != nil {
return err
}
err = bucket.Put(id[:], b)
if err != nil {
return err
}
}
return nil
})
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Set",
"(",
"envs",
"...",
"envelope",
".",
"Envelope",
")",
"error",
"{",
"return",
"db",
".",
"db",
".",
"Update",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"for",
"_",
",",
"env",
":=",
"range",
"envs",
"{",
"id",
":=",
"env",
".",
"GetID",
"(",
")",
"\n\n",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"env",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"bucket",
",",
"err",
":=",
"tx",
".",
"CreateBucketIfNotExists",
"(",
"[",
"]",
"byte",
"{",
"id",
".",
"Type",
"(",
")",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"bucket",
".",
"Put",
"(",
"id",
"[",
":",
"]",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"}"
] | // Set stores the serialized value of env into the db, under key id.
// Stored values are grouped by their type. | [
"Set",
"stores",
"the",
"serialized",
"value",
"of",
"env",
"into",
"the",
"db",
"under",
"key",
"id",
".",
"Stored",
"values",
"are",
"grouped",
"by",
"their",
"type",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/db/db.go#L104-L126 |
1,732 | manifoldco/torus-cli | daemon/db/db.go | Get | func (db *DB) Get(id *identity.ID, env envelope.Envelope) error {
return db.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte{id.Type()})
if bucket == nil {
return errors.New("ID not found")
}
b := bucket.Get(id[:])
if b == nil {
return errors.New("ID not found")
}
return json.Unmarshal(b, env)
})
} | go | func (db *DB) Get(id *identity.ID, env envelope.Envelope) error {
return db.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte{id.Type()})
if bucket == nil {
return errors.New("ID not found")
}
b := bucket.Get(id[:])
if b == nil {
return errors.New("ID not found")
}
return json.Unmarshal(b, env)
})
} | [
"func",
"(",
"db",
"*",
"DB",
")",
"Get",
"(",
"id",
"*",
"identity",
".",
"ID",
",",
"env",
"envelope",
".",
"Envelope",
")",
"error",
"{",
"return",
"db",
".",
"db",
".",
"View",
"(",
"func",
"(",
"tx",
"*",
"bolt",
".",
"Tx",
")",
"error",
"{",
"bucket",
":=",
"tx",
".",
"Bucket",
"(",
"[",
"]",
"byte",
"{",
"id",
".",
"Type",
"(",
")",
"}",
")",
"\n",
"if",
"bucket",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"b",
":=",
"bucket",
".",
"Get",
"(",
"id",
"[",
":",
"]",
")",
"\n",
"if",
"b",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"env",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Get returns the value of id in env. It returns an error if id does not exist. | [
"Get",
"returns",
"the",
"value",
"of",
"id",
"in",
"env",
".",
"It",
"returns",
"an",
"error",
"if",
"id",
"does",
"not",
"exist",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/db/db.go#L129-L143 |
1,733 | manifoldco/torus-cli | primitive/primitive.go | NewClaim | func NewClaim(orgID, ownerID, previous, pubKeyID *identity.ID, claimType ClaimType) *Claim {
return &Claim{
OrgID: orgID,
OwnerID: ownerID,
Previous: previous,
PublicKeyID: pubKeyID,
ClaimType: claimType,
Created: time.Now().UTC(),
}
} | go | func NewClaim(orgID, ownerID, previous, pubKeyID *identity.ID, claimType ClaimType) *Claim {
return &Claim{
OrgID: orgID,
OwnerID: ownerID,
Previous: previous,
PublicKeyID: pubKeyID,
ClaimType: claimType,
Created: time.Now().UTC(),
}
} | [
"func",
"NewClaim",
"(",
"orgID",
",",
"ownerID",
",",
"previous",
",",
"pubKeyID",
"*",
"identity",
".",
"ID",
",",
"claimType",
"ClaimType",
")",
"*",
"Claim",
"{",
"return",
"&",
"Claim",
"{",
"OrgID",
":",
"orgID",
",",
"OwnerID",
":",
"ownerID",
",",
"Previous",
":",
"previous",
",",
"PublicKeyID",
":",
"pubKeyID",
",",
"ClaimType",
":",
"claimType",
",",
"Created",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewClaim returns a new Claim, with the created time set to now | [
"NewClaim",
"returns",
"a",
"new",
"Claim",
"with",
"the",
"created",
"time",
"set",
"to",
"now"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/primitive/primitive.go#L195-L204 |
1,734 | manifoldco/torus-cli | primitive/primitive.go | NewKeyring | func NewKeyring(orgID, projectID *identity.ID, pathExp *pathexp.PathExp) *Keyring {
return &Keyring{
BaseKeyring: BaseKeyring{
Created: time.Now().UTC(),
OrgID: orgID,
PathExp: pathExp,
ProjectID: projectID,
// This is the first instance of the keyring, so version is 1,
// and there is no previous instance.
Previous: nil,
KeyringVersion: 1,
},
}
} | go | func NewKeyring(orgID, projectID *identity.ID, pathExp *pathexp.PathExp) *Keyring {
return &Keyring{
BaseKeyring: BaseKeyring{
Created: time.Now().UTC(),
OrgID: orgID,
PathExp: pathExp,
ProjectID: projectID,
// This is the first instance of the keyring, so version is 1,
// and there is no previous instance.
Previous: nil,
KeyringVersion: 1,
},
}
} | [
"func",
"NewKeyring",
"(",
"orgID",
",",
"projectID",
"*",
"identity",
".",
"ID",
",",
"pathExp",
"*",
"pathexp",
".",
"PathExp",
")",
"*",
"Keyring",
"{",
"return",
"&",
"Keyring",
"{",
"BaseKeyring",
":",
"BaseKeyring",
"{",
"Created",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
",",
"OrgID",
":",
"orgID",
",",
"PathExp",
":",
"pathExp",
",",
"ProjectID",
":",
"projectID",
",",
"// This is the first instance of the keyring, so version is 1,",
"// and there is no previous instance.",
"Previous",
":",
"nil",
",",
"KeyringVersion",
":",
"1",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewKeyring returns a new v2 Keyring, with the created time set to now | [
"NewKeyring",
"returns",
"a",
"new",
"v2",
"Keyring",
"with",
"the",
"created",
"time",
"set",
"to",
"now"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/primitive/primitive.go#L272-L286 |
1,735 | manifoldco/torus-cli | primitive/primitive.go | MarshalText | func (pe *PolicyEffect) MarshalText() ([]byte, error) {
if *pe {
return []byte("allow"), nil
}
return []byte("deny"), nil
} | go | func (pe *PolicyEffect) MarshalText() ([]byte, error) {
if *pe {
return []byte("allow"), nil
}
return []byte("deny"), nil
} | [
"func",
"(",
"pe",
"*",
"PolicyEffect",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"*",
"pe",
"{",
"return",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}"
] | // MarshalText implements the encoding.TextMarshaler interface, used for JSON
// marshaling. | [
"MarshalText",
"implements",
"the",
"encoding",
".",
"TextMarshaler",
"interface",
"used",
"for",
"JSON",
"marshaling",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/primitive/primitive.go#L587-L592 |
1,736 | manifoldco/torus-cli | primitive/primitive.go | MarshalJSON | func (pa *PolicyAction) MarshalJSON() ([]byte, error) {
out := []string{}
for i, v := range policyActionStrings {
if (1<<uint(i))&byte(*pa) > 0 {
out = append(out, v)
}
}
if len(out) == 1 {
return json.Marshal(out[0])
}
return json.Marshal(out)
} | go | func (pa *PolicyAction) MarshalJSON() ([]byte, error) {
out := []string{}
for i, v := range policyActionStrings {
if (1<<uint(i))&byte(*pa) > 0 {
out = append(out, v)
}
}
if len(out) == 1 {
return json.Marshal(out[0])
}
return json.Marshal(out)
} | [
"func",
"(",
"pa",
"*",
"PolicyAction",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"out",
":=",
"[",
"]",
"string",
"{",
"}",
"\n\n",
"for",
"i",
",",
"v",
":=",
"range",
"policyActionStrings",
"{",
"if",
"(",
"1",
"<<",
"uint",
"(",
"i",
")",
")",
"&",
"byte",
"(",
"*",
"pa",
")",
">",
"0",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"out",
")",
"==",
"1",
"{",
"return",
"json",
".",
"Marshal",
"(",
"out",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"json",
".",
"Marshal",
"(",
"out",
")",
"\n",
"}"
] | // MarshalJSON implements the json.Marshaler interface. A PolicyAction is
// encoded in JSON either the string representations of its actions in a list,
// or a single string when there is only one action. | [
"MarshalJSON",
"implements",
"the",
"json",
".",
"Marshaler",
"interface",
".",
"A",
"PolicyAction",
"is",
"encoded",
"in",
"JSON",
"either",
"the",
"string",
"representations",
"of",
"its",
"actions",
"in",
"a",
"list",
"or",
"a",
"single",
"string",
"when",
"there",
"is",
"only",
"one",
"action",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/primitive/primitive.go#L630-L644 |
1,737 | manifoldco/torus-cli | primitive/primitive.go | ShortString | func (pa *PolicyAction) ShortString() string {
out := []byte{}
for i, v := range policyActionStrings {
if (1<<uint(i))&byte(*pa) > 0 {
out = append(out, v[0])
} else {
out = append(out, '-')
}
}
return string(out)
} | go | func (pa *PolicyAction) ShortString() string {
out := []byte{}
for i, v := range policyActionStrings {
if (1<<uint(i))&byte(*pa) > 0 {
out = append(out, v[0])
} else {
out = append(out, '-')
}
}
return string(out)
} | [
"func",
"(",
"pa",
"*",
"PolicyAction",
")",
"ShortString",
"(",
")",
"string",
"{",
"out",
":=",
"[",
"]",
"byte",
"{",
"}",
"\n\n",
"for",
"i",
",",
"v",
":=",
"range",
"policyActionStrings",
"{",
"if",
"(",
"1",
"<<",
"uint",
"(",
"i",
")",
")",
"&",
"byte",
"(",
"*",
"pa",
")",
">",
"0",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"v",
"[",
"0",
"]",
")",
"\n",
"}",
"else",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"'-'",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"string",
"(",
"out",
")",
"\n",
"}"
] | // ShortString displays a single character representation of each of the
// policy's actions. | [
"ShortString",
"displays",
"a",
"single",
"character",
"representation",
"of",
"each",
"of",
"the",
"policy",
"s",
"actions",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/primitive/primitive.go#L687-L699 |
1,738 | manifoldco/torus-cli | api/org_invites.go | Approve | func (i *OrgInvitesClient) Approve(ctx context.Context, inviteID identity.ID, output ProgressFunc) error {
return i.client.DaemonRoundTrip(ctx, "POST", "/org-invites/"+inviteID.String()+"/approve", nil, nil, nil, output)
} | go | func (i *OrgInvitesClient) Approve(ctx context.Context, inviteID identity.ID, output ProgressFunc) error {
return i.client.DaemonRoundTrip(ctx, "POST", "/org-invites/"+inviteID.String()+"/approve", nil, nil, nil, output)
} | [
"func",
"(",
"i",
"*",
"OrgInvitesClient",
")",
"Approve",
"(",
"ctx",
"context",
".",
"Context",
",",
"inviteID",
"identity",
".",
"ID",
",",
"output",
"ProgressFunc",
")",
"error",
"{",
"return",
"i",
".",
"client",
".",
"DaemonRoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"inviteID",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"nil",
",",
"output",
")",
"\n",
"}"
] | // Approve executes the approve invite request | [
"Approve",
"executes",
"the",
"approve",
"invite",
"request"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/org_invites.go#L22-L24 |
1,739 | manifoldco/torus-cli | daemon/logic/worklog.go | List | func (w *Worklog) List(ctx context.Context, orgID *identity.ID,
itemType apitypes.WorklogType) ([]apitypes.WorklogItem, error) {
org, err := w.engine.client.Orgs.Get(ctx, orgID)
if err != nil {
return nil, err
}
var items []apitypes.WorklogItem
for t, h := range w.handlers {
if t&itemType == 0 {
continue
}
hItems, err := h.list(ctx, org)
if err != nil {
return nil, err
}
items = append(items, hItems...)
}
return items, nil
} | go | func (w *Worklog) List(ctx context.Context, orgID *identity.ID,
itemType apitypes.WorklogType) ([]apitypes.WorklogItem, error) {
org, err := w.engine.client.Orgs.Get(ctx, orgID)
if err != nil {
return nil, err
}
var items []apitypes.WorklogItem
for t, h := range w.handlers {
if t&itemType == 0 {
continue
}
hItems, err := h.list(ctx, org)
if err != nil {
return nil, err
}
items = append(items, hItems...)
}
return items, nil
} | [
"func",
"(",
"w",
"*",
"Worklog",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
",",
"itemType",
"apitypes",
".",
"WorklogType",
")",
"(",
"[",
"]",
"apitypes",
".",
"WorklogItem",
",",
"error",
")",
"{",
"org",
",",
"err",
":=",
"w",
".",
"engine",
".",
"client",
".",
"Orgs",
".",
"Get",
"(",
"ctx",
",",
"orgID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"items",
"[",
"]",
"apitypes",
".",
"WorklogItem",
"\n",
"for",
"t",
",",
"h",
":=",
"range",
"w",
".",
"handlers",
"{",
"if",
"t",
"&",
"itemType",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"hItems",
",",
"err",
":=",
"h",
".",
"list",
"(",
"ctx",
",",
"org",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"items",
"=",
"append",
"(",
"items",
",",
"hItems",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"items",
",",
"nil",
"\n",
"}"
] | // List returns the list of all outstanding worklog items for the given org | [
"List",
"returns",
"the",
"list",
"of",
"all",
"outstanding",
"worklog",
"items",
"for",
"the",
"given",
"org"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/worklog.go#L60-L82 |
1,740 | manifoldco/torus-cli | daemon/logic/worklog.go | Get | func (w *Worklog) Get(ctx context.Context, orgID *identity.ID,
ident *apitypes.WorklogID) (*apitypes.WorklogItem, error) {
items, err := w.List(ctx, orgID, ident.Type())
if err != nil {
return nil, err
}
for _, item := range items {
if *item.ID == *ident {
return &item, nil
}
}
return nil, nil
} | go | func (w *Worklog) Get(ctx context.Context, orgID *identity.ID,
ident *apitypes.WorklogID) (*apitypes.WorklogItem, error) {
items, err := w.List(ctx, orgID, ident.Type())
if err != nil {
return nil, err
}
for _, item := range items {
if *item.ID == *ident {
return &item, nil
}
}
return nil, nil
} | [
"func",
"(",
"w",
"*",
"Worklog",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
",",
"ident",
"*",
"apitypes",
".",
"WorklogID",
")",
"(",
"*",
"apitypes",
".",
"WorklogItem",
",",
"error",
")",
"{",
"items",
",",
"err",
":=",
"w",
".",
"List",
"(",
"ctx",
",",
"orgID",
",",
"ident",
".",
"Type",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"item",
":=",
"range",
"items",
"{",
"if",
"*",
"item",
".",
"ID",
"==",
"*",
"ident",
"{",
"return",
"&",
"item",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // Get returns a single worklog item for the given org with the given ident. | [
"Get",
"returns",
"a",
"single",
"worklog",
"item",
"for",
"the",
"given",
"org",
"with",
"the",
"given",
"ident",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/worklog.go#L85-L100 |
1,741 | manifoldco/torus-cli | daemon/logic/worklog.go | Resolve | func (w *Worklog) Resolve(ctx context.Context, n *observer.Notifier,
orgID *identity.ID, ident *apitypes.WorklogID) error {
item, err := w.Get(ctx, orgID, ident)
if err != nil {
return err
}
if item == nil {
return nil
}
for t, h := range w.handlers {
if t&item.Type() == 0 {
continue
}
return h.resolve(ctx, n, orgID, item)
}
panic("worklog handler not found for type")
} | go | func (w *Worklog) Resolve(ctx context.Context, n *observer.Notifier,
orgID *identity.ID, ident *apitypes.WorklogID) error {
item, err := w.Get(ctx, orgID, ident)
if err != nil {
return err
}
if item == nil {
return nil
}
for t, h := range w.handlers {
if t&item.Type() == 0 {
continue
}
return h.resolve(ctx, n, orgID, item)
}
panic("worklog handler not found for type")
} | [
"func",
"(",
"w",
"*",
"Worklog",
")",
"Resolve",
"(",
"ctx",
"context",
".",
"Context",
",",
"n",
"*",
"observer",
".",
"Notifier",
",",
"orgID",
"*",
"identity",
".",
"ID",
",",
"ident",
"*",
"apitypes",
".",
"WorklogID",
")",
"error",
"{",
"item",
",",
"err",
":=",
"w",
".",
"Get",
"(",
"ctx",
",",
"orgID",
",",
"ident",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"item",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"t",
",",
"h",
":=",
"range",
"w",
".",
"handlers",
"{",
"if",
"t",
"&",
"item",
".",
"Type",
"(",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"return",
"h",
".",
"resolve",
"(",
"ctx",
",",
"n",
",",
"orgID",
",",
"item",
")",
"\n",
"}",
"\n\n",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // Resolve attempts to resolve the worklog item in the given org with the given
// ident. | [
"Resolve",
"attempts",
"to",
"resolve",
"the",
"worklog",
"item",
"in",
"the",
"given",
"org",
"with",
"the",
"given",
"ident",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/worklog.go#L104-L125 |
1,742 | manifoldco/torus-cli | registry/users.go | Create | func (u *UsersClient) Create(ctx context.Context, userObj *envelope.User,
signup apitypes.Signup) (envelope.UserInf, error) {
v := &url.Values{}
if signup.InviteCode != "" {
v.Set("code", signup.InviteCode)
}
if signup.OrgInvite && signup.OrgName != "" {
v.Set("org", signup.OrgName)
}
if signup.Email != "" {
v.Set("email", signup.Email)
}
e := envelope.Unsigned{}
err := u.client.RoundTrip(ctx, "POST", "/users", v, &userObj, &e)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | go | func (u *UsersClient) Create(ctx context.Context, userObj *envelope.User,
signup apitypes.Signup) (envelope.UserInf, error) {
v := &url.Values{}
if signup.InviteCode != "" {
v.Set("code", signup.InviteCode)
}
if signup.OrgInvite && signup.OrgName != "" {
v.Set("org", signup.OrgName)
}
if signup.Email != "" {
v.Set("email", signup.Email)
}
e := envelope.Unsigned{}
err := u.client.RoundTrip(ctx, "POST", "/users", v, &userObj, &e)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | [
"func",
"(",
"u",
"*",
"UsersClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"userObj",
"*",
"envelope",
".",
"User",
",",
"signup",
"apitypes",
".",
"Signup",
")",
"(",
"envelope",
".",
"UserInf",
",",
"error",
")",
"{",
"v",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"if",
"signup",
".",
"InviteCode",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"signup",
".",
"InviteCode",
")",
"\n",
"}",
"\n",
"if",
"signup",
".",
"OrgInvite",
"&&",
"signup",
".",
"OrgName",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"signup",
".",
"OrgName",
")",
"\n",
"}",
"\n",
"if",
"signup",
".",
"Email",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"signup",
".",
"Email",
")",
"\n",
"}",
"\n\n",
"e",
":=",
"envelope",
".",
"Unsigned",
"{",
"}",
"\n",
"err",
":=",
"u",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"v",
",",
"&",
"userObj",
",",
"&",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"envelope",
".",
"ConvertUser",
"(",
"&",
"e",
")",
"\n",
"}"
] | // Create attempts to register a new user | [
"Create",
"attempts",
"to",
"register",
"a",
"new",
"user"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/users.go#L17-L38 |
1,743 | manifoldco/torus-cli | registry/users.go | VerifyEmail | func (u *UsersClient) VerifyEmail(ctx context.Context, verifyCode string) error {
verify := apitypes.VerifyEmail{
Code: verifyCode,
}
return u.client.RoundTrip(ctx, "POST", "/users/verify", nil, &verify, nil)
} | go | func (u *UsersClient) VerifyEmail(ctx context.Context, verifyCode string) error {
verify := apitypes.VerifyEmail{
Code: verifyCode,
}
return u.client.RoundTrip(ctx, "POST", "/users/verify", nil, &verify, nil)
} | [
"func",
"(",
"u",
"*",
"UsersClient",
")",
"VerifyEmail",
"(",
"ctx",
"context",
".",
"Context",
",",
"verifyCode",
"string",
")",
"error",
"{",
"verify",
":=",
"apitypes",
".",
"VerifyEmail",
"{",
"Code",
":",
"verifyCode",
",",
"}",
"\n",
"return",
"u",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"verify",
",",
"nil",
")",
"\n",
"}"
] | // VerifyEmail will confirm the user's email with the registry | [
"VerifyEmail",
"will",
"confirm",
"the",
"user",
"s",
"email",
"with",
"the",
"registry"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/users.go#L41-L46 |
1,744 | manifoldco/torus-cli | registry/users.go | Update | func (u *UsersClient) Update(ctx context.Context, userObj interface{}) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.RoundTrip(ctx, "PATCH", "/users/self", nil, userObj, &e)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | go | func (u *UsersClient) Update(ctx context.Context, userObj interface{}) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.RoundTrip(ctx, "PATCH", "/users/self", nil, userObj, &e)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | [
"func",
"(",
"u",
"*",
"UsersClient",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"userObj",
"interface",
"{",
"}",
")",
"(",
"envelope",
".",
"UserInf",
",",
"error",
")",
"{",
"e",
":=",
"envelope",
".",
"Unsigned",
"{",
"}",
"\n",
"err",
":=",
"u",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"userObj",
",",
"&",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"envelope",
".",
"ConvertUser",
"(",
"&",
"e",
")",
"\n",
"}"
] | // Update patches the user object with whitelisted fields | [
"Update",
"patches",
"the",
"user",
"object",
"with",
"whitelisted",
"fields"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/users.go#L49-L57 |
1,745 | manifoldco/torus-cli | daemon/logic/engine.go | ApproveInvite | func (e *Engine) ApproveInvite(ctx context.Context, notifier *observer.Notifier,
InviteID *identity.ID) (*envelope.OrgInvite, error) {
n := notifier.Notifier(3)
invite, err := e.client.OrgInvites.Get(ctx, InviteID)
if err != nil {
log.Printf("could not fetch org invitation: %s", err)
return nil, err
}
if invite.Body.State != primitive.OrgInviteAcceptedState {
log.Printf("invitation not in accepted state: %s", invite.Body.State)
return nil, &apitypes.Error{
Type: apitypes.BadRequestError,
Err: []string{"Invite must be accepted before it can be approved"},
}
}
n.Notify(observer.Progress, "Invite retrieved", true)
v1members, v2members, err := createKeyringMemberships(ctx, e.crypto,
e.client, e.session, invite.Body.OrgID, invite.Body.InviteeID)
if err != nil {
return nil, err
}
n.Notify(observer.Progress, "Keyring memberships created", true)
invite, err = e.client.OrgInvites.Approve(ctx, InviteID)
if err != nil {
log.Printf("could not approve org invite: %s", err)
return nil, err
}
n.Notify(observer.Progress, "Invite approved", true)
if len(v1members) != 0 {
_, err = e.client.KeyringMember.Post(ctx, v1members)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return nil, err
}
}
for _, member := range v2members {
err = e.client.Keyring.Members.Post(ctx, member)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return nil, err
}
}
return invite, nil
} | go | func (e *Engine) ApproveInvite(ctx context.Context, notifier *observer.Notifier,
InviteID *identity.ID) (*envelope.OrgInvite, error) {
n := notifier.Notifier(3)
invite, err := e.client.OrgInvites.Get(ctx, InviteID)
if err != nil {
log.Printf("could not fetch org invitation: %s", err)
return nil, err
}
if invite.Body.State != primitive.OrgInviteAcceptedState {
log.Printf("invitation not in accepted state: %s", invite.Body.State)
return nil, &apitypes.Error{
Type: apitypes.BadRequestError,
Err: []string{"Invite must be accepted before it can be approved"},
}
}
n.Notify(observer.Progress, "Invite retrieved", true)
v1members, v2members, err := createKeyringMemberships(ctx, e.crypto,
e.client, e.session, invite.Body.OrgID, invite.Body.InviteeID)
if err != nil {
return nil, err
}
n.Notify(observer.Progress, "Keyring memberships created", true)
invite, err = e.client.OrgInvites.Approve(ctx, InviteID)
if err != nil {
log.Printf("could not approve org invite: %s", err)
return nil, err
}
n.Notify(observer.Progress, "Invite approved", true)
if len(v1members) != 0 {
_, err = e.client.KeyringMember.Post(ctx, v1members)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return nil, err
}
}
for _, member := range v2members {
err = e.client.Keyring.Members.Post(ctx, member)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return nil, err
}
}
return invite, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"ApproveInvite",
"(",
"ctx",
"context",
".",
"Context",
",",
"notifier",
"*",
"observer",
".",
"Notifier",
",",
"InviteID",
"*",
"identity",
".",
"ID",
")",
"(",
"*",
"envelope",
".",
"OrgInvite",
",",
"error",
")",
"{",
"n",
":=",
"notifier",
".",
"Notifier",
"(",
"3",
")",
"\n\n",
"invite",
",",
"err",
":=",
"e",
".",
"client",
".",
"OrgInvites",
".",
"Get",
"(",
"ctx",
",",
"InviteID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"invite",
".",
"Body",
".",
"State",
"!=",
"primitive",
".",
"OrgInviteAcceptedState",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"invite",
".",
"Body",
".",
"State",
")",
"\n",
"return",
"nil",
",",
"&",
"apitypes",
".",
"Error",
"{",
"Type",
":",
"apitypes",
".",
"BadRequestError",
",",
"Err",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"\n",
"}",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n\n",
"v1members",
",",
"v2members",
",",
"err",
":=",
"createKeyringMemberships",
"(",
"ctx",
",",
"e",
".",
"crypto",
",",
"e",
".",
"client",
",",
"e",
".",
"session",
",",
"invite",
".",
"Body",
".",
"OrgID",
",",
"invite",
".",
"Body",
".",
"InviteeID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n\n",
"invite",
",",
"err",
"=",
"e",
".",
"client",
".",
"OrgInvites",
".",
"Approve",
"(",
"ctx",
",",
"InviteID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n\n",
"if",
"len",
"(",
"v1members",
")",
"!=",
"0",
"{",
"_",
",",
"err",
"=",
"e",
".",
"client",
".",
"KeyringMember",
".",
"Post",
"(",
"ctx",
",",
"v1members",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"member",
":=",
"range",
"v2members",
"{",
"err",
"=",
"e",
".",
"client",
".",
"Keyring",
".",
"Members",
".",
"Post",
"(",
"ctx",
",",
"member",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"invite",
",",
"nil",
"\n",
"}"
] | // ApproveInvite approves an invitation of a user into an organzation by
// encoding them into a Keyring. | [
"ApproveInvite",
"approves",
"an",
"invitation",
"of",
"a",
"user",
"into",
"an",
"organzation",
"by",
"encoding",
"them",
"into",
"a",
"Keyring",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/engine.go#L435-L489 |
1,746 | manifoldco/torus-cli | registry/version.go | Get | func (v *VersionClient) Get(ctx context.Context) (*apitypes.Version, error) {
version := apitypes.Version{}
err := v.client.RoundTrip(ctx, "GET", "/version", nil, nil, &version)
return &version, err
} | go | func (v *VersionClient) Get(ctx context.Context) (*apitypes.Version, error) {
version := apitypes.Version{}
err := v.client.RoundTrip(ctx, "GET", "/version", nil, nil, &version)
return &version, err
} | [
"func",
"(",
"v",
"*",
"VersionClient",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"apitypes",
".",
"Version",
",",
"error",
")",
"{",
"version",
":=",
"apitypes",
".",
"Version",
"{",
"}",
"\n",
"err",
":=",
"v",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"&",
"version",
")",
"\n",
"return",
"&",
"version",
",",
"err",
"\n",
"}"
] | // Get returns the registry's release version. | [
"Get",
"returns",
"the",
"registry",
"s",
"release",
"version",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/version.go#L16-L20 |
1,747 | manifoldco/torus-cli | registry/projects.go | Create | func (p *ProjectsClient) Create(ctx context.Context, org *identity.ID, name string) (*envelope.Project, error) {
project := projectCreateRequest{}
project.Body.OrgID = org
project.Body.Name = name
res := envelope.Project{}
err := p.client.RoundTrip(ctx, "POST", "/projects", nil, &project, &res)
return &res, err
} | go | func (p *ProjectsClient) Create(ctx context.Context, org *identity.ID, name string) (*envelope.Project, error) {
project := projectCreateRequest{}
project.Body.OrgID = org
project.Body.Name = name
res := envelope.Project{}
err := p.client.RoundTrip(ctx, "POST", "/projects", nil, &project, &res)
return &res, err
} | [
"func",
"(",
"p",
"*",
"ProjectsClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"org",
"*",
"identity",
".",
"ID",
",",
"name",
"string",
")",
"(",
"*",
"envelope",
".",
"Project",
",",
"error",
")",
"{",
"project",
":=",
"projectCreateRequest",
"{",
"}",
"\n",
"project",
".",
"Body",
".",
"OrgID",
"=",
"org",
"\n",
"project",
".",
"Body",
".",
"Name",
"=",
"name",
"\n\n",
"res",
":=",
"envelope",
".",
"Project",
"{",
"}",
"\n",
"err",
":=",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"project",
",",
"&",
"res",
")",
"\n",
"return",
"&",
"res",
",",
"err",
"\n",
"}"
] | // Create creates a new project with the given name within the given org | [
"Create",
"creates",
"a",
"new",
"project",
"with",
"the",
"given",
"name",
"within",
"the",
"given",
"org"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/projects.go#L34-L42 |
1,748 | manifoldco/torus-cli | registry/projects.go | List | func (p *ProjectsClient) List(ctx context.Context, orgID *identity.ID) ([]envelope.Project, error) {
orgs := []identity.ID{*orgID}
return p.Search(ctx, orgs, nil)
} | go | func (p *ProjectsClient) List(ctx context.Context, orgID *identity.ID) ([]envelope.Project, error) {
orgs := []identity.ID{*orgID}
return p.Search(ctx, orgs, nil)
} | [
"func",
"(",
"p",
"*",
"ProjectsClient",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
")",
"(",
"[",
"]",
"envelope",
".",
"Project",
",",
"error",
")",
"{",
"orgs",
":=",
"[",
"]",
"identity",
".",
"ID",
"{",
"*",
"orgID",
"}",
"\n",
"return",
"p",
".",
"Search",
"(",
"ctx",
",",
"orgs",
",",
"nil",
")",
"\n",
"}"
] | // List returns a list of all Projects within the given org. | [
"List",
"returns",
"a",
"list",
"of",
"all",
"Projects",
"within",
"the",
"given",
"org",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/projects.go#L60-L63 |
1,749 | manifoldco/torus-cli | registry/projects.go | GetTree | func (p *ProjectsClient) GetTree(ctx context.Context, orgID *identity.ID) ([]ProjectTreeSegment, error) {
v := &url.Values{}
v.Set("org_id", orgID.String())
var segments []ProjectTreeSegment
err := p.client.RoundTrip(ctx, "GET", "/projecttree", v, nil, &segments)
return segments, err
} | go | func (p *ProjectsClient) GetTree(ctx context.Context, orgID *identity.ID) ([]ProjectTreeSegment, error) {
v := &url.Values{}
v.Set("org_id", orgID.String())
var segments []ProjectTreeSegment
err := p.client.RoundTrip(ctx, "GET", "/projecttree", v, nil, &segments)
return segments, err
} | [
"func",
"(",
"p",
"*",
"ProjectsClient",
")",
"GetTree",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
")",
"(",
"[",
"]",
"ProjectTreeSegment",
",",
"error",
")",
"{",
"v",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"orgID",
".",
"String",
"(",
")",
")",
"\n\n",
"var",
"segments",
"[",
"]",
"ProjectTreeSegment",
"\n",
"err",
":=",
"p",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"v",
",",
"nil",
",",
"&",
"segments",
")",
"\n",
"return",
"segments",
",",
"err",
"\n",
"}"
] | // GetTree returns a project tree | [
"GetTree",
"returns",
"a",
"project",
"tree"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/projects.go#L66-L73 |
1,750 | manifoldco/torus-cli | prompts/select.go | SelectAcceptAction | func SelectAcceptAction() (int, string, error) {
label := "Do you want to login or create an account?"
v := []string{"Login", "Signup"}
p := selectPrompt(label, "Action", validate.OneOf(v))
return p(v, "")
} | go | func SelectAcceptAction() (int, string, error) {
label := "Do you want to login or create an account?"
v := []string{"Login", "Signup"}
p := selectPrompt(label, "Action", validate.OneOf(v))
return p(v, "")
} | [
"func",
"SelectAcceptAction",
"(",
")",
"(",
"int",
",",
"string",
",",
"error",
")",
"{",
"label",
":=",
"\"",
"\"",
"\n",
"v",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"p",
":=",
"selectPrompt",
"(",
"label",
",",
"\"",
"\"",
",",
"validate",
".",
"OneOf",
"(",
"v",
")",
")",
"\n\n",
"return",
"p",
"(",
"v",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // SelectAcceptAction prompts the user to select whether they want to log into
// an existing account or to create a new one when they're accepting an org
// invitation. | [
"SelectAcceptAction",
"prompts",
"the",
"user",
"to",
"select",
"whether",
"they",
"want",
"to",
"log",
"into",
"an",
"existing",
"account",
"or",
"to",
"create",
"a",
"new",
"one",
"when",
"they",
"re",
"accepting",
"an",
"org",
"invitation",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/prompts/select.go#L59-L65 |
1,751 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | Parse | func (pp *primitiveParser) Parse() map[string]*data {
pp.loadTypeComments()
pp.loadStructs()
visible := make(map[string]*data)
for k := range pp.structmap {
if strings.ToUpper(string(k[0])) != string(k[0]) { // not exported
continue
}
pp.visitStruct(visible, k, false)
}
return visible
} | go | func (pp *primitiveParser) Parse() map[string]*data {
pp.loadTypeComments()
pp.loadStructs()
visible := make(map[string]*data)
for k := range pp.structmap {
if strings.ToUpper(string(k[0])) != string(k[0]) { // not exported
continue
}
pp.visitStruct(visible, k, false)
}
return visible
} | [
"func",
"(",
"pp",
"*",
"primitiveParser",
")",
"Parse",
"(",
")",
"map",
"[",
"string",
"]",
"*",
"data",
"{",
"pp",
".",
"loadTypeComments",
"(",
")",
"\n",
"pp",
".",
"loadStructs",
"(",
")",
"\n\n",
"visible",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"data",
")",
"\n",
"for",
"k",
":=",
"range",
"pp",
".",
"structmap",
"{",
"if",
"strings",
".",
"ToUpper",
"(",
"string",
"(",
"k",
"[",
"0",
"]",
")",
")",
"!=",
"string",
"(",
"k",
"[",
"0",
"]",
")",
"{",
"// not exported",
"continue",
"\n",
"}",
"\n",
"pp",
".",
"visitStruct",
"(",
"visible",
",",
"k",
",",
"false",
")",
"\n",
"}",
"\n\n",
"return",
"visible",
"\n",
"}"
] | // Parse performs the actual work of walking over all defined structs,
// and building data representations of them for use in template rendering. | [
"Parse",
"performs",
"the",
"actual",
"work",
"of",
"walking",
"over",
"all",
"defined",
"structs",
"and",
"building",
"data",
"representations",
"of",
"them",
"for",
"use",
"in",
"template",
"rendering",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L115-L128 |
1,752 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | visitStruct | func (pp *primitiveParser) visitStruct(reachable map[string]*data, k string, visible bool) {
if _, ok := reachable[k]; ok { // already included
return
}
s := pp.structmap[k]
d := data{
Name: k,
Byte: pp.typedecls[pp.fset.Position(s.Pos()).Line],
}
d.Immutable, d.Version, d.Fields = pp.gatherFields(reachable, s, visible)
d.Visible = visible || d.Immutable
sort.Sort(sortFields(d.Fields))
reachable[k] = &d
} | go | func (pp *primitiveParser) visitStruct(reachable map[string]*data, k string, visible bool) {
if _, ok := reachable[k]; ok { // already included
return
}
s := pp.structmap[k]
d := data{
Name: k,
Byte: pp.typedecls[pp.fset.Position(s.Pos()).Line],
}
d.Immutable, d.Version, d.Fields = pp.gatherFields(reachable, s, visible)
d.Visible = visible || d.Immutable
sort.Sort(sortFields(d.Fields))
reachable[k] = &d
} | [
"func",
"(",
"pp",
"*",
"primitiveParser",
")",
"visitStruct",
"(",
"reachable",
"map",
"[",
"string",
"]",
"*",
"data",
",",
"k",
"string",
",",
"visible",
"bool",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"reachable",
"[",
"k",
"]",
";",
"ok",
"{",
"// already included",
"return",
"\n",
"}",
"\n\n",
"s",
":=",
"pp",
".",
"structmap",
"[",
"k",
"]",
"\n\n",
"d",
":=",
"data",
"{",
"Name",
":",
"k",
",",
"Byte",
":",
"pp",
".",
"typedecls",
"[",
"pp",
".",
"fset",
".",
"Position",
"(",
"s",
".",
"Pos",
"(",
")",
")",
".",
"Line",
"]",
",",
"}",
"\n",
"d",
".",
"Immutable",
",",
"d",
".",
"Version",
",",
"d",
".",
"Fields",
"=",
"pp",
".",
"gatherFields",
"(",
"reachable",
",",
"s",
",",
"visible",
")",
"\n",
"d",
".",
"Visible",
"=",
"visible",
"||",
"d",
".",
"Immutable",
"\n\n",
"sort",
".",
"Sort",
"(",
"sortFields",
"(",
"d",
".",
"Fields",
")",
")",
"\n",
"reachable",
"[",
"k",
"]",
"=",
"&",
"d",
"\n",
"}"
] | // visitStruct inspects the struct with the given name, parsing out its
// field definitions and mutability state. | [
"visitStruct",
"inspects",
"the",
"struct",
"with",
"the",
"given",
"name",
"parsing",
"out",
"its",
"field",
"definitions",
"and",
"mutability",
"state",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L132-L148 |
1,753 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | gatherFields | func (pp *primitiveParser) gatherFields(reachable map[string]*data, s *ast.StructType, visible bool) (bool, uint8, []field) {
fields := []field{}
immutable := false
var version uint8
if s == nil {
return immutable, version, fields
}
for _, f := range s.Fields.List {
var typeName string
switch t := f.Type.(type) {
case *ast.Ident:
typeName = t.Name
case *ast.StarExpr:
if i, ok := t.X.(*ast.Ident); ok {
typeName = i.Name
}
}
if len(f.Names) == 0 {
switch typeName {
case "immutable":
immutable = true
case "v1Schema":
version = 1
case "v2Schema":
version = 2
}
embedded := pp.structmap[typeName]
embImmutable, embVersion, embeddedFields := pp.gatherFields(reachable, embedded, visible || immutable)
immutable = immutable || embImmutable
visible = visible || immutable
if version == 0 {
version = embVersion
}
fields = append(fields, embeddedFields...)
continue
}
// This isn't an embedded struct, but it might be our own struct
// that is now reachable. we need to create a MarshalJSON func for
// it if so.
if _, ok := pp.structmap[typeName]; ok {
pp.visitStruct(reachable, typeName, visible)
}
for _, n := range f.Names {
name := n.Name
if f.Tag != nil {
tname := parseJSONTag(f.Tag.Value)
if tname != "" {
name = tname
}
}
fields = append(fields, field{
Name: name,
Field: n.Name,
})
}
}
return immutable, version, fields
} | go | func (pp *primitiveParser) gatherFields(reachable map[string]*data, s *ast.StructType, visible bool) (bool, uint8, []field) {
fields := []field{}
immutable := false
var version uint8
if s == nil {
return immutable, version, fields
}
for _, f := range s.Fields.List {
var typeName string
switch t := f.Type.(type) {
case *ast.Ident:
typeName = t.Name
case *ast.StarExpr:
if i, ok := t.X.(*ast.Ident); ok {
typeName = i.Name
}
}
if len(f.Names) == 0 {
switch typeName {
case "immutable":
immutable = true
case "v1Schema":
version = 1
case "v2Schema":
version = 2
}
embedded := pp.structmap[typeName]
embImmutable, embVersion, embeddedFields := pp.gatherFields(reachable, embedded, visible || immutable)
immutable = immutable || embImmutable
visible = visible || immutable
if version == 0 {
version = embVersion
}
fields = append(fields, embeddedFields...)
continue
}
// This isn't an embedded struct, but it might be our own struct
// that is now reachable. we need to create a MarshalJSON func for
// it if so.
if _, ok := pp.structmap[typeName]; ok {
pp.visitStruct(reachable, typeName, visible)
}
for _, n := range f.Names {
name := n.Name
if f.Tag != nil {
tname := parseJSONTag(f.Tag.Value)
if tname != "" {
name = tname
}
}
fields = append(fields, field{
Name: name,
Field: n.Name,
})
}
}
return immutable, version, fields
} | [
"func",
"(",
"pp",
"*",
"primitiveParser",
")",
"gatherFields",
"(",
"reachable",
"map",
"[",
"string",
"]",
"*",
"data",
",",
"s",
"*",
"ast",
".",
"StructType",
",",
"visible",
"bool",
")",
"(",
"bool",
",",
"uint8",
",",
"[",
"]",
"field",
")",
"{",
"fields",
":=",
"[",
"]",
"field",
"{",
"}",
"\n\n",
"immutable",
":=",
"false",
"\n",
"var",
"version",
"uint8",
"\n",
"if",
"s",
"==",
"nil",
"{",
"return",
"immutable",
",",
"version",
",",
"fields",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"f",
":=",
"range",
"s",
".",
"Fields",
".",
"List",
"{",
"var",
"typeName",
"string",
"\n",
"switch",
"t",
":=",
"f",
".",
"Type",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"Ident",
":",
"typeName",
"=",
"t",
".",
"Name",
"\n",
"case",
"*",
"ast",
".",
"StarExpr",
":",
"if",
"i",
",",
"ok",
":=",
"t",
".",
"X",
".",
"(",
"*",
"ast",
".",
"Ident",
")",
";",
"ok",
"{",
"typeName",
"=",
"i",
".",
"Name",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"f",
".",
"Names",
")",
"==",
"0",
"{",
"switch",
"typeName",
"{",
"case",
"\"",
"\"",
":",
"immutable",
"=",
"true",
"\n",
"case",
"\"",
"\"",
":",
"version",
"=",
"1",
"\n",
"case",
"\"",
"\"",
":",
"version",
"=",
"2",
"\n",
"}",
"\n",
"embedded",
":=",
"pp",
".",
"structmap",
"[",
"typeName",
"]",
"\n",
"embImmutable",
",",
"embVersion",
",",
"embeddedFields",
":=",
"pp",
".",
"gatherFields",
"(",
"reachable",
",",
"embedded",
",",
"visible",
"||",
"immutable",
")",
"\n",
"immutable",
"=",
"immutable",
"||",
"embImmutable",
"\n",
"visible",
"=",
"visible",
"||",
"immutable",
"\n",
"if",
"version",
"==",
"0",
"{",
"version",
"=",
"embVersion",
"\n",
"}",
"\n",
"fields",
"=",
"append",
"(",
"fields",
",",
"embeddedFields",
"...",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"// This isn't an embedded struct, but it might be our own struct",
"// that is now reachable. we need to create a MarshalJSON func for",
"// it if so.",
"if",
"_",
",",
"ok",
":=",
"pp",
".",
"structmap",
"[",
"typeName",
"]",
";",
"ok",
"{",
"pp",
".",
"visitStruct",
"(",
"reachable",
",",
"typeName",
",",
"visible",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"n",
":=",
"range",
"f",
".",
"Names",
"{",
"name",
":=",
"n",
".",
"Name",
"\n",
"if",
"f",
".",
"Tag",
"!=",
"nil",
"{",
"tname",
":=",
"parseJSONTag",
"(",
"f",
".",
"Tag",
".",
"Value",
")",
"\n",
"if",
"tname",
"!=",
"\"",
"\"",
"{",
"name",
"=",
"tname",
"\n",
"}",
"\n",
"}",
"\n",
"fields",
"=",
"append",
"(",
"fields",
",",
"field",
"{",
"Name",
":",
"name",
",",
"Field",
":",
"n",
".",
"Name",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"immutable",
",",
"version",
",",
"fields",
"\n",
"}"
] | // gatherFields is used by visitStruct to gather the fields for a struct.
// embedded struct fields are hoisted up to the enclosing struct for JSON
// representation.
// referenced structs will in turn be visited.
//
// gatherFields transfers visibility from immutable structs, or any already
// known visible structs, to structs that they reference.
// visibility determines if we should create a MarshalJSON func for the struct. | [
"gatherFields",
"is",
"used",
"by",
"visitStruct",
"to",
"gather",
"the",
"fields",
"for",
"a",
"struct",
".",
"embedded",
"struct",
"fields",
"are",
"hoisted",
"up",
"to",
"the",
"enclosing",
"struct",
"for",
"JSON",
"representation",
".",
"referenced",
"structs",
"will",
"in",
"turn",
"be",
"visited",
".",
"gatherFields",
"transfers",
"visibility",
"from",
"immutable",
"structs",
"or",
"any",
"already",
"known",
"visible",
"structs",
"to",
"structs",
"that",
"they",
"reference",
".",
"visibility",
"determines",
"if",
"we",
"should",
"create",
"a",
"MarshalJSON",
"func",
"for",
"the",
"struct",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L158-L220 |
1,754 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | loadTypeComments | func (pp *primitiveParser) loadTypeComments() {
pp.typedecls = make(map[int]string)
for _, c := range pp.p.Comments {
cmt := strings.Trim(c.List[0].Text, "/* \t")
parts := strings.Split(cmt, " ")
if len(parts) == 2 && parts[0] == "type:" {
pp.typedecls[pp.fset.Position(c.List[0].Pos()).Line] = parts[1]
}
}
} | go | func (pp *primitiveParser) loadTypeComments() {
pp.typedecls = make(map[int]string)
for _, c := range pp.p.Comments {
cmt := strings.Trim(c.List[0].Text, "/* \t")
parts := strings.Split(cmt, " ")
if len(parts) == 2 && parts[0] == "type:" {
pp.typedecls[pp.fset.Position(c.List[0].Pos()).Line] = parts[1]
}
}
} | [
"func",
"(",
"pp",
"*",
"primitiveParser",
")",
"loadTypeComments",
"(",
")",
"{",
"pp",
".",
"typedecls",
"=",
"make",
"(",
"map",
"[",
"int",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"pp",
".",
"p",
".",
"Comments",
"{",
"cmt",
":=",
"strings",
".",
"Trim",
"(",
"c",
".",
"List",
"[",
"0",
"]",
".",
"Text",
",",
"\"",
"\\t",
"\"",
")",
"\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"cmt",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"==",
"2",
"&&",
"parts",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"pp",
".",
"typedecls",
"[",
"pp",
".",
"fset",
".",
"Position",
"(",
"c",
".",
"List",
"[",
"0",
"]",
".",
"Pos",
"(",
")",
")",
".",
"Line",
"]",
"=",
"parts",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // loadTypeComments loads our annotation comments on structs, indicating
// their enumerated byte type, allowing us to look it up later by line. | [
"loadTypeComments",
"loads",
"our",
"annotation",
"comments",
"on",
"structs",
"indicating",
"their",
"enumerated",
"byte",
"type",
"allowing",
"us",
"to",
"look",
"it",
"up",
"later",
"by",
"line",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L224-L233 |
1,755 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | loadStructs | func (pp *primitiveParser) loadStructs() {
pp.structmap = make(map[string]*ast.StructType)
for k, o := range pp.p.Scope.Objects {
// We only care about types
if o.Kind != ast.Typ {
continue
}
ts, ok := o.Decl.(*ast.TypeSpec)
if !ok {
continue
}
// and to be more exact, only struct types
s, ok := ts.Type.(*ast.StructType)
if !ok {
continue
}
// Empty struct? We don't need to generate and json for it. skip.
if len(s.Fields.List) == 0 {
continue
}
pp.structmap[k] = s
}
} | go | func (pp *primitiveParser) loadStructs() {
pp.structmap = make(map[string]*ast.StructType)
for k, o := range pp.p.Scope.Objects {
// We only care about types
if o.Kind != ast.Typ {
continue
}
ts, ok := o.Decl.(*ast.TypeSpec)
if !ok {
continue
}
// and to be more exact, only struct types
s, ok := ts.Type.(*ast.StructType)
if !ok {
continue
}
// Empty struct? We don't need to generate and json for it. skip.
if len(s.Fields.List) == 0 {
continue
}
pp.structmap[k] = s
}
} | [
"func",
"(",
"pp",
"*",
"primitiveParser",
")",
"loadStructs",
"(",
")",
"{",
"pp",
".",
"structmap",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"StructType",
")",
"\n\n",
"for",
"k",
",",
"o",
":=",
"range",
"pp",
".",
"p",
".",
"Scope",
".",
"Objects",
"{",
"// We only care about types",
"if",
"o",
".",
"Kind",
"!=",
"ast",
".",
"Typ",
"{",
"continue",
"\n",
"}",
"\n",
"ts",
",",
"ok",
":=",
"o",
".",
"Decl",
".",
"(",
"*",
"ast",
".",
"TypeSpec",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"// and to be more exact, only struct types",
"s",
",",
"ok",
":=",
"ts",
".",
"Type",
".",
"(",
"*",
"ast",
".",
"StructType",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"// Empty struct? We don't need to generate and json for it. skip.",
"if",
"len",
"(",
"s",
".",
"Fields",
".",
"List",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"pp",
".",
"structmap",
"[",
"k",
"]",
"=",
"s",
"\n",
"}",
"\n",
"}"
] | // loadStructs creates a map of name to ast node for struct types from the
// parsed file, filtering out other types. | [
"loadStructs",
"creates",
"a",
"map",
"of",
"name",
"to",
"ast",
"node",
"for",
"struct",
"types",
"from",
"the",
"parsed",
"file",
"filtering",
"out",
"other",
"types",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L237-L263 |
1,756 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | parseJSONTag | func parseJSONTag(tag string) string {
if len(tag) == 0 {
return ""
}
if tag[:7] != "`json:\"" {
return ""
}
parts := strings.Split(tag[7:len(tag)-2], ",")
return parts[0]
} | go | func parseJSONTag(tag string) string {
if len(tag) == 0 {
return ""
}
if tag[:7] != "`json:\"" {
return ""
}
parts := strings.Split(tag[7:len(tag)-2], ",")
return parts[0]
} | [
"func",
"parseJSONTag",
"(",
"tag",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"tag",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"if",
"tag",
"[",
":",
"7",
"]",
"!=",
"\"",
"\\\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"tag",
"[",
"7",
":",
"len",
"(",
"tag",
")",
"-",
"2",
"]",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"parts",
"[",
"0",
"]",
"\n",
"}"
] | // parseJSONTag parses the given JSON struct field tag, to get its name.
// omitting fields via tags is not supported. | [
"parseJSONTag",
"parses",
"the",
"given",
"JSON",
"struct",
"field",
"tag",
"to",
"get",
"its",
"name",
".",
"omitting",
"fields",
"via",
"tags",
"is",
"not",
"supported",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L267-L279 |
1,757 | manifoldco/torus-cli | tools/primitive-boilerplate/main.go | writeTemplate | func writeTemplate(fileName string, tmpl *template.Template, data interface{}) {
buf := &bytes.Buffer{}
err := tmpl.Execute(buf, data)
if err != nil {
log.Fatal(err)
}
formatted, err := format.Source(buf.Bytes())
if err != nil {
log.Fatal(err)
}
fd, err := os.Create(fileName)
if err != nil {
log.Fatal(err)
}
defer fd.Close()
fd.Write(formatted)
} | go | func writeTemplate(fileName string, tmpl *template.Template, data interface{}) {
buf := &bytes.Buffer{}
err := tmpl.Execute(buf, data)
if err != nil {
log.Fatal(err)
}
formatted, err := format.Source(buf.Bytes())
if err != nil {
log.Fatal(err)
}
fd, err := os.Create(fileName)
if err != nil {
log.Fatal(err)
}
defer fd.Close()
fd.Write(formatted)
} | [
"func",
"writeTemplate",
"(",
"fileName",
"string",
",",
"tmpl",
"*",
"template",
".",
"Template",
",",
"data",
"interface",
"{",
"}",
")",
"{",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"err",
":=",
"tmpl",
".",
"Execute",
"(",
"buf",
",",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"formatted",
",",
"err",
":=",
"format",
".",
"Source",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"fd",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"defer",
"fd",
".",
"Close",
"(",
")",
"\n\n",
"fd",
".",
"Write",
"(",
"formatted",
")",
"\n",
"}"
] | // writeTemplate writes the given template to the given file, with the given
// data. Templates are assumed to be generating go source files, so they
// are formatted as well. | [
"writeTemplate",
"writes",
"the",
"given",
"template",
"to",
"the",
"given",
"file",
"with",
"the",
"given",
"data",
".",
"Templates",
"are",
"assumed",
"to",
"be",
"generating",
"go",
"source",
"files",
"so",
"they",
"are",
"formatted",
"as",
"well",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/tools/primitive-boilerplate/main.go#L284-L303 |
1,758 | manifoldco/torus-cli | apitypes/credential.go | String | func (c *CredentialValue) String() string {
if c.cvtype == unsetCV {
panic("CredentialValue has been unset")
}
if c.cvtype == undecryptedCV {
panic("CredentialValue was not decrypted")
}
return c.value
} | go | func (c *CredentialValue) String() string {
if c.cvtype == unsetCV {
panic("CredentialValue has been unset")
}
if c.cvtype == undecryptedCV {
panic("CredentialValue was not decrypted")
}
return c.value
} | [
"func",
"(",
"c",
"*",
"CredentialValue",
")",
"String",
"(",
")",
"string",
"{",
"if",
"c",
".",
"cvtype",
"==",
"unsetCV",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"cvtype",
"==",
"undecryptedCV",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"value",
"\n",
"}"
] | // String returns the string representation of this credential. It panics
// if the credential was deleted. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"this",
"credential",
".",
"It",
"panics",
"if",
"the",
"credential",
"was",
"deleted",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/credential.go#L124-L134 |
1,759 | manifoldco/torus-cli | apitypes/credential.go | Raw | func (c *CredentialValue) Raw() (interface{}, error) {
if c.IsUnset() {
return nil, errors.New("Cannot return raw value of an unset Credential")
}
return c.raw, nil
} | go | func (c *CredentialValue) Raw() (interface{}, error) {
if c.IsUnset() {
return nil, errors.New("Cannot return raw value of an unset Credential")
}
return c.raw, nil
} | [
"func",
"(",
"c",
"*",
"CredentialValue",
")",
"Raw",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"c",
".",
"IsUnset",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"raw",
",",
"nil",
"\n",
"}"
] | // Raw returns the underlying typed value for this Credential. | [
"Raw",
"returns",
"the",
"underlying",
"typed",
"value",
"for",
"this",
"Credential",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/credential.go#L145-L151 |
1,760 | manifoldco/torus-cli | apitypes/credential.go | NewStringCredentialValue | func NewStringCredentialValue(s string) *CredentialValue {
return &CredentialValue{
cvtype: stringCV,
value: s,
raw: s,
}
} | go | func NewStringCredentialValue(s string) *CredentialValue {
return &CredentialValue{
cvtype: stringCV,
value: s,
raw: s,
}
} | [
"func",
"NewStringCredentialValue",
"(",
"s",
"string",
")",
"*",
"CredentialValue",
"{",
"return",
"&",
"CredentialValue",
"{",
"cvtype",
":",
"stringCV",
",",
"value",
":",
"s",
",",
"raw",
":",
"s",
",",
"}",
"\n",
"}"
] | // NewStringCredentialValue creates a CredentialValue with a string value. | [
"NewStringCredentialValue",
"creates",
"a",
"CredentialValue",
"with",
"a",
"string",
"value",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/credential.go#L253-L259 |
1,761 | manifoldco/torus-cli | apitypes/credential.go | NewIntCredentialValue | func NewIntCredentialValue(i int) *CredentialValue {
return &CredentialValue{
cvtype: intCV,
value: strconv.Itoa(i),
raw: i,
}
} | go | func NewIntCredentialValue(i int) *CredentialValue {
return &CredentialValue{
cvtype: intCV,
value: strconv.Itoa(i),
raw: i,
}
} | [
"func",
"NewIntCredentialValue",
"(",
"i",
"int",
")",
"*",
"CredentialValue",
"{",
"return",
"&",
"CredentialValue",
"{",
"cvtype",
":",
"intCV",
",",
"value",
":",
"strconv",
".",
"Itoa",
"(",
"i",
")",
",",
"raw",
":",
"i",
",",
"}",
"\n",
"}"
] | // NewIntCredentialValue creates a CredentialValue with an int value. | [
"NewIntCredentialValue",
"creates",
"a",
"CredentialValue",
"with",
"an",
"int",
"value",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/credential.go#L262-L268 |
1,762 | manifoldco/torus-cli | apitypes/credential.go | NewFloatCredentialValue | func NewFloatCredentialValue(f float64) *CredentialValue {
return &CredentialValue{
cvtype: floatCV,
value: strconv.FormatFloat(f, 'g', -1, 64),
raw: f,
}
} | go | func NewFloatCredentialValue(f float64) *CredentialValue {
return &CredentialValue{
cvtype: floatCV,
value: strconv.FormatFloat(f, 'g', -1, 64),
raw: f,
}
} | [
"func",
"NewFloatCredentialValue",
"(",
"f",
"float64",
")",
"*",
"CredentialValue",
"{",
"return",
"&",
"CredentialValue",
"{",
"cvtype",
":",
"floatCV",
",",
"value",
":",
"strconv",
".",
"FormatFloat",
"(",
"f",
",",
"'g'",
",",
"-",
"1",
",",
"64",
")",
",",
"raw",
":",
"f",
",",
"}",
"\n",
"}"
] | // NewFloatCredentialValue creates a CredentialValue with a float value. | [
"NewFloatCredentialValue",
"creates",
"a",
"CredentialValue",
"with",
"a",
"float",
"value",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/credential.go#L271-L277 |
1,763 | manifoldco/torus-cli | registry/services.go | Create | func (s *ServicesClient) Create(ctx context.Context, orgID, projectID *identity.ID, name string) error {
if orgID == nil || projectID == nil {
return errors.New("invalid org or project")
}
serviceBody := primitive.Service{
Name: name,
OrgID: orgID,
ProjectID: projectID,
}
ID, err := identity.NewMutable(&serviceBody)
if err != nil {
return err
}
service := envelope.Service{
ID: &ID,
Version: 1,
Body: &serviceBody,
}
return s.client.RoundTrip(ctx, "POST", "/services", nil, service, nil)
} | go | func (s *ServicesClient) Create(ctx context.Context, orgID, projectID *identity.ID, name string) error {
if orgID == nil || projectID == nil {
return errors.New("invalid org or project")
}
serviceBody := primitive.Service{
Name: name,
OrgID: orgID,
ProjectID: projectID,
}
ID, err := identity.NewMutable(&serviceBody)
if err != nil {
return err
}
service := envelope.Service{
ID: &ID,
Version: 1,
Body: &serviceBody,
}
return s.client.RoundTrip(ctx, "POST", "/services", nil, service, nil)
} | [
"func",
"(",
"s",
"*",
"ServicesClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
",",
"projectID",
"*",
"identity",
".",
"ID",
",",
"name",
"string",
")",
"error",
"{",
"if",
"orgID",
"==",
"nil",
"||",
"projectID",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"serviceBody",
":=",
"primitive",
".",
"Service",
"{",
"Name",
":",
"name",
",",
"OrgID",
":",
"orgID",
",",
"ProjectID",
":",
"projectID",
",",
"}",
"\n\n",
"ID",
",",
"err",
":=",
"identity",
".",
"NewMutable",
"(",
"&",
"serviceBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"service",
":=",
"envelope",
".",
"Service",
"{",
"ID",
":",
"&",
"ID",
",",
"Version",
":",
"1",
",",
"Body",
":",
"&",
"serviceBody",
",",
"}",
"\n\n",
"return",
"s",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"service",
",",
"nil",
")",
"\n",
"}"
] | // Create performs a request to create a new service object | [
"Create",
"performs",
"a",
"request",
"to",
"create",
"a",
"new",
"service",
"object"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/services.go#L40-L63 |
1,764 | manifoldco/torus-cli | registry/claimtree.go | Find | func (ct *ClaimTree) Find(id *identity.ID, mustActive bool) (*apitypes.PublicKeySegment, error) {
for _, pks := range ct.PublicKeys {
if *pks.PublicKey.ID == *id {
if mustActive && pks.Revoked() {
continue
}
return &pks, nil
}
}
return nil, ErrKeyNotFound
} | go | func (ct *ClaimTree) Find(id *identity.ID, mustActive bool) (*apitypes.PublicKeySegment, error) {
for _, pks := range ct.PublicKeys {
if *pks.PublicKey.ID == *id {
if mustActive && pks.Revoked() {
continue
}
return &pks, nil
}
}
return nil, ErrKeyNotFound
} | [
"func",
"(",
"ct",
"*",
"ClaimTree",
")",
"Find",
"(",
"id",
"*",
"identity",
".",
"ID",
",",
"mustActive",
"bool",
")",
"(",
"*",
"apitypes",
".",
"PublicKeySegment",
",",
"error",
")",
"{",
"for",
"_",
",",
"pks",
":=",
"range",
"ct",
".",
"PublicKeys",
"{",
"if",
"*",
"pks",
".",
"PublicKey",
".",
"ID",
"==",
"*",
"id",
"{",
"if",
"mustActive",
"&&",
"pks",
".",
"Revoked",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"return",
"&",
"pks",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"ErrKeyNotFound",
"\n",
"}"
] | // Find returns the PublicKeySegment for the given PublicKeyID. Accepts a
// boolean for indicating whether or not to enforce that the key must be
// active.
//
// If a key segment could not be found an error is returned. | [
"Find",
"returns",
"the",
"PublicKeySegment",
"for",
"the",
"given",
"PublicKeyID",
".",
"Accepts",
"a",
"boolean",
"for",
"indicating",
"whether",
"or",
"not",
"to",
"enforce",
"that",
"the",
"key",
"must",
"be",
"active",
".",
"If",
"a",
"key",
"segment",
"could",
"not",
"be",
"found",
"an",
"error",
"is",
"returned",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/claimtree.go#L51-L63 |
1,765 | manifoldco/torus-cli | registry/claimtree.go | FindActive | func (ct *ClaimTree) FindActive(ownerID *identity.ID, t primitive.KeyType) (*apitypes.PublicKeySegment, error) {
for _, pks := range ct.PublicKeys {
if *pks.PublicKey.Body.OwnerID != *ownerID {
continue
}
if pks.PublicKey.Body.KeyType != t {
continue
}
if pks.Revoked() {
continue
}
return &pks, nil
}
return nil, ErrMissingKeyForOwner
} | go | func (ct *ClaimTree) FindActive(ownerID *identity.ID, t primitive.KeyType) (*apitypes.PublicKeySegment, error) {
for _, pks := range ct.PublicKeys {
if *pks.PublicKey.Body.OwnerID != *ownerID {
continue
}
if pks.PublicKey.Body.KeyType != t {
continue
}
if pks.Revoked() {
continue
}
return &pks, nil
}
return nil, ErrMissingKeyForOwner
} | [
"func",
"(",
"ct",
"*",
"ClaimTree",
")",
"FindActive",
"(",
"ownerID",
"*",
"identity",
".",
"ID",
",",
"t",
"primitive",
".",
"KeyType",
")",
"(",
"*",
"apitypes",
".",
"PublicKeySegment",
",",
"error",
")",
"{",
"for",
"_",
",",
"pks",
":=",
"range",
"ct",
".",
"PublicKeys",
"{",
"if",
"*",
"pks",
".",
"PublicKey",
".",
"Body",
".",
"OwnerID",
"!=",
"*",
"ownerID",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"pks",
".",
"PublicKey",
".",
"Body",
".",
"KeyType",
"!=",
"t",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"pks",
".",
"Revoked",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n\n",
"return",
"&",
"pks",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"ErrMissingKeyForOwner",
"\n",
"}"
] | // FindActive returns the PublicKeySegment for a non-revoked Public Key for
// the given owner id.
//
// If an active key cannot be found an error is returned | [
"FindActive",
"returns",
"the",
"PublicKeySegment",
"for",
"a",
"non",
"-",
"revoked",
"Public",
"Key",
"for",
"the",
"given",
"owner",
"id",
".",
"If",
"an",
"active",
"key",
"cannot",
"be",
"found",
"an",
"error",
"is",
"returned"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/claimtree.go#L69-L87 |
1,766 | manifoldco/torus-cli | registry/claimtree.go | List | func (c *ClaimTreeClient) List(ctx context.Context, orgID *identity.ID,
ownerID *identity.ID) ([]ClaimTree, error) {
query := &url.Values{}
if orgID != nil {
query.Set("org_id", orgID.String())
}
if ownerID != nil {
query.Set("owner_id", ownerID.String())
}
var resp []ClaimTree
err := c.client.RoundTrip(ctx, "GET", "/claimtree", query, nil, &resp)
return resp, err
} | go | func (c *ClaimTreeClient) List(ctx context.Context, orgID *identity.ID,
ownerID *identity.ID) ([]ClaimTree, error) {
query := &url.Values{}
if orgID != nil {
query.Set("org_id", orgID.String())
}
if ownerID != nil {
query.Set("owner_id", ownerID.String())
}
var resp []ClaimTree
err := c.client.RoundTrip(ctx, "GET", "/claimtree", query, nil, &resp)
return resp, err
} | [
"func",
"(",
"c",
"*",
"ClaimTreeClient",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
",",
"ownerID",
"*",
"identity",
".",
"ID",
")",
"(",
"[",
"]",
"ClaimTree",
",",
"error",
")",
"{",
"query",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"if",
"orgID",
"!=",
"nil",
"{",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"orgID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"if",
"ownerID",
"!=",
"nil",
"{",
"query",
".",
"Set",
"(",
"\"",
"\"",
",",
"ownerID",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"var",
"resp",
"[",
"]",
"ClaimTree",
"\n",
"err",
":=",
"c",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"query",
",",
"nil",
",",
"&",
"resp",
")",
"\n",
"return",
"resp",
",",
"err",
"\n",
"}"
] | // List returns a list of all claimtrees for a given orgID. If no orgID is
// provided then it returns all claimtrees for every organization the user
// belongs too.
//
// If an ownerID is provided then only public keys and claims related to that
// user or machine will be returned. | [
"List",
"returns",
"a",
"list",
"of",
"all",
"claimtrees",
"for",
"a",
"given",
"orgID",
".",
"If",
"no",
"orgID",
"is",
"provided",
"then",
"it",
"returns",
"all",
"claimtrees",
"for",
"every",
"organization",
"the",
"user",
"belongs",
"too",
".",
"If",
"an",
"ownerID",
"is",
"provided",
"then",
"only",
"public",
"keys",
"and",
"claims",
"related",
"to",
"that",
"user",
"or",
"machine",
"will",
"be",
"returned",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/claimtree.go#L95-L110 |
1,767 | manifoldco/torus-cli | registry/claimtree.go | Get | func (c *ClaimTreeClient) Get(ctx context.Context, orgID *identity.ID,
ownerID *identity.ID) (*ClaimTree, error) {
if orgID == nil {
return nil, errors.New("An org id must be provided")
}
cts, err := c.List(ctx, orgID, ownerID)
if err != nil {
return nil, err
}
if len(cts) != 1 {
return nil, ErrClaimTreeNotFound
}
return &cts[0], nil
} | go | func (c *ClaimTreeClient) Get(ctx context.Context, orgID *identity.ID,
ownerID *identity.ID) (*ClaimTree, error) {
if orgID == nil {
return nil, errors.New("An org id must be provided")
}
cts, err := c.List(ctx, orgID, ownerID)
if err != nil {
return nil, err
}
if len(cts) != 1 {
return nil, ErrClaimTreeNotFound
}
return &cts[0], nil
} | [
"func",
"(",
"c",
"*",
"ClaimTreeClient",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
",",
"ownerID",
"*",
"identity",
".",
"ID",
")",
"(",
"*",
"ClaimTree",
",",
"error",
")",
"{",
"if",
"orgID",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cts",
",",
"err",
":=",
"c",
".",
"List",
"(",
"ctx",
",",
"orgID",
",",
"ownerID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"cts",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"ErrClaimTreeNotFound",
"\n",
"}",
"\n\n",
"return",
"&",
"cts",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // Get returns a claimtree for a specific organization by the given orgID.
//
// If an ownerID is provided then only public keys and claims related to that
// user or machine will be returned. | [
"Get",
"returns",
"a",
"claimtree",
"for",
"a",
"specific",
"organization",
"by",
"the",
"given",
"orgID",
".",
"If",
"an",
"ownerID",
"is",
"provided",
"then",
"only",
"public",
"keys",
"and",
"claims",
"related",
"to",
"that",
"user",
"or",
"machine",
"will",
"be",
"returned",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/claimtree.go#L116-L133 |
1,768 | manifoldco/torus-cli | prompts/prompts.go | Password | func Password(confirm bool, override *string) (string, error) {
preferences, err := prefs.NewPreferences()
if err != nil {
return "", err
}
label := "Password"
if override != nil {
label = *override
}
if !ui.Attached() {
return "", errs.ErrTerminalRequired
}
prompt := &promptui.Prompt{
Label: label,
Mask: pwMask,
Validate: promptui.ValidateFunc(validate.Password),
IsVimMode: preferences.Core.Vim,
}
password, err := prompt.Run()
if err != nil {
return "", err
}
if !confirm {
return password, err
}
prompt = &promptui.Prompt{
Label: "Confirm " + label,
Mask: pwMask,
Validate: promptui.ValidateFunc(validate.ConfirmPassword(password)),
IsVimMode: preferences.Core.Vim,
}
_, err = prompt.Run()
if err != nil {
return "", convertErr(err)
}
return password, nil
} | go | func Password(confirm bool, override *string) (string, error) {
preferences, err := prefs.NewPreferences()
if err != nil {
return "", err
}
label := "Password"
if override != nil {
label = *override
}
if !ui.Attached() {
return "", errs.ErrTerminalRequired
}
prompt := &promptui.Prompt{
Label: label,
Mask: pwMask,
Validate: promptui.ValidateFunc(validate.Password),
IsVimMode: preferences.Core.Vim,
}
password, err := prompt.Run()
if err != nil {
return "", err
}
if !confirm {
return password, err
}
prompt = &promptui.Prompt{
Label: "Confirm " + label,
Mask: pwMask,
Validate: promptui.ValidateFunc(validate.ConfirmPassword(password)),
IsVimMode: preferences.Core.Vim,
}
_, err = prompt.Run()
if err != nil {
return "", convertErr(err)
}
return password, nil
} | [
"func",
"Password",
"(",
"confirm",
"bool",
",",
"override",
"*",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"preferences",
",",
"err",
":=",
"prefs",
".",
"NewPreferences",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"label",
":=",
"\"",
"\"",
"\n",
"if",
"override",
"!=",
"nil",
"{",
"label",
"=",
"*",
"override",
"\n",
"}",
"\n\n",
"if",
"!",
"ui",
".",
"Attached",
"(",
")",
"{",
"return",
"\"",
"\"",
",",
"errs",
".",
"ErrTerminalRequired",
"\n",
"}",
"\n\n",
"prompt",
":=",
"&",
"promptui",
".",
"Prompt",
"{",
"Label",
":",
"label",
",",
"Mask",
":",
"pwMask",
",",
"Validate",
":",
"promptui",
".",
"ValidateFunc",
"(",
"validate",
".",
"Password",
")",
",",
"IsVimMode",
":",
"preferences",
".",
"Core",
".",
"Vim",
",",
"}",
"\n\n",
"password",
",",
"err",
":=",
"prompt",
".",
"Run",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"confirm",
"{",
"return",
"password",
",",
"err",
"\n",
"}",
"\n\n",
"prompt",
"=",
"&",
"promptui",
".",
"Prompt",
"{",
"Label",
":",
"\"",
"\"",
"+",
"label",
",",
"Mask",
":",
"pwMask",
",",
"Validate",
":",
"promptui",
".",
"ValidateFunc",
"(",
"validate",
".",
"ConfirmPassword",
"(",
"password",
")",
")",
",",
"IsVimMode",
":",
"preferences",
".",
"Core",
".",
"Vim",
",",
"}",
"\n\n",
"_",
",",
"err",
"=",
"prompt",
".",
"Run",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"convertErr",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"password",
",",
"nil",
"\n",
"}"
] | // Password prompts the user to provide a password. The value provided by the
// user is masked.
//
// If confirm is true the user will be prompted to supply the password again. | [
"Password",
"prompts",
"the",
"user",
"to",
"provide",
"a",
"password",
".",
"The",
"value",
"provided",
"by",
"the",
"user",
"is",
"masked",
".",
"If",
"confirm",
"is",
"true",
"the",
"user",
"will",
"be",
"prompted",
"to",
"supply",
"the",
"password",
"again",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/prompts/prompts.go#L69-L113 |
1,769 | manifoldco/torus-cli | api/users.go | Create | func (u *UsersClient) Create(ctx context.Context, signup *apitypes.Signup, output *ProgressFunc) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.DaemonRoundTrip(ctx, "POST", "/signup", nil, &signup, &e, nil)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | go | func (u *UsersClient) Create(ctx context.Context, signup *apitypes.Signup, output *ProgressFunc) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.DaemonRoundTrip(ctx, "POST", "/signup", nil, &signup, &e, nil)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | [
"func",
"(",
"u",
"*",
"UsersClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"signup",
"*",
"apitypes",
".",
"Signup",
",",
"output",
"*",
"ProgressFunc",
")",
"(",
"envelope",
".",
"UserInf",
",",
"error",
")",
"{",
"e",
":=",
"envelope",
".",
"Unsigned",
"{",
"}",
"\n",
"err",
":=",
"u",
".",
"client",
".",
"DaemonRoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"signup",
",",
"&",
"e",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"envelope",
".",
"ConvertUser",
"(",
"&",
"e",
")",
"\n",
"}"
] | // Create will have the daemon create a new user request | [
"Create",
"will",
"have",
"the",
"daemon",
"create",
"a",
"new",
"user",
"request"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/users.go#L22-L30 |
1,770 | manifoldco/torus-cli | api/users.go | Update | func (u *UsersClient) Update(ctx context.Context, delta apitypes.ProfileUpdate) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.DaemonRoundTrip(ctx, "PATCH", "/self", nil, &delta, &e, nil)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | go | func (u *UsersClient) Update(ctx context.Context, delta apitypes.ProfileUpdate) (envelope.UserInf, error) {
e := envelope.Unsigned{}
err := u.client.DaemonRoundTrip(ctx, "PATCH", "/self", nil, &delta, &e, nil)
if err != nil {
return nil, err
}
return envelope.ConvertUser(&e)
} | [
"func",
"(",
"u",
"*",
"UsersClient",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"delta",
"apitypes",
".",
"ProfileUpdate",
")",
"(",
"envelope",
".",
"UserInf",
",",
"error",
")",
"{",
"e",
":=",
"envelope",
".",
"Unsigned",
"{",
"}",
"\n",
"err",
":=",
"u",
".",
"client",
".",
"DaemonRoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"delta",
",",
"&",
"e",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"envelope",
".",
"ConvertUser",
"(",
"&",
"e",
")",
"\n",
"}"
] | // Update performs a profile update to the user object | [
"Update",
"performs",
"a",
"profile",
"update",
"to",
"the",
"user",
"object"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/users.go#L33-L41 |
1,771 | manifoldco/torus-cli | api/users.go | Verify | func (u *UsersClient) Verify(ctx context.Context, code string) error {
verifyEmail := apitypes.VerifyEmail{
Code: code,
}
return u.client.DaemonRoundTrip(ctx, "POST", "/verify", nil, &verifyEmail, nil, nil)
} | go | func (u *UsersClient) Verify(ctx context.Context, code string) error {
verifyEmail := apitypes.VerifyEmail{
Code: code,
}
return u.client.DaemonRoundTrip(ctx, "POST", "/verify", nil, &verifyEmail, nil, nil)
} | [
"func",
"(",
"u",
"*",
"UsersClient",
")",
"Verify",
"(",
"ctx",
"context",
".",
"Context",
",",
"code",
"string",
")",
"error",
"{",
"verifyEmail",
":=",
"apitypes",
".",
"VerifyEmail",
"{",
"Code",
":",
"code",
",",
"}",
"\n\n",
"return",
"u",
".",
"client",
".",
"DaemonRoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"verifyEmail",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // Verify verifies the users account using the given code | [
"Verify",
"verifies",
"the",
"users",
"account",
"using",
"the",
"given",
"code"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/users.go#L44-L50 |
1,772 | manifoldco/torus-cli | dirprefs/dirprefs.go | Load | func Load(recurse bool) (*DirPreferences, error) {
path, err := os.Getwd()
if err != nil {
return nil, err
}
prefs := &DirPreferences{}
var f *os.File
for {
f, err = os.Open(filepath.Join(path, ".torus.json"))
if err != nil {
if isSystemRoot(path) || !recurse {
return prefs, nil
}
path = filepath.Dir(path)
continue
}
break
}
defer f.Close()
dec := json.NewDecoder(f)
err = dec.Decode(prefs)
if err != nil {
return nil, err
}
prefs.Path = f.Name()
return prefs, nil
} | go | func Load(recurse bool) (*DirPreferences, error) {
path, err := os.Getwd()
if err != nil {
return nil, err
}
prefs := &DirPreferences{}
var f *os.File
for {
f, err = os.Open(filepath.Join(path, ".torus.json"))
if err != nil {
if isSystemRoot(path) || !recurse {
return prefs, nil
}
path = filepath.Dir(path)
continue
}
break
}
defer f.Close()
dec := json.NewDecoder(f)
err = dec.Decode(prefs)
if err != nil {
return nil, err
}
prefs.Path = f.Name()
return prefs, nil
} | [
"func",
"Load",
"(",
"recurse",
"bool",
")",
"(",
"*",
"DirPreferences",
",",
"error",
")",
"{",
"path",
",",
"err",
":=",
"os",
".",
"Getwd",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"prefs",
":=",
"&",
"DirPreferences",
"{",
"}",
"\n\n",
"var",
"f",
"*",
"os",
".",
"File",
"\n",
"for",
"{",
"f",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"isSystemRoot",
"(",
"path",
")",
"||",
"!",
"recurse",
"{",
"return",
"prefs",
",",
"nil",
"\n",
"}",
"\n\n",
"path",
"=",
"filepath",
".",
"Dir",
"(",
"path",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"break",
"\n",
"}",
"\n\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"dec",
":=",
"json",
".",
"NewDecoder",
"(",
"f",
")",
"\n",
"err",
"=",
"dec",
".",
"Decode",
"(",
"prefs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"prefs",
".",
"Path",
"=",
"f",
".",
"Name",
"(",
")",
"\n",
"return",
"prefs",
",",
"nil",
"\n",
"}"
] | // Load loads DirPreferences. It starts in the current working directory,
// looking for a readable '.torus.json' file, and walks up the directory
// hierarchy until it finds one, or reaches the root of the fs.
//
// It returns an empty DirPreferences is no '.torus.json' files are found.
// It returns an error if a malformed file is found, or if any errors occur
// during file system access. | [
"Load",
"loads",
"DirPreferences",
".",
"It",
"starts",
"in",
"the",
"current",
"working",
"directory",
"looking",
"for",
"a",
"readable",
".",
"torus",
".",
"json",
"file",
"and",
"walks",
"up",
"the",
"directory",
"hierarchy",
"until",
"it",
"finds",
"one",
"or",
"reaches",
"the",
"root",
"of",
"the",
"fs",
".",
"It",
"returns",
"an",
"empty",
"DirPreferences",
"is",
"no",
".",
"torus",
".",
"json",
"files",
"are",
"found",
".",
"It",
"returns",
"an",
"error",
"if",
"a",
"malformed",
"file",
"is",
"found",
"or",
"if",
"any",
"errors",
"occur",
"during",
"file",
"system",
"access",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/dirprefs/dirprefs.go#L24-L57 |
1,773 | manifoldco/torus-cli | dirprefs/dirprefs.go | Save | func (d *DirPreferences) Save() error {
f, err := os.Create(d.Path)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
return enc.Encode(d)
} | go | func (d *DirPreferences) Save() error {
f, err := os.Create(d.Path)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
return enc.Encode(d)
} | [
"func",
"(",
"d",
"*",
"DirPreferences",
")",
"Save",
"(",
")",
"error",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"d",
".",
"Path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"f",
")",
"\n",
"return",
"enc",
".",
"Encode",
"(",
"d",
")",
"\n",
"}"
] | // Save writes the DirPreferences values to the file in the struct's Path
// field | [
"Save",
"writes",
"the",
"DirPreferences",
"values",
"to",
"the",
"file",
"in",
"the",
"struct",
"s",
"Path",
"field"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/dirprefs/dirprefs.go#L61-L71 |
1,774 | manifoldco/torus-cli | dirprefs/dirprefs.go | isSystemRoot | func isSystemRoot(path string) bool {
if len(path) != rootPathLength {
return false
}
return os.PathSeparator == path[rootPathLength-1]
} | go | func isSystemRoot(path string) bool {
if len(path) != rootPathLength {
return false
}
return os.PathSeparator == path[rootPathLength-1]
} | [
"func",
"isSystemRoot",
"(",
"path",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"path",
")",
"!=",
"rootPathLength",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"os",
".",
"PathSeparator",
"==",
"path",
"[",
"rootPathLength",
"-",
"1",
"]",
"\n",
"}"
] | // isSystemRoot validates if the given path is the root of the system for the
// OS the application is running on. | [
"isSystemRoot",
"validates",
"if",
"the",
"given",
"path",
"is",
"the",
"root",
"of",
"the",
"system",
"for",
"the",
"OS",
"the",
"application",
"is",
"running",
"on",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/dirprefs/dirprefs.go#L80-L86 |
1,775 | manifoldco/torus-cli | errs/errs.go | ToError | func ToError(err error) error {
switch e := err.(type) {
case *cli.ExitError:
return e
case nil:
return nil
default:
return cli.NewExitError(err.Error(), -1)
}
} | go | func ToError(err error) error {
switch e := err.(type) {
case *cli.ExitError:
return e
case nil:
return nil
default:
return cli.NewExitError(err.Error(), -1)
}
} | [
"func",
"ToError",
"(",
"err",
"error",
")",
"error",
"{",
"switch",
"e",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"cli",
".",
"ExitError",
":",
"return",
"e",
"\n",
"case",
"nil",
":",
"return",
"nil",
"\n",
"default",
":",
"return",
"cli",
".",
"NewExitError",
"(",
"err",
".",
"Error",
"(",
")",
",",
"-",
"1",
")",
"\n",
"}",
"\n",
"}"
] | // ToError converts the given error into a cli.ExitError | [
"ToError",
"converts",
"the",
"given",
"error",
"into",
"a",
"cli",
".",
"ExitError"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/errs/errs.go#L19-L28 |
1,776 | manifoldco/torus-cli | errs/errs.go | NewUsageExitError | func NewUsageExitError(message string, ctx *cli.Context) error {
if wordRegex.MatchString(message[len(message)-1:]) {
message += "."
}
return cli.NewExitError(message+"\n"+usageString(ctx), -1)
} | go | func NewUsageExitError(message string, ctx *cli.Context) error {
if wordRegex.MatchString(message[len(message)-1:]) {
message += "."
}
return cli.NewExitError(message+"\n"+usageString(ctx), -1)
} | [
"func",
"NewUsageExitError",
"(",
"message",
"string",
",",
"ctx",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"if",
"wordRegex",
".",
"MatchString",
"(",
"message",
"[",
"len",
"(",
"message",
")",
"-",
"1",
":",
"]",
")",
"{",
"message",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"cli",
".",
"NewExitError",
"(",
"message",
"+",
"\"",
"\\n",
"\"",
"+",
"usageString",
"(",
"ctx",
")",
",",
"-",
"1",
")",
"\n",
"}"
] | // NewUsageExitError creates an ExitError with appended usage text | [
"NewUsageExitError",
"creates",
"an",
"ExitError",
"with",
"appended",
"usage",
"text"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/errs/errs.go#L36-L41 |
1,777 | manifoldco/torus-cli | errs/errs.go | NewErrorExitError | func NewErrorExitError(message string, err error) error {
if wordRegex.MatchString(message[len(message)-1:]) {
message += "."
}
return cli.NewExitError(message+"\n"+err.Error(), -1)
} | go | func NewErrorExitError(message string, err error) error {
if wordRegex.MatchString(message[len(message)-1:]) {
message += "."
}
return cli.NewExitError(message+"\n"+err.Error(), -1)
} | [
"func",
"NewErrorExitError",
"(",
"message",
"string",
",",
"err",
"error",
")",
"error",
"{",
"if",
"wordRegex",
".",
"MatchString",
"(",
"message",
"[",
"len",
"(",
"message",
")",
"-",
"1",
":",
"]",
")",
"{",
"message",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"cli",
".",
"NewExitError",
"(",
"message",
"+",
"\"",
"\\n",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
",",
"-",
"1",
")",
"\n",
"}"
] | // NewErrorExitError creates an ExitError with an appended error message | [
"NewErrorExitError",
"creates",
"an",
"ExitError",
"with",
"an",
"appended",
"error",
"message"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/errs/errs.go#L44-L49 |
1,778 | manifoldco/torus-cli | errs/errs.go | NewExitError | func NewExitError(message string) error {
if wordRegex.MatchString(message[len(message)-1:]) {
message += "."
}
return cli.NewExitError(message, -1)
} | go | func NewExitError(message string) error {
if wordRegex.MatchString(message[len(message)-1:]) {
message += "."
}
return cli.NewExitError(message, -1)
} | [
"func",
"NewExitError",
"(",
"message",
"string",
")",
"error",
"{",
"if",
"wordRegex",
".",
"MatchString",
"(",
"message",
"[",
"len",
"(",
"message",
")",
"-",
"1",
":",
"]",
")",
"{",
"message",
"+=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"cli",
".",
"NewExitError",
"(",
"message",
",",
"-",
"1",
")",
"\n",
"}"
] | // NewExitError creates an ExitError with -1 | [
"NewExitError",
"creates",
"an",
"ExitError",
"with",
"-",
"1"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/errs/errs.go#L52-L57 |
1,779 | manifoldco/torus-cli | errs/errs.go | MultiError | func MultiError(errors ...error) cli.MultiError {
nonNilErrs := []error{}
for _, e := range errors {
if e != nil {
nonNilErrs = append(nonNilErrs, e)
}
}
return cli.NewMultiError(nonNilErrs...)
} | go | func MultiError(errors ...error) cli.MultiError {
nonNilErrs := []error{}
for _, e := range errors {
if e != nil {
nonNilErrs = append(nonNilErrs, e)
}
}
return cli.NewMultiError(nonNilErrs...)
} | [
"func",
"MultiError",
"(",
"errors",
"...",
"error",
")",
"cli",
".",
"MultiError",
"{",
"nonNilErrs",
":=",
"[",
"]",
"error",
"{",
"}",
"\n",
"for",
"_",
",",
"e",
":=",
"range",
"errors",
"{",
"if",
"e",
"!=",
"nil",
"{",
"nonNilErrs",
"=",
"append",
"(",
"nonNilErrs",
",",
"e",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"cli",
".",
"NewMultiError",
"(",
"nonNilErrs",
"...",
")",
"\n",
"}"
] | // MultiError loops over all given errors unpacks them and then creates a new
// MultiError for non-nil entries. | [
"MultiError",
"loops",
"over",
"all",
"given",
"errors",
"unpacks",
"them",
"and",
"then",
"creates",
"a",
"new",
"MultiError",
"for",
"non",
"-",
"nil",
"entries",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/errs/errs.go#L61-L70 |
1,780 | manifoldco/torus-cli | api/version.go | GetDaemon | func (v *VersionClient) GetDaemon(ctx context.Context) (*apitypes.Version, error) {
version := &apitypes.Version{}
err := v.client.DaemonRoundTrip(ctx, "GET", "/version", nil, nil, version, nil)
return version, err
} | go | func (v *VersionClient) GetDaemon(ctx context.Context) (*apitypes.Version, error) {
version := &apitypes.Version{}
err := v.client.DaemonRoundTrip(ctx, "GET", "/version", nil, nil, version, nil)
return version, err
} | [
"func",
"(",
"v",
"*",
"VersionClient",
")",
"GetDaemon",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"apitypes",
".",
"Version",
",",
"error",
")",
"{",
"version",
":=",
"&",
"apitypes",
".",
"Version",
"{",
"}",
"\n",
"err",
":=",
"v",
".",
"client",
".",
"DaemonRoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"version",
",",
"nil",
")",
"\n",
"return",
"version",
",",
"err",
"\n",
"}"
] | // GetDaemon returns the daemon's release version. | [
"GetDaemon",
"returns",
"the",
"daemon",
"s",
"release",
"version",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/version.go#L22-L26 |
1,781 | manifoldco/torus-cli | gatekeeper/http/http.go | NewGatekeeper | func NewGatekeeper(org, team, certpath, keypath string, cfg *config.Config, api *api.Client) (*Gatekeeper, error) {
server := &http.Server{
Addr: cfg.GatekeeperAddress,
}
keypair, err := tlsKeypair(certpath, keypath)
if err != nil {
log.Printf("Starting Gatekeeper without SSL: %s", err)
} else {
if err != nil {
return nil, err
}
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{*keypair},
}
server.TLSConfig = tlsConfig
}
g := &Gatekeeper{
defaults: gatekeeperDefaults{
Org: org,
Team: team,
},
s: server,
c: cfg,
api: api,
}
return g, nil
} | go | func NewGatekeeper(org, team, certpath, keypath string, cfg *config.Config, api *api.Client) (*Gatekeeper, error) {
server := &http.Server{
Addr: cfg.GatekeeperAddress,
}
keypair, err := tlsKeypair(certpath, keypath)
if err != nil {
log.Printf("Starting Gatekeeper without SSL: %s", err)
} else {
if err != nil {
return nil, err
}
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{*keypair},
}
server.TLSConfig = tlsConfig
}
g := &Gatekeeper{
defaults: gatekeeperDefaults{
Org: org,
Team: team,
},
s: server,
c: cfg,
api: api,
}
return g, nil
} | [
"func",
"NewGatekeeper",
"(",
"org",
",",
"team",
",",
"certpath",
",",
"keypath",
"string",
",",
"cfg",
"*",
"config",
".",
"Config",
",",
"api",
"*",
"api",
".",
"Client",
")",
"(",
"*",
"Gatekeeper",
",",
"error",
")",
"{",
"server",
":=",
"&",
"http",
".",
"Server",
"{",
"Addr",
":",
"cfg",
".",
"GatekeeperAddress",
",",
"}",
"\n\n",
"keypair",
",",
"err",
":=",
"tlsKeypair",
"(",
"certpath",
",",
"keypath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tlsConfig",
":=",
"&",
"tls",
".",
"Config",
"{",
"MinVersion",
":",
"tls",
".",
"VersionTLS12",
",",
"Certificates",
":",
"[",
"]",
"tls",
".",
"Certificate",
"{",
"*",
"keypair",
"}",
",",
"}",
"\n\n",
"server",
".",
"TLSConfig",
"=",
"tlsConfig",
"\n",
"}",
"\n\n",
"g",
":=",
"&",
"Gatekeeper",
"{",
"defaults",
":",
"gatekeeperDefaults",
"{",
"Org",
":",
"org",
",",
"Team",
":",
"team",
",",
"}",
",",
"s",
":",
"server",
",",
"c",
":",
"cfg",
",",
"api",
":",
"api",
",",
"}",
"\n\n",
"return",
"g",
",",
"nil",
"\n",
"}"
] | // NewGatekeeper returns a new Gatekeeper. | [
"NewGatekeeper",
"returns",
"a",
"new",
"Gatekeeper",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/gatekeeper/http/http.go#L34-L66 |
1,782 | manifoldco/torus-cli | gatekeeper/http/http.go | Listen | func (g *Gatekeeper) Listen() error {
mux := bone.New()
mux.Post("/v0/machine/aws", routes.AWSBootstrapRoute(g.defaults.Org, g.defaults.Team, g.api))
g.s.Handler = loggingHandler(mux)
h := httpdown.HTTP{}
var err error
g.hd, err = h.ListenAndServe(g.s)
if err != nil {
return err
}
return g.hd.Wait()
} | go | func (g *Gatekeeper) Listen() error {
mux := bone.New()
mux.Post("/v0/machine/aws", routes.AWSBootstrapRoute(g.defaults.Org, g.defaults.Team, g.api))
g.s.Handler = loggingHandler(mux)
h := httpdown.HTTP{}
var err error
g.hd, err = h.ListenAndServe(g.s)
if err != nil {
return err
}
return g.hd.Wait()
} | [
"func",
"(",
"g",
"*",
"Gatekeeper",
")",
"Listen",
"(",
")",
"error",
"{",
"mux",
":=",
"bone",
".",
"New",
"(",
")",
"\n\n",
"mux",
".",
"Post",
"(",
"\"",
"\"",
",",
"routes",
".",
"AWSBootstrapRoute",
"(",
"g",
".",
"defaults",
".",
"Org",
",",
"g",
".",
"defaults",
".",
"Team",
",",
"g",
".",
"api",
")",
")",
"\n\n",
"g",
".",
"s",
".",
"Handler",
"=",
"loggingHandler",
"(",
"mux",
")",
"\n",
"h",
":=",
"httpdown",
".",
"HTTP",
"{",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"g",
".",
"hd",
",",
"err",
"=",
"h",
".",
"ListenAndServe",
"(",
"g",
".",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"g",
".",
"hd",
".",
"Wait",
"(",
")",
"\n",
"}"
] | // Listen listens on a TCP port for HTTP machine requests | [
"Listen",
"listens",
"on",
"a",
"TCP",
"port",
"for",
"HTTP",
"machine",
"requests"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/gatekeeper/http/http.go#L69-L84 |
1,783 | manifoldco/torus-cli | cmd/gatekeeper.go | startGatekeeperCmd | func startGatekeeperCmd(ctx *cli.Context) error {
log.SetOutput(os.Stdout)
cfg, err := config.LoadConfig()
if err != nil {
return errs.NewErrorExitError("Failed to load config.", err)
}
gatekeeper, err := gatekeeper.New(ctx.String("org"), ctx.String("role"), ctx.String("cert"), ctx.String("key"), cfg)
if err != nil {
log.Printf("Error starting a new Gatekeeper instance: %s", err)
return err
}
log.Printf("v%s of the Gatekeeper is now listeneing on %s", cfg.Version, gatekeeper.Addr())
err = gatekeeper.Listen()
if err != nil {
log.Printf("Error while running the Gatekeeper.\n%s", err)
}
return err
} | go | func startGatekeeperCmd(ctx *cli.Context) error {
log.SetOutput(os.Stdout)
cfg, err := config.LoadConfig()
if err != nil {
return errs.NewErrorExitError("Failed to load config.", err)
}
gatekeeper, err := gatekeeper.New(ctx.String("org"), ctx.String("role"), ctx.String("cert"), ctx.String("key"), cfg)
if err != nil {
log.Printf("Error starting a new Gatekeeper instance: %s", err)
return err
}
log.Printf("v%s of the Gatekeeper is now listeneing on %s", cfg.Version, gatekeeper.Addr())
err = gatekeeper.Listen()
if err != nil {
log.Printf("Error while running the Gatekeeper.\n%s", err)
}
return err
} | [
"func",
"startGatekeeperCmd",
"(",
"ctx",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"log",
".",
"SetOutput",
"(",
"os",
".",
"Stdout",
")",
"\n\n",
"cfg",
",",
"err",
":=",
"config",
".",
"LoadConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errs",
".",
"NewErrorExitError",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"gatekeeper",
",",
"err",
":=",
"gatekeeper",
".",
"New",
"(",
"ctx",
".",
"String",
"(",
"\"",
"\"",
")",
",",
"ctx",
".",
"String",
"(",
"\"",
"\"",
")",
",",
"ctx",
".",
"String",
"(",
"\"",
"\"",
")",
",",
"ctx",
".",
"String",
"(",
"\"",
"\"",
")",
",",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"cfg",
".",
"Version",
",",
"gatekeeper",
".",
"Addr",
"(",
")",
")",
"\n",
"err",
"=",
"gatekeeper",
".",
"Listen",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // startGatekeeper starts the machine Gatekeeper | [
"startGatekeeper",
"starts",
"the",
"machine",
"Gatekeeper"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/gatekeeper.go#L48-L69 |
1,784 | manifoldco/torus-cli | registry/orgs.go | Create | func (o *OrgsClient) Create(ctx context.Context, name string) (*envelope.Org, error) {
org := orgCreateRequest{}
org.Body.Name = name
res := envelope.Org{}
err := o.client.RoundTrip(ctx, "POST", "/orgs", nil, &org, &res)
return &res, err
} | go | func (o *OrgsClient) Create(ctx context.Context, name string) (*envelope.Org, error) {
org := orgCreateRequest{}
org.Body.Name = name
res := envelope.Org{}
err := o.client.RoundTrip(ctx, "POST", "/orgs", nil, &org, &res)
return &res, err
} | [
"func",
"(",
"o",
"*",
"OrgsClient",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"*",
"envelope",
".",
"Org",
",",
"error",
")",
"{",
"org",
":=",
"orgCreateRequest",
"{",
"}",
"\n",
"org",
".",
"Body",
".",
"Name",
"=",
"name",
"\n\n",
"res",
":=",
"envelope",
".",
"Org",
"{",
"}",
"\n",
"err",
":=",
"o",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"&",
"org",
",",
"&",
"res",
")",
"\n",
"return",
"&",
"res",
",",
"err",
"\n",
"}"
] | // Create creates a new org with the given name. It returns the newly-created org. | [
"Create",
"creates",
"a",
"new",
"org",
"with",
"the",
"given",
"name",
".",
"It",
"returns",
"the",
"newly",
"-",
"created",
"org",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/orgs.go#L38-L45 |
1,785 | manifoldco/torus-cli | registry/orgs.go | Get | func (o *OrgsClient) Get(ctx context.Context, orgID *identity.ID) (*envelope.Org, error) {
org := envelope.Org{}
err := o.client.RoundTrip(ctx, "GET", "/orgs/"+orgID.String(), nil, nil, &org)
return &org, err
} | go | func (o *OrgsClient) Get(ctx context.Context, orgID *identity.ID) (*envelope.Org, error) {
org := envelope.Org{}
err := o.client.RoundTrip(ctx, "GET", "/orgs/"+orgID.String(), nil, nil, &org)
return &org, err
} | [
"func",
"(",
"o",
"*",
"OrgsClient",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"*",
"identity",
".",
"ID",
")",
"(",
"*",
"envelope",
".",
"Org",
",",
"error",
")",
"{",
"org",
":=",
"envelope",
".",
"Org",
"{",
"}",
"\n",
"err",
":=",
"o",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"orgID",
".",
"String",
"(",
")",
",",
"nil",
",",
"nil",
",",
"&",
"org",
")",
"\n",
"return",
"&",
"org",
",",
"err",
"\n",
"}"
] | // Get returns the organization with the given ID. | [
"Get",
"returns",
"the",
"organization",
"with",
"the",
"given",
"ID",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/orgs.go#L48-L52 |
1,786 | manifoldco/torus-cli | registry/orgs.go | List | func (o *OrgsClient) List(ctx context.Context) ([]envelope.Org, error) {
var orgs []envelope.Org
err := o.client.RoundTrip(ctx, "GET", "/orgs", nil, nil, &orgs)
return orgs, err
} | go | func (o *OrgsClient) List(ctx context.Context) ([]envelope.Org, error) {
var orgs []envelope.Org
err := o.client.RoundTrip(ctx, "GET", "/orgs", nil, nil, &orgs)
return orgs, err
} | [
"func",
"(",
"o",
"*",
"OrgsClient",
")",
"List",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"envelope",
".",
"Org",
",",
"error",
")",
"{",
"var",
"orgs",
"[",
"]",
"envelope",
".",
"Org",
"\n",
"err",
":=",
"o",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
"&",
"orgs",
")",
"\n",
"return",
"orgs",
",",
"err",
"\n",
"}"
] | // List returns all organizations that the signed-in user has access to | [
"List",
"returns",
"all",
"organizations",
"that",
"the",
"signed",
"-",
"in",
"user",
"has",
"access",
"to"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/orgs.go#L75-L79 |
1,787 | manifoldco/torus-cli | registry/orgs.go | RemoveMember | func (o *OrgsClient) RemoveMember(ctx context.Context, orgID identity.ID,
userID identity.ID) error {
path := "/orgs/" + orgID.String() + "/members/" + userID.String()
return o.client.RoundTrip(ctx, "DELETE", path, nil, nil, nil)
} | go | func (o *OrgsClient) RemoveMember(ctx context.Context, orgID identity.ID,
userID identity.ID) error {
path := "/orgs/" + orgID.String() + "/members/" + userID.String()
return o.client.RoundTrip(ctx, "DELETE", path, nil, nil, nil)
} | [
"func",
"(",
"o",
"*",
"OrgsClient",
")",
"RemoveMember",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"identity",
".",
"ID",
",",
"userID",
"identity",
".",
"ID",
")",
"error",
"{",
"path",
":=",
"\"",
"\"",
"+",
"orgID",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"+",
"userID",
".",
"String",
"(",
")",
"\n",
"return",
"o",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"path",
",",
"nil",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] | // RemoveMember removes a user from an org | [
"RemoveMember",
"removes",
"a",
"user",
"from",
"an",
"org"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/orgs.go#L82-L87 |
1,788 | manifoldco/torus-cli | registry/orgs.go | GetTree | func (o *OrgsClient) GetTree(ctx context.Context, orgID identity.ID) ([]OrgTreeSegment, error) {
v := &url.Values{}
v.Set("org_id", orgID.String())
var segments []OrgTreeSegment
err := o.client.RoundTrip(ctx, "GET", "/orgtree", v, nil, &segments)
return segments, err
} | go | func (o *OrgsClient) GetTree(ctx context.Context, orgID identity.ID) ([]OrgTreeSegment, error) {
v := &url.Values{}
v.Set("org_id", orgID.String())
var segments []OrgTreeSegment
err := o.client.RoundTrip(ctx, "GET", "/orgtree", v, nil, &segments)
return segments, err
} | [
"func",
"(",
"o",
"*",
"OrgsClient",
")",
"GetTree",
"(",
"ctx",
"context",
".",
"Context",
",",
"orgID",
"identity",
".",
"ID",
")",
"(",
"[",
"]",
"OrgTreeSegment",
",",
"error",
")",
"{",
"v",
":=",
"&",
"url",
".",
"Values",
"{",
"}",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"orgID",
".",
"String",
"(",
")",
")",
"\n\n",
"var",
"segments",
"[",
"]",
"OrgTreeSegment",
"\n",
"err",
":=",
"o",
".",
"client",
".",
"RoundTrip",
"(",
"ctx",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"v",
",",
"nil",
",",
"&",
"segments",
")",
"\n",
"return",
"segments",
",",
"err",
"\n",
"}"
] | // GetTree returns an org tree | [
"GetTree",
"returns",
"an",
"org",
"tree"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/orgs.go#L90-L97 |
1,789 | manifoldco/torus-cli | daemon/logic/machine.go | CreateToken | func (m *Machine) CreateToken(ctx context.Context, notifier *observer.Notifier,
machine *envelope.Machine, secret *base64.Value) (*registry.MachineTokenCreationSegment, error) {
n := notifier.Notifier(2)
n.Notify(observer.Progress, "Generating machine token", true)
salt, err := crypto.GenerateSalt(ctx)
if err != nil {
return nil, err
}
keypair, err := crypto.DeriveLoginKeypair(ctx, *secret, salt)
if err != nil {
return nil, err
}
orgID := machine.Body.OrgID
masterKey, err := crypto.CreateMasterKeyObject(ctx, *secret, nil)
if err != nil {
return nil, err
}
tokenBody := &primitive.MachineToken{
OrgID: orgID,
MachineID: machine.ID,
PublicKey: &primitive.LoginPublicKey{
Salt: keypair.Salt(),
Value: keypair.PublicKey(),
Alg: crypto.EdDSA,
},
Master: masterKey,
CreatedBy: m.engine.session.ID(),
Created: time.Now().UTC(),
DestroyedBy: nil,
Destroyed: nil,
State: primitive.MachineTokenActiveState,
}
tokenID, err := identity.NewMutable(tokenBody)
if err != nil {
return nil, err
}
token := &envelope.MachineToken{
ID: &tokenID,
Version: 1,
Body: tokenBody,
}
// Create an "empty" machine session in order to create a Crypto engine on
// behalf of the machine for deriving and uploading these keys.
sess := session.NewSession(m.engine.guard)
err = sess.Set(apitypes.MachineSession, machine, token, *secret, []byte("hello"))
if err != nil {
return nil, err
}
c := crypto.NewEngine(sess, m.engine.guard)
n.Notify(observer.Progress, "Generating token keypairs", true)
kp, err := c.GenerateKeyPairs(ctx)
if err != nil {
log.Printf("Error generating machine keypairs: %s", err)
return nil, err
}
authID := sess.AuthID()
keypairs, err := generateKeypairs(ctx, c, orgID, authID, kp)
if err != nil {
return nil, err
}
return ®istry.MachineTokenCreationSegment{
Token: token,
Keypairs: keypairs,
}, nil
} | go | func (m *Machine) CreateToken(ctx context.Context, notifier *observer.Notifier,
machine *envelope.Machine, secret *base64.Value) (*registry.MachineTokenCreationSegment, error) {
n := notifier.Notifier(2)
n.Notify(observer.Progress, "Generating machine token", true)
salt, err := crypto.GenerateSalt(ctx)
if err != nil {
return nil, err
}
keypair, err := crypto.DeriveLoginKeypair(ctx, *secret, salt)
if err != nil {
return nil, err
}
orgID := machine.Body.OrgID
masterKey, err := crypto.CreateMasterKeyObject(ctx, *secret, nil)
if err != nil {
return nil, err
}
tokenBody := &primitive.MachineToken{
OrgID: orgID,
MachineID: machine.ID,
PublicKey: &primitive.LoginPublicKey{
Salt: keypair.Salt(),
Value: keypair.PublicKey(),
Alg: crypto.EdDSA,
},
Master: masterKey,
CreatedBy: m.engine.session.ID(),
Created: time.Now().UTC(),
DestroyedBy: nil,
Destroyed: nil,
State: primitive.MachineTokenActiveState,
}
tokenID, err := identity.NewMutable(tokenBody)
if err != nil {
return nil, err
}
token := &envelope.MachineToken{
ID: &tokenID,
Version: 1,
Body: tokenBody,
}
// Create an "empty" machine session in order to create a Crypto engine on
// behalf of the machine for deriving and uploading these keys.
sess := session.NewSession(m.engine.guard)
err = sess.Set(apitypes.MachineSession, machine, token, *secret, []byte("hello"))
if err != nil {
return nil, err
}
c := crypto.NewEngine(sess, m.engine.guard)
n.Notify(observer.Progress, "Generating token keypairs", true)
kp, err := c.GenerateKeyPairs(ctx)
if err != nil {
log.Printf("Error generating machine keypairs: %s", err)
return nil, err
}
authID := sess.AuthID()
keypairs, err := generateKeypairs(ctx, c, orgID, authID, kp)
if err != nil {
return nil, err
}
return ®istry.MachineTokenCreationSegment{
Token: token,
Keypairs: keypairs,
}, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"CreateToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"notifier",
"*",
"observer",
".",
"Notifier",
",",
"machine",
"*",
"envelope",
".",
"Machine",
",",
"secret",
"*",
"base64",
".",
"Value",
")",
"(",
"*",
"registry",
".",
"MachineTokenCreationSegment",
",",
"error",
")",
"{",
"n",
":=",
"notifier",
".",
"Notifier",
"(",
"2",
")",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n",
"salt",
",",
"err",
":=",
"crypto",
".",
"GenerateSalt",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"keypair",
",",
"err",
":=",
"crypto",
".",
"DeriveLoginKeypair",
"(",
"ctx",
",",
"*",
"secret",
",",
"salt",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"orgID",
":=",
"machine",
".",
"Body",
".",
"OrgID",
"\n\n",
"masterKey",
",",
"err",
":=",
"crypto",
".",
"CreateMasterKeyObject",
"(",
"ctx",
",",
"*",
"secret",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tokenBody",
":=",
"&",
"primitive",
".",
"MachineToken",
"{",
"OrgID",
":",
"orgID",
",",
"MachineID",
":",
"machine",
".",
"ID",
",",
"PublicKey",
":",
"&",
"primitive",
".",
"LoginPublicKey",
"{",
"Salt",
":",
"keypair",
".",
"Salt",
"(",
")",
",",
"Value",
":",
"keypair",
".",
"PublicKey",
"(",
")",
",",
"Alg",
":",
"crypto",
".",
"EdDSA",
",",
"}",
",",
"Master",
":",
"masterKey",
",",
"CreatedBy",
":",
"m",
".",
"engine",
".",
"session",
".",
"ID",
"(",
")",
",",
"Created",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
",",
"DestroyedBy",
":",
"nil",
",",
"Destroyed",
":",
"nil",
",",
"State",
":",
"primitive",
".",
"MachineTokenActiveState",
",",
"}",
"\n",
"tokenID",
",",
"err",
":=",
"identity",
".",
"NewMutable",
"(",
"tokenBody",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"token",
":=",
"&",
"envelope",
".",
"MachineToken",
"{",
"ID",
":",
"&",
"tokenID",
",",
"Version",
":",
"1",
",",
"Body",
":",
"tokenBody",
",",
"}",
"\n\n",
"// Create an \"empty\" machine session in order to create a Crypto engine on",
"// behalf of the machine for deriving and uploading these keys.",
"sess",
":=",
"session",
".",
"NewSession",
"(",
"m",
".",
"engine",
".",
"guard",
")",
"\n",
"err",
"=",
"sess",
".",
"Set",
"(",
"apitypes",
".",
"MachineSession",
",",
"machine",
",",
"token",
",",
"*",
"secret",
",",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
":=",
"crypto",
".",
"NewEngine",
"(",
"sess",
",",
"m",
".",
"engine",
".",
"guard",
")",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n",
"kp",
",",
"err",
":=",
"c",
".",
"GenerateKeyPairs",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"authID",
":=",
"sess",
".",
"AuthID",
"(",
")",
"\n",
"keypairs",
",",
"err",
":=",
"generateKeypairs",
"(",
"ctx",
",",
"c",
",",
"orgID",
",",
"authID",
",",
"kp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"registry",
".",
"MachineTokenCreationSegment",
"{",
"Token",
":",
"token",
",",
"Keypairs",
":",
"keypairs",
",",
"}",
",",
"nil",
"\n",
"}"
] | // CreateToken generates a new machine token given a machine and a secret value. | [
"CreateToken",
"generates",
"a",
"new",
"machine",
"token",
"given",
"a",
"machine",
"and",
"a",
"secret",
"value",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/machine.go#L33-L107 |
1,790 | manifoldco/torus-cli | daemon/logic/machine.go | EncodeToken | func (m *Machine) EncodeToken(ctx context.Context, notifier *observer.Notifier,
token *envelope.MachineToken) error {
n := notifier.Notifier(2)
n.Notify(observer.Progress, "Creating keyring memberships for token", true)
v1members, v2members, err := createKeyringMemberships(ctx, m.engine.crypto,
m.engine.client, m.engine.session, token.Body.OrgID, token.ID)
if err != nil {
return err
}
n.Notify(observer.Progress, "Uploading keyring memberships", true)
if len(v1members) != 0 {
_, err = m.engine.client.KeyringMember.Post(ctx, v1members)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return err
}
}
for _, member := range v2members {
err = m.engine.client.Keyring.Members.Post(ctx, member)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return err
}
}
return nil
} | go | func (m *Machine) EncodeToken(ctx context.Context, notifier *observer.Notifier,
token *envelope.MachineToken) error {
n := notifier.Notifier(2)
n.Notify(observer.Progress, "Creating keyring memberships for token", true)
v1members, v2members, err := createKeyringMemberships(ctx, m.engine.crypto,
m.engine.client, m.engine.session, token.Body.OrgID, token.ID)
if err != nil {
return err
}
n.Notify(observer.Progress, "Uploading keyring memberships", true)
if len(v1members) != 0 {
_, err = m.engine.client.KeyringMember.Post(ctx, v1members)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return err
}
}
for _, member := range v2members {
err = m.engine.client.Keyring.Members.Post(ctx, member)
if err != nil {
log.Printf("error uploading memberships: %s", err)
return err
}
}
return nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"EncodeToken",
"(",
"ctx",
"context",
".",
"Context",
",",
"notifier",
"*",
"observer",
".",
"Notifier",
",",
"token",
"*",
"envelope",
".",
"MachineToken",
")",
"error",
"{",
"n",
":=",
"notifier",
".",
"Notifier",
"(",
"2",
")",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n\n",
"v1members",
",",
"v2members",
",",
"err",
":=",
"createKeyringMemberships",
"(",
"ctx",
",",
"m",
".",
"engine",
".",
"crypto",
",",
"m",
".",
"engine",
".",
"client",
",",
"m",
".",
"engine",
".",
"session",
",",
"token",
".",
"Body",
".",
"OrgID",
",",
"token",
".",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"n",
".",
"Notify",
"(",
"observer",
".",
"Progress",
",",
"\"",
"\"",
",",
"true",
")",
"\n\n",
"if",
"len",
"(",
"v1members",
")",
"!=",
"0",
"{",
"_",
",",
"err",
"=",
"m",
".",
"engine",
".",
"client",
".",
"KeyringMember",
".",
"Post",
"(",
"ctx",
",",
"v1members",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"member",
":=",
"range",
"v2members",
"{",
"err",
"=",
"m",
".",
"engine",
".",
"client",
".",
"Keyring",
".",
"Members",
".",
"Post",
"(",
"ctx",
",",
"member",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // EncodeToken creates KeyringMemberships for the provided Machine Token. Used
// during the machine creation process | [
"EncodeToken",
"creates",
"KeyringMemberships",
"for",
"the",
"provided",
"Machine",
"Token",
".",
"Used",
"during",
"the",
"machine",
"creation",
"process"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/machine.go#L111-L143 |
1,791 | manifoldco/torus-cli | daemon/logic/credential_graph_set.go | Active | func (cgs *credentialGraphSet) Active() ([]registry.CredentialGraph, error) {
active := make([]registry.CredentialGraph, 0, len(cgs.graphs))
for _, graphs := range cgs.graphs {
// parents is the slice of IDs already seen in Previous fields.
// they cannot be active as they have been overwritten.
var parents []identity.ID
sort.Sort(graphSorter(graphs))
for headOffset, graph := range graphs {
var activeCreds []envelope.CredentialInf
var err error
activeCreds, parents, err = cgs.activeCreds(parents, graph)
if err != nil {
return nil, err
}
// the most recent version of a keyring is always active
// (it could be filled entirely with unset values)
if len(activeCreds) > 0 || headOffset == 0 {
active = append(active, graph)
}
}
}
return active, nil
} | go | func (cgs *credentialGraphSet) Active() ([]registry.CredentialGraph, error) {
active := make([]registry.CredentialGraph, 0, len(cgs.graphs))
for _, graphs := range cgs.graphs {
// parents is the slice of IDs already seen in Previous fields.
// they cannot be active as they have been overwritten.
var parents []identity.ID
sort.Sort(graphSorter(graphs))
for headOffset, graph := range graphs {
var activeCreds []envelope.CredentialInf
var err error
activeCreds, parents, err = cgs.activeCreds(parents, graph)
if err != nil {
return nil, err
}
// the most recent version of a keyring is always active
// (it could be filled entirely with unset values)
if len(activeCreds) > 0 || headOffset == 0 {
active = append(active, graph)
}
}
}
return active, nil
} | [
"func",
"(",
"cgs",
"*",
"credentialGraphSet",
")",
"Active",
"(",
")",
"(",
"[",
"]",
"registry",
".",
"CredentialGraph",
",",
"error",
")",
"{",
"active",
":=",
"make",
"(",
"[",
"]",
"registry",
".",
"CredentialGraph",
",",
"0",
",",
"len",
"(",
"cgs",
".",
"graphs",
")",
")",
"\n\n",
"for",
"_",
",",
"graphs",
":=",
"range",
"cgs",
".",
"graphs",
"{",
"// parents is the slice of IDs already seen in Previous fields.",
"// they cannot be active as they have been overwritten.",
"var",
"parents",
"[",
"]",
"identity",
".",
"ID",
"\n\n",
"sort",
".",
"Sort",
"(",
"graphSorter",
"(",
"graphs",
")",
")",
"\n",
"for",
"headOffset",
",",
"graph",
":=",
"range",
"graphs",
"{",
"var",
"activeCreds",
"[",
"]",
"envelope",
".",
"CredentialInf",
"\n",
"var",
"err",
"error",
"\n",
"activeCreds",
",",
"parents",
",",
"err",
"=",
"cgs",
".",
"activeCreds",
"(",
"parents",
",",
"graph",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// the most recent version of a keyring is always active",
"// (it could be filled entirely with unset values)",
"if",
"len",
"(",
"activeCreds",
")",
">",
"0",
"||",
"headOffset",
"==",
"0",
"{",
"active",
"=",
"append",
"(",
"active",
",",
"graph",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"active",
",",
"nil",
"\n",
"}"
] | // Active returns a slice of CredentialGraphs that contain credentials that
// are still reachable.
// A credential is reachable if a newer version of the CredentialGraph has not
// replaced its value, and it is not an `unset` Credential. | [
"Active",
"returns",
"a",
"slice",
"of",
"CredentialGraphs",
"that",
"contain",
"credentials",
"that",
"are",
"still",
"reachable",
".",
"A",
"credential",
"is",
"reachable",
"if",
"a",
"newer",
"version",
"of",
"the",
"CredentialGraph",
"has",
"not",
"replaced",
"its",
"value",
"and",
"it",
"is",
"not",
"an",
"unset",
"Credential",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/credential_graph_set.go#L92-L119 |
1,792 | manifoldco/torus-cli | daemon/logic/credential_graph_set.go | NeedRotation | func (cgs *credentialGraphSet) NeedRotation() ([]RotationReason, error) {
var needRotation []RotationReason
typ := (&primitive.User{}).Type()
for _, graphs := range cgs.graphs {
var parents []identity.ID
sort.Sort(graphSorter(graphs))
for _, graph := range graphs {
var activeCreds []envelope.CredentialInf
var err error
activeCreds, parents, err = cgs.activeCreds(parents, graph)
if err != nil {
return nil, err
}
var reasons []primitive.KeyringMemberClaim
for _, c := range graph.GetClaims() {
if c.Body.ClaimType == primitive.RevocationClaimType {
// Ignore machines
if c.Body.OwnerID.Type() == typ {
reasons = append(reasons, *c.Body)
}
}
}
if len(reasons) > 0 {
for _, c := range activeCreds {
needRotation = append(needRotation, RotationReason{
Credential: c,
Reasons: reasons,
})
}
}
}
}
return needRotation, nil
} | go | func (cgs *credentialGraphSet) NeedRotation() ([]RotationReason, error) {
var needRotation []RotationReason
typ := (&primitive.User{}).Type()
for _, graphs := range cgs.graphs {
var parents []identity.ID
sort.Sort(graphSorter(graphs))
for _, graph := range graphs {
var activeCreds []envelope.CredentialInf
var err error
activeCreds, parents, err = cgs.activeCreds(parents, graph)
if err != nil {
return nil, err
}
var reasons []primitive.KeyringMemberClaim
for _, c := range graph.GetClaims() {
if c.Body.ClaimType == primitive.RevocationClaimType {
// Ignore machines
if c.Body.OwnerID.Type() == typ {
reasons = append(reasons, *c.Body)
}
}
}
if len(reasons) > 0 {
for _, c := range activeCreds {
needRotation = append(needRotation, RotationReason{
Credential: c,
Reasons: reasons,
})
}
}
}
}
return needRotation, nil
} | [
"func",
"(",
"cgs",
"*",
"credentialGraphSet",
")",
"NeedRotation",
"(",
")",
"(",
"[",
"]",
"RotationReason",
",",
"error",
")",
"{",
"var",
"needRotation",
"[",
"]",
"RotationReason",
"\n\n",
"typ",
":=",
"(",
"&",
"primitive",
".",
"User",
"{",
"}",
")",
".",
"Type",
"(",
")",
"\n",
"for",
"_",
",",
"graphs",
":=",
"range",
"cgs",
".",
"graphs",
"{",
"var",
"parents",
"[",
"]",
"identity",
".",
"ID",
"\n\n",
"sort",
".",
"Sort",
"(",
"graphSorter",
"(",
"graphs",
")",
")",
"\n",
"for",
"_",
",",
"graph",
":=",
"range",
"graphs",
"{",
"var",
"activeCreds",
"[",
"]",
"envelope",
".",
"CredentialInf",
"\n",
"var",
"err",
"error",
"\n",
"activeCreds",
",",
"parents",
",",
"err",
"=",
"cgs",
".",
"activeCreds",
"(",
"parents",
",",
"graph",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"reasons",
"[",
"]",
"primitive",
".",
"KeyringMemberClaim",
"\n",
"for",
"_",
",",
"c",
":=",
"range",
"graph",
".",
"GetClaims",
"(",
")",
"{",
"if",
"c",
".",
"Body",
".",
"ClaimType",
"==",
"primitive",
".",
"RevocationClaimType",
"{",
"// Ignore machines",
"if",
"c",
".",
"Body",
".",
"OwnerID",
".",
"Type",
"(",
")",
"==",
"typ",
"{",
"reasons",
"=",
"append",
"(",
"reasons",
",",
"*",
"c",
".",
"Body",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"reasons",
")",
">",
"0",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"activeCreds",
"{",
"needRotation",
"=",
"append",
"(",
"needRotation",
",",
"RotationReason",
"{",
"Credential",
":",
"c",
",",
"Reasons",
":",
"reasons",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"needRotation",
",",
"nil",
"\n",
"}"
] | // NeedRotation returns a slice of Credentials that need to be rotated.
//
// A Credential needs to be rotated if its most recent set version is in a
// CredentialGraph version that contains a revocation of a user's share to
// that Keyring. | [
"NeedRotation",
"returns",
"a",
"slice",
"of",
"Credentials",
"that",
"need",
"to",
"be",
"rotated",
".",
"A",
"Credential",
"needs",
"to",
"be",
"rotated",
"if",
"its",
"most",
"recent",
"set",
"version",
"is",
"in",
"a",
"CredentialGraph",
"version",
"that",
"contains",
"a",
"revocation",
"of",
"a",
"user",
"s",
"share",
"to",
"that",
"Keyring",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/credential_graph_set.go#L173-L211 |
1,793 | manifoldco/torus-cli | daemon/logic/credential_graph_set.go | Head | func (cgs *credentialGraphSet) Head(pe *pathexp.PathExp) (registry.CredentialGraph, error) {
gpe, err := pe.WithInstance("*")
if err != nil {
return nil, err
}
graphs, ok := cgs.graphs[gpe.String()]
if !ok {
return nil, nil
}
sort.Sort(graphSorter(graphs))
return graphs[0], nil
} | go | func (cgs *credentialGraphSet) Head(pe *pathexp.PathExp) (registry.CredentialGraph, error) {
gpe, err := pe.WithInstance("*")
if err != nil {
return nil, err
}
graphs, ok := cgs.graphs[gpe.String()]
if !ok {
return nil, nil
}
sort.Sort(graphSorter(graphs))
return graphs[0], nil
} | [
"func",
"(",
"cgs",
"*",
"credentialGraphSet",
")",
"Head",
"(",
"pe",
"*",
"pathexp",
".",
"PathExp",
")",
"(",
"registry",
".",
"CredentialGraph",
",",
"error",
")",
"{",
"gpe",
",",
"err",
":=",
"pe",
".",
"WithInstance",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"graphs",
",",
"ok",
":=",
"cgs",
".",
"graphs",
"[",
"gpe",
".",
"String",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"sort",
".",
"Sort",
"(",
"graphSorter",
"(",
"graphs",
")",
")",
"\n",
"return",
"graphs",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // Head returns the most recent version of a CredentialGraph that would contain
// the given PathExp. | [
"Head",
"returns",
"the",
"most",
"recent",
"version",
"of",
"a",
"CredentialGraph",
"that",
"would",
"contain",
"the",
"given",
"PathExp",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/credential_graph_set.go#L215-L229 |
1,794 | manifoldco/torus-cli | daemon/logic/credential_graph_set.go | HeadCredential | func (cgs *credentialGraphSet) HeadCredential(pe *pathexp.PathExp, name string) (envelope.CredentialInf, error) {
var head envelope.CredentialInf
version := -1
gpe, err := pe.WithInstance("*")
if err != nil {
return nil, err
}
graphs, ok := cgs.graphs[gpe.String()]
if !ok {
return nil, nil
}
sort.Sort(graphSorter(graphs))
for _, graph := range graphs {
creds := graph.GetCredentials()
for _, cred := range creds {
if cred.PathExp().Equal(pe) && cred.Name() == name && cred.CredentialVersion() > version {
env := cred
head = env
version = cred.CredentialVersion()
}
}
}
return head, nil
} | go | func (cgs *credentialGraphSet) HeadCredential(pe *pathexp.PathExp, name string) (envelope.CredentialInf, error) {
var head envelope.CredentialInf
version := -1
gpe, err := pe.WithInstance("*")
if err != nil {
return nil, err
}
graphs, ok := cgs.graphs[gpe.String()]
if !ok {
return nil, nil
}
sort.Sort(graphSorter(graphs))
for _, graph := range graphs {
creds := graph.GetCredentials()
for _, cred := range creds {
if cred.PathExp().Equal(pe) && cred.Name() == name && cred.CredentialVersion() > version {
env := cred
head = env
version = cred.CredentialVersion()
}
}
}
return head, nil
} | [
"func",
"(",
"cgs",
"*",
"credentialGraphSet",
")",
"HeadCredential",
"(",
"pe",
"*",
"pathexp",
".",
"PathExp",
",",
"name",
"string",
")",
"(",
"envelope",
".",
"CredentialInf",
",",
"error",
")",
"{",
"var",
"head",
"envelope",
".",
"CredentialInf",
"\n",
"version",
":=",
"-",
"1",
"\n\n",
"gpe",
",",
"err",
":=",
"pe",
".",
"WithInstance",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"graphs",
",",
"ok",
":=",
"cgs",
".",
"graphs",
"[",
"gpe",
".",
"String",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n\n",
"sort",
".",
"Sort",
"(",
"graphSorter",
"(",
"graphs",
")",
")",
"\n",
"for",
"_",
",",
"graph",
":=",
"range",
"graphs",
"{",
"creds",
":=",
"graph",
".",
"GetCredentials",
"(",
")",
"\n",
"for",
"_",
",",
"cred",
":=",
"range",
"creds",
"{",
"if",
"cred",
".",
"PathExp",
"(",
")",
".",
"Equal",
"(",
"pe",
")",
"&&",
"cred",
".",
"Name",
"(",
")",
"==",
"name",
"&&",
"cred",
".",
"CredentialVersion",
"(",
")",
">",
"version",
"{",
"env",
":=",
"cred",
"\n",
"head",
"=",
"env",
"\n",
"version",
"=",
"cred",
".",
"CredentialVersion",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"head",
",",
"nil",
"\n",
"}"
] | // HeadCredential returns the most recent version of a Credential that shares
// the provided PathExp and Name
//
// A Head Credential need not be in the Head of the CredentialGraph. | [
"HeadCredential",
"returns",
"the",
"most",
"recent",
"version",
"of",
"a",
"Credential",
"that",
"shares",
"the",
"provided",
"PathExp",
"and",
"Name",
"A",
"Head",
"Credential",
"need",
"not",
"be",
"in",
"the",
"Head",
"of",
"the",
"CredentialGraph",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/credential_graph_set.go#L235-L262 |
1,795 | manifoldco/torus-cli | api/client.go | NewDaemonRequest | func (rt *apiRoundTripper) NewDaemonRequest(method, path string,
query *url.Values, body interface{}) (*http.Request, string, error) {
return rt.newRequest(method, daemonAPIVersion, path, query, body)
} | go | func (rt *apiRoundTripper) NewDaemonRequest(method, path string,
query *url.Values, body interface{}) (*http.Request, string, error) {
return rt.newRequest(method, daemonAPIVersion, path, query, body)
} | [
"func",
"(",
"rt",
"*",
"apiRoundTripper",
")",
"NewDaemonRequest",
"(",
"method",
",",
"path",
"string",
",",
"query",
"*",
"url",
".",
"Values",
",",
"body",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"string",
",",
"error",
")",
"{",
"return",
"rt",
".",
"newRequest",
"(",
"method",
",",
"daemonAPIVersion",
",",
"path",
",",
"query",
",",
"body",
")",
"\n",
"}"
] | // NewDaemonRequest constructs a new http.Request, with a body containing the json
// representation of body, if provided. Daemon requests are handled directly
// by the torus daemon. | [
"NewDaemonRequest",
"constructs",
"a",
"new",
"http",
".",
"Request",
"with",
"a",
"body",
"containing",
"the",
"json",
"representation",
"of",
"body",
"if",
"provided",
".",
"Daemon",
"requests",
"are",
"handled",
"directly",
"by",
"the",
"torus",
"daemon",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/client.go#L91-L95 |
1,796 | manifoldco/torus-cli | api/client.go | newRequest | func (rt *apiRoundTripper) newRequest(method, prefix, path string,
query *url.Values, body interface{}) (*http.Request, string, error) {
requestID := uuid.NewV4().String()
prefixed := "/" + prefix + path
req, err := rt.DefaultRequestDoer.NewRequest(method, prefixed, query, body)
if err != nil {
return nil, requestID, err
}
req.Header.Set("X-Request-ID", requestID)
return req, requestID, nil
} | go | func (rt *apiRoundTripper) newRequest(method, prefix, path string,
query *url.Values, body interface{}) (*http.Request, string, error) {
requestID := uuid.NewV4().String()
prefixed := "/" + prefix + path
req, err := rt.DefaultRequestDoer.NewRequest(method, prefixed, query, body)
if err != nil {
return nil, requestID, err
}
req.Header.Set("X-Request-ID", requestID)
return req, requestID, nil
} | [
"func",
"(",
"rt",
"*",
"apiRoundTripper",
")",
"newRequest",
"(",
"method",
",",
"prefix",
",",
"path",
"string",
",",
"query",
"*",
"url",
".",
"Values",
",",
"body",
"interface",
"{",
"}",
")",
"(",
"*",
"http",
".",
"Request",
",",
"string",
",",
"error",
")",
"{",
"requestID",
":=",
"uuid",
".",
"NewV4",
"(",
")",
".",
"String",
"(",
")",
"\n\n",
"prefixed",
":=",
"\"",
"\"",
"+",
"prefix",
"+",
"path",
"\n",
"req",
",",
"err",
":=",
"rt",
".",
"DefaultRequestDoer",
".",
"NewRequest",
"(",
"method",
",",
"prefixed",
",",
"query",
",",
"body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"requestID",
",",
"err",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"requestID",
")",
"\n\n",
"return",
"req",
",",
"requestID",
",",
"nil",
"\n",
"}"
] | // newRequest augments the default to set a unique request id | [
"newRequest",
"augments",
"the",
"default",
"to",
"set",
"a",
"unique",
"request",
"id"
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/client.go#L105-L119 |
1,797 | manifoldco/torus-cli | api/client.go | DoWithProgress | func (rt *apiRoundTripper) DoWithProgress(ctx context.Context, r *http.Request, v interface{}, reqID string, progress ProgressFunc) (*http.Response, error) {
done := make(chan bool)
req, _, err := rt.newRequest("GET", daemonAPIVersion, "/observe", nil, nil)
if err != nil {
return nil, err
}
stream, err := eventsource.SubscribeWith("", rt.Client, req)
if err != nil {
return nil, err
}
go func() {
for {
select {
case <-done:
return
case ev := <-stream.Events:
data := ev.Data()
raw := []byte(data)
event := Event{}
event.MessageType = "message"
err = json.Unmarshal(raw, &event)
if err != nil {
progress(nil, err)
go func() {
<-done
}()
return
}
if event.ID == reqID {
progress(&event, nil)
}
case err := <-stream.Errors:
progress(nil, err)
}
}
}()
defer func() { done <- true }()
return rt.Do(ctx, r, v)
} | go | func (rt *apiRoundTripper) DoWithProgress(ctx context.Context, r *http.Request, v interface{}, reqID string, progress ProgressFunc) (*http.Response, error) {
done := make(chan bool)
req, _, err := rt.newRequest("GET", daemonAPIVersion, "/observe", nil, nil)
if err != nil {
return nil, err
}
stream, err := eventsource.SubscribeWith("", rt.Client, req)
if err != nil {
return nil, err
}
go func() {
for {
select {
case <-done:
return
case ev := <-stream.Events:
data := ev.Data()
raw := []byte(data)
event := Event{}
event.MessageType = "message"
err = json.Unmarshal(raw, &event)
if err != nil {
progress(nil, err)
go func() {
<-done
}()
return
}
if event.ID == reqID {
progress(&event, nil)
}
case err := <-stream.Errors:
progress(nil, err)
}
}
}()
defer func() { done <- true }()
return rt.Do(ctx, r, v)
} | [
"func",
"(",
"rt",
"*",
"apiRoundTripper",
")",
"DoWithProgress",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"interface",
"{",
"}",
",",
"reqID",
"string",
",",
"progress",
"ProgressFunc",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"done",
":=",
"make",
"(",
"chan",
"bool",
")",
"\n",
"req",
",",
"_",
",",
"err",
":=",
"rt",
".",
"newRequest",
"(",
"\"",
"\"",
",",
"daemonAPIVersion",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stream",
",",
"err",
":=",
"eventsource",
".",
"SubscribeWith",
"(",
"\"",
"\"",
",",
"rt",
".",
"Client",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"select",
"{",
"case",
"<-",
"done",
":",
"return",
"\n",
"case",
"ev",
":=",
"<-",
"stream",
".",
"Events",
":",
"data",
":=",
"ev",
".",
"Data",
"(",
")",
"\n",
"raw",
":=",
"[",
"]",
"byte",
"(",
"data",
")",
"\n\n",
"event",
":=",
"Event",
"{",
"}",
"\n",
"event",
".",
"MessageType",
"=",
"\"",
"\"",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"raw",
",",
"&",
"event",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"progress",
"(",
"nil",
",",
"err",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"<-",
"done",
"\n",
"}",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"event",
".",
"ID",
"==",
"reqID",
"{",
"progress",
"(",
"&",
"event",
",",
"nil",
")",
"\n",
"}",
"\n",
"case",
"err",
":=",
"<-",
"stream",
".",
"Errors",
":",
"progress",
"(",
"nil",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"done",
"<-",
"true",
"}",
"(",
")",
"\n\n",
"return",
"rt",
".",
"Do",
"(",
"ctx",
",",
"r",
",",
"v",
")",
"\n",
"}"
] | // DoWithProgress executes the HTTP request like Do, in addition to
// connecting the provided ProgressFunc to any server-sent event progress
// messages. | [
"DoWithProgress",
"executes",
"the",
"HTTP",
"request",
"like",
"Do",
"in",
"addition",
"to",
"connecting",
"the",
"provided",
"ProgressFunc",
"to",
"any",
"server",
"-",
"sent",
"event",
"progress",
"messages",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/client.go#L124-L166 |
1,798 | manifoldco/torus-cli | daemon/updates/updates.go | NewEngine | func NewEngine(cfg *config.Config, t *http.Transport, options ...func(*Engine)) *Engine {
engine := &Engine{
config: cfg,
stop: make(chan struct{}),
targetVersion: "unknown",
client: &http.Client{Transport: t},
}
for _, opt := range options {
opt(engine)
}
if engine.timeManager == nil {
engine.timeManager = defaultTimeManager{}
}
return engine
} | go | func NewEngine(cfg *config.Config, t *http.Transport, options ...func(*Engine)) *Engine {
engine := &Engine{
config: cfg,
stop: make(chan struct{}),
targetVersion: "unknown",
client: &http.Client{Transport: t},
}
for _, opt := range options {
opt(engine)
}
if engine.timeManager == nil {
engine.timeManager = defaultTimeManager{}
}
return engine
} | [
"func",
"NewEngine",
"(",
"cfg",
"*",
"config",
".",
"Config",
",",
"t",
"*",
"http",
".",
"Transport",
",",
"options",
"...",
"func",
"(",
"*",
"Engine",
")",
")",
"*",
"Engine",
"{",
"engine",
":=",
"&",
"Engine",
"{",
"config",
":",
"cfg",
",",
"stop",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"targetVersion",
":",
"\"",
"\"",
",",
"client",
":",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"t",
"}",
",",
"}",
"\n\n",
"for",
"_",
",",
"opt",
":=",
"range",
"options",
"{",
"opt",
"(",
"engine",
")",
"\n",
"}",
"\n\n",
"if",
"engine",
".",
"timeManager",
"==",
"nil",
"{",
"engine",
".",
"timeManager",
"=",
"defaultTimeManager",
"{",
"}",
"\n",
"}",
"\n\n",
"return",
"engine",
"\n",
"}"
] | // NewEngine creates a new Engine based on the provided config structure.
// It can be extended by passing specific options which alter the initialization
// of the Engine itself. | [
"NewEngine",
"creates",
"a",
"new",
"Engine",
"based",
"on",
"the",
"provided",
"config",
"structure",
".",
"It",
"can",
"be",
"extended",
"by",
"passing",
"specific",
"options",
"which",
"alter",
"the",
"initialization",
"of",
"the",
"Engine",
"itself",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/updates/updates.go#L60-L77 |
1,799 | manifoldco/torus-cli | daemon/updates/updates.go | SetTimeManager | func (e *Engine) SetTimeManager(manager TimeManager) func(*Engine) {
return func(engine *Engine) {
engine.timeManager = manager
}
} | go | func (e *Engine) SetTimeManager(manager TimeManager) func(*Engine) {
return func(engine *Engine) {
engine.timeManager = manager
}
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"SetTimeManager",
"(",
"manager",
"TimeManager",
")",
"func",
"(",
"*",
"Engine",
")",
"{",
"return",
"func",
"(",
"engine",
"*",
"Engine",
")",
"{",
"engine",
".",
"timeManager",
"=",
"manager",
"\n",
"}",
"\n",
"}"
] | // SetTimeManager is a configuration function for `NewEngine` which sets the
// Engine's TimeManager instance to the `manager` argument. | [
"SetTimeManager",
"is",
"a",
"configuration",
"function",
"for",
"NewEngine",
"which",
"sets",
"the",
"Engine",
"s",
"TimeManager",
"instance",
"to",
"the",
"manager",
"argument",
"."
] | 137599f985e6f676c081ffb4230aaad52fb7d26c | https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/updates/updates.go#L99-L103 |
Subsets and Splits