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
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
1,600
manifoldco/torus-cli
daemon/observer/observer.go
Start
func (o *Observer) Start() { for { select { case evt := <-o.notify: // We have an event to observe if len(o.observers) == 0 { log.Printf("Ignoring event due to no observers: %s", evt.ID) continue } evtb, err := json.Marshal(evt) if err != nil { log.Printf("Error marshaling event: %s", err) continue } sse := []byte("event: " + evt.Type + "\ndata: ") sse = append(sse, append(evtb, []byte("\n\n")...)...) for n := range o.observers { n <- sse } case n := <-o.newObservers: o.observers[n] = true case n := <-o.closedObservers: delete(o.observers, n) case <-o.closed: // The Observer has been closed. return } } }
go
func (o *Observer) Start() { for { select { case evt := <-o.notify: // We have an event to observe if len(o.observers) == 0 { log.Printf("Ignoring event due to no observers: %s", evt.ID) continue } evtb, err := json.Marshal(evt) if err != nil { log.Printf("Error marshaling event: %s", err) continue } sse := []byte("event: " + evt.Type + "\ndata: ") sse = append(sse, append(evtb, []byte("\n\n")...)...) for n := range o.observers { n <- sse } case n := <-o.newObservers: o.observers[n] = true case n := <-o.closedObservers: delete(o.observers, n) case <-o.closed: // The Observer has been closed. return } } }
[ "func", "(", "o", "*", "Observer", ")", "Start", "(", ")", "{", "for", "{", "select", "{", "case", "evt", ":=", "<-", "o", ".", "notify", ":", "// We have an event to observe", "if", "len", "(", "o", ".", "observers", ")", "==", "0", "{", "log", "....
// Start begins listening for notifications of observable events. It returns // after stop has been called.
[ "Start", "begins", "listening", "for", "notifications", "of", "observable", "events", ".", "It", "returns", "after", "stop", "has", "been", "called", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/observer/observer.go#L253-L284
1,601
manifoldco/torus-cli
prefs/publickey.go
LoadPublicKey
func LoadPublicKey(prefs *Preferences) (*PublicKey, error) { filePath := prefs.Core.PublicKeyFile var fd io.Reader var err error if filePath == "" { var b []byte b, err = data.Asset("data/public_key.json") if err == nil { fd = bytes.NewReader(b) } } else { fd, err = readPublicKeyFile(filePath) } if err != nil { return nil, err } key, err := parsePublicKeyFile(fd) if err != nil { return nil, err } return key, nil }
go
func LoadPublicKey(prefs *Preferences) (*PublicKey, error) { filePath := prefs.Core.PublicKeyFile var fd io.Reader var err error if filePath == "" { var b []byte b, err = data.Asset("data/public_key.json") if err == nil { fd = bytes.NewReader(b) } } else { fd, err = readPublicKeyFile(filePath) } if err != nil { return nil, err } key, err := parsePublicKeyFile(fd) if err != nil { return nil, err } return key, nil }
[ "func", "LoadPublicKey", "(", "prefs", "*", "Preferences", ")", "(", "*", "PublicKey", ",", "error", ")", "{", "filePath", ":=", "prefs", ".", "Core", ".", "PublicKeyFile", "\n\n", "var", "fd", "io", ".", "Reader", "\n", "var", "err", "error", "\n\n", ...
// LoadPublicKey reads the publickey file from disk and parses the json
[ "LoadPublicKey", "reads", "the", "publickey", "file", "from", "disk", "and", "parses", "the", "json" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/prefs/publickey.go#L24-L51
1,602
manifoldco/torus-cli
prefs/publickey.go
ValidatePublicKey
func ValidatePublicKey(filePath string) error { var text string src, err := os.Stat(filePath) if err != nil { return errs.NewExitError("Publick key file must exist") } fMode := src.Mode() if fMode.Perm() != requiredPermissions { text = fmt.Sprintf("File specified has permissions %d, must have permissions %d", fMode.Perm(), requiredPermissions) return errs.NewExitError(text) } fd, err := readPublicKeyFile(filePath) if err != nil { return errs.NewExitError("Could not read file, permissions ok") } _, err = parsePublicKeyFile(fd) if err != nil { return errs.NewExitError("Could not parse JSON") } return nil }
go
func ValidatePublicKey(filePath string) error { var text string src, err := os.Stat(filePath) if err != nil { return errs.NewExitError("Publick key file must exist") } fMode := src.Mode() if fMode.Perm() != requiredPermissions { text = fmt.Sprintf("File specified has permissions %d, must have permissions %d", fMode.Perm(), requiredPermissions) return errs.NewExitError(text) } fd, err := readPublicKeyFile(filePath) if err != nil { return errs.NewExitError("Could not read file, permissions ok") } _, err = parsePublicKeyFile(fd) if err != nil { return errs.NewExitError("Could not parse JSON") } return nil }
[ "func", "ValidatePublicKey", "(", "filePath", "string", ")", "error", "{", "var", "text", "string", "\n\n", "src", ",", "err", ":=", "os", ".", "Stat", "(", "filePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errs", ".", "NewExitError", "(...
// ValidatePublicKey checks the publickey path for valid file
[ "ValidatePublicKey", "checks", "the", "publickey", "path", "for", "valid", "file" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/prefs/publickey.go#L78-L103
1,603
manifoldco/torus-cli
daemon/ctxutil/ctxutil.go
ErrIfDone
func ErrIfDone(ctx context.Context) error { select { case <-ctx.Done(): return ctx.Err() default: return nil } }
go
func ErrIfDone(ctx context.Context) error { select { case <-ctx.Done(): return ctx.Err() default: return nil } }
[ "func", "ErrIfDone", "(", "ctx", "context", ".", "Context", ")", "error", "{", "select", "{", "case", "<-", "ctx", ".", "Done", "(", ")", ":", "return", "ctx", ".", "Err", "(", ")", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}" ]
// ErrIfDone returns the Context's error if done. It is a convenience method // for long-running routines that don't have cancellable goroutines.
[ "ErrIfDone", "returns", "the", "Context", "s", "error", "if", "done", ".", "It", "is", "a", "convenience", "method", "for", "long", "-", "running", "routines", "that", "don", "t", "have", "cancellable", "goroutines", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/ctxutil/ctxutil.go#L8-L15
1,604
manifoldco/torus-cli
daemon/logic/session.go
Login
func (s *Session) Login(ctx context.Context, creds apitypes.LoginCredential) error { if !creds.Valid() { return &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{"invalid login credentials provided"}, } } salt, loginToken, err := s.engine.client.Tokens.PostLogin(ctx, creds) if err != nil { return err } mechanism := loginToken.Body.Mechanism var authToken *envelope.Token switch mechanism { case primitive.HMACAuth: authToken, err = s.attemptEdDSAUpgrade(ctx, loginToken, salt, creds) case primitive.EdDSAAuth: authToken, err = s.attemptEdDSALogin(ctx, loginToken, salt, creds) default: err = &apitypes.Error{ Type: apitypes.InternalServerError, Err: []string{fmt.Sprintf("unrecognized auth mechanism: %s", mechanism)}, } } if err != nil { return err } token := []byte(authToken.Body.Token) self, err := s.engine.client.Self.Get(ctx, authToken.Body.Token) if err != nil { return err } s.engine.db.Set(self.Identity) if self.Type == apitypes.UserSession { s.engine.db.Set(self.Auth) } return s.engine.session.Set(self.Type, self.Identity, self.Auth, creds.Passphrase(), token) }
go
func (s *Session) Login(ctx context.Context, creds apitypes.LoginCredential) error { if !creds.Valid() { return &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{"invalid login credentials provided"}, } } salt, loginToken, err := s.engine.client.Tokens.PostLogin(ctx, creds) if err != nil { return err } mechanism := loginToken.Body.Mechanism var authToken *envelope.Token switch mechanism { case primitive.HMACAuth: authToken, err = s.attemptEdDSAUpgrade(ctx, loginToken, salt, creds) case primitive.EdDSAAuth: authToken, err = s.attemptEdDSALogin(ctx, loginToken, salt, creds) default: err = &apitypes.Error{ Type: apitypes.InternalServerError, Err: []string{fmt.Sprintf("unrecognized auth mechanism: %s", mechanism)}, } } if err != nil { return err } token := []byte(authToken.Body.Token) self, err := s.engine.client.Self.Get(ctx, authToken.Body.Token) if err != nil { return err } s.engine.db.Set(self.Identity) if self.Type == apitypes.UserSession { s.engine.db.Set(self.Auth) } return s.engine.session.Set(self.Type, self.Identity, self.Auth, creds.Passphrase(), token) }
[ "func", "(", "s", "*", "Session", ")", "Login", "(", "ctx", "context", ".", "Context", ",", "creds", "apitypes", ".", "LoginCredential", ")", "error", "{", "if", "!", "creds", ".", "Valid", "(", ")", "{", "return", "&", "apitypes", ".", "Error", "{",...
// Login attempts to create a valid auth token to authorize http requests made // against the registry.
[ "Login", "attempts", "to", "create", "a", "valid", "auth", "token", "to", "authorize", "http", "requests", "made", "against", "the", "registry", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/session.go#L33-L75
1,605
manifoldco/torus-cli
daemon/logic/session.go
Verify
func (s *Session) Verify(ctx context.Context, code string) error { if s.engine.session.Type() == apitypes.MachineSession { return &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{"A machine cannot verify it's acccount!"}, } } err := s.engine.client.Users.VerifyEmail(ctx, code) if err != nil { return err } token := s.engine.session.Token() self, err := s.engine.client.Self.Get(ctx, string(token)) if err != nil { return err } err = s.engine.session.SetIdentity(self.Type, self.Identity, self.Auth) if err != nil { return err } return s.engine.session.SetIdentity(self.Type, self.Identity, self.Auth) }
go
func (s *Session) Verify(ctx context.Context, code string) error { if s.engine.session.Type() == apitypes.MachineSession { return &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{"A machine cannot verify it's acccount!"}, } } err := s.engine.client.Users.VerifyEmail(ctx, code) if err != nil { return err } token := s.engine.session.Token() self, err := s.engine.client.Self.Get(ctx, string(token)) if err != nil { return err } err = s.engine.session.SetIdentity(self.Type, self.Identity, self.Auth) if err != nil { return err } return s.engine.session.SetIdentity(self.Type, self.Identity, self.Auth) }
[ "func", "(", "s", "*", "Session", ")", "Verify", "(", "ctx", "context", ".", "Context", ",", "code", "string", ")", "error", "{", "if", "s", ".", "engine", ".", "session", ".", "Type", "(", ")", "==", "apitypes", ".", "MachineSession", "{", "return",...
// Verify attempts to verify the users account using the
[ "Verify", "attempts", "to", "verify", "the", "users", "account", "using", "the" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/session.go#L78-L103
1,606
manifoldco/torus-cli
daemon/logic/session.go
UpdateProfile
func (s *Session) UpdateProfile(ctx context.Context, newEmail, newName, newPassword string) (envelope.UserInf, error) { if s.engine.session.Type() != apitypes.UserSession { return nil, &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{"You must be a logged in user to change your password!"}, } } // Convert the auth portion of the session to a UserInf interface // Note: the auth and identity sections for a user are the same user, ok := s.engine.session.Self().Auth.(envelope.UserInf) if !ok { log.Printf("Could not convert to UserInf during update profile") return nil, &apitypes.Error{ Type: apitypes.InternalServerError, Err: []string{"Could not convert to user interface"}, } } if user.StructVersion() != 2 { return nil, &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{fmt.Sprintf( "User schema must be v2 to perform password change: %d", user.StructVersion()), }, } } payload := &updateProfile{} if newEmail != "" { payload.Email = newEmail } if newName != "" { payload.Name = newName } if newPassword != "" { pw, master, keypair, err := s.engine.crypto.ChangePassword(ctx, newPassword) if err != nil { log.Printf("Could not re-encrypt master key: %s", err) return nil, &apitypes.Error{ Type: apitypes.InternalServerError, Err: []string{"Could not re-encrypt master key"}, } } payload.Password = pw payload.Master = master payload.PublicKey = keypair } updatedUser, err := s.engine.client.Users.Update(ctx, payload) if err != nil { log.Printf("Could not update password on server due to err: %s", err) return nil, err } s.engine.session.SetIdentity(apitypes.UserSession, updatedUser, updatedUser) return updatedUser, nil }
go
func (s *Session) UpdateProfile(ctx context.Context, newEmail, newName, newPassword string) (envelope.UserInf, error) { if s.engine.session.Type() != apitypes.UserSession { return nil, &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{"You must be a logged in user to change your password!"}, } } // Convert the auth portion of the session to a UserInf interface // Note: the auth and identity sections for a user are the same user, ok := s.engine.session.Self().Auth.(envelope.UserInf) if !ok { log.Printf("Could not convert to UserInf during update profile") return nil, &apitypes.Error{ Type: apitypes.InternalServerError, Err: []string{"Could not convert to user interface"}, } } if user.StructVersion() != 2 { return nil, &apitypes.Error{ Type: apitypes.BadRequestError, Err: []string{fmt.Sprintf( "User schema must be v2 to perform password change: %d", user.StructVersion()), }, } } payload := &updateProfile{} if newEmail != "" { payload.Email = newEmail } if newName != "" { payload.Name = newName } if newPassword != "" { pw, master, keypair, err := s.engine.crypto.ChangePassword(ctx, newPassword) if err != nil { log.Printf("Could not re-encrypt master key: %s", err) return nil, &apitypes.Error{ Type: apitypes.InternalServerError, Err: []string{"Could not re-encrypt master key"}, } } payload.Password = pw payload.Master = master payload.PublicKey = keypair } updatedUser, err := s.engine.client.Users.Update(ctx, payload) if err != nil { log.Printf("Could not update password on server due to err: %s", err) return nil, err } s.engine.session.SetIdentity(apitypes.UserSession, updatedUser, updatedUser) return updatedUser, nil }
[ "func", "(", "s", "*", "Session", ")", "UpdateProfile", "(", "ctx", "context", ".", "Context", ",", "newEmail", ",", "newName", ",", "newPassword", "string", ")", "(", "envelope", ".", "UserInf", ",", "error", ")", "{", "if", "s", ".", "engine", ".", ...
// UpdateProfile attempts to update the root password used by a user to log // into Torus which also allows them to access their stored and encrypted // secrets.
[ "UpdateProfile", "attempts", "to", "update", "the", "root", "password", "used", "by", "a", "user", "to", "log", "into", "Torus", "which", "also", "allows", "them", "to", "access", "their", "stored", "and", "encrypted", "secrets", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/session.go#L108-L169
1,607
manifoldco/torus-cli
daemon/logic/session.go
Logout
func (s *Session) Logout(ctx context.Context) error { if !s.engine.session.HasToken() { return &apitypes.Error{ Type: apitypes.UnauthorizedError, Err: []string{"You must be logged in, to logout!"}, } } tok := s.engine.session.Token() err := s.engine.client.Tokens.Delete(ctx, string(tok[:])) switch err := err.(type) { case *apitypes.Error: switch err.Type { case apitypes.InternalServerError: // On a 5XX response, we don't know for sure that the server // has successfully removed the auth token. Keep the copy in // the daemon, so the user may try again. return err case apitypes.NotFoundError, apitypes.BadRequestError, apitypes.UnauthorizedError: // A 4XX error indicates either the token isn't found, or we're // not allowed to remove it (or the server is a teapot). // // In any case, the daemon has gotten out of sync with the // server. Remove our local copy of the auth token. log.Printf("Got 4XX removing auth token. Treating as success") logoutErr := s.engine.session.Logout() if logoutErr != nil { return logoutErr } return nil } case nil: logoutErr := s.engine.session.Logout() if logoutErr != nil { return logoutErr } return nil default: return err } return nil }
go
func (s *Session) Logout(ctx context.Context) error { if !s.engine.session.HasToken() { return &apitypes.Error{ Type: apitypes.UnauthorizedError, Err: []string{"You must be logged in, to logout!"}, } } tok := s.engine.session.Token() err := s.engine.client.Tokens.Delete(ctx, string(tok[:])) switch err := err.(type) { case *apitypes.Error: switch err.Type { case apitypes.InternalServerError: // On a 5XX response, we don't know for sure that the server // has successfully removed the auth token. Keep the copy in // the daemon, so the user may try again. return err case apitypes.NotFoundError, apitypes.BadRequestError, apitypes.UnauthorizedError: // A 4XX error indicates either the token isn't found, or we're // not allowed to remove it (or the server is a teapot). // // In any case, the daemon has gotten out of sync with the // server. Remove our local copy of the auth token. log.Printf("Got 4XX removing auth token. Treating as success") logoutErr := s.engine.session.Logout() if logoutErr != nil { return logoutErr } return nil } case nil: logoutErr := s.engine.session.Logout() if logoutErr != nil { return logoutErr } return nil default: return err } return nil }
[ "func", "(", "s", "*", "Session", ")", "Logout", "(", "ctx", "context", ".", "Context", ")", "error", "{", "if", "!", "s", ".", "engine", ".", "session", ".", "HasToken", "(", ")", "{", "return", "&", "apitypes", ".", "Error", "{", "Type", ":", "...
// Logout destroys the current session if it exists, otherwise, it returns an // error that the request could not be completed.
[ "Logout", "destroys", "the", "current", "session", "if", "it", "exists", "otherwise", "it", "returns", "an", "error", "that", "the", "request", "could", "not", "be", "completed", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/session.go#L208-L254
1,608
manifoldco/torus-cli
registry/memberships.go
Create
func (m *MembershipsClient) Create(ctx context.Context, userID, orgID, teamID *identity.ID) error { if orgID == nil { return errors.New("invalid org") } if userID == nil { return errors.New("invalid user") } if teamID == nil { return errors.New("invalid team") } membershipBody := primitive.Membership{ OwnerID: userID, OrgID: orgID, TeamID: teamID, } ID, err := identity.NewMutable(&membershipBody) if err != nil { return err } membership := envelope.Membership{ ID: &ID, Version: 1, Body: &membershipBody, } return m.client.RoundTrip(ctx, "POST", "/memberships", nil, &membership, nil) }
go
func (m *MembershipsClient) Create(ctx context.Context, userID, orgID, teamID *identity.ID) error { if orgID == nil { return errors.New("invalid org") } if userID == nil { return errors.New("invalid user") } if teamID == nil { return errors.New("invalid team") } membershipBody := primitive.Membership{ OwnerID: userID, OrgID: orgID, TeamID: teamID, } ID, err := identity.NewMutable(&membershipBody) if err != nil { return err } membership := envelope.Membership{ ID: &ID, Version: 1, Body: &membershipBody, } return m.client.RoundTrip(ctx, "POST", "/memberships", nil, &membership, nil) }
[ "func", "(", "m", "*", "MembershipsClient", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "userID", ",", "orgID", ",", "teamID", "*", "identity", ".", "ID", ")", "error", "{", "if", "orgID", "==", "nil", "{", "return", "errors", ".", "Ne...
// Create requests addition of a user to a team
[ "Create", "requests", "addition", "of", "a", "user", "to", "a", "team" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/memberships.go#L41-L70
1,609
manifoldco/torus-cli
registry/memberships.go
Delete
func (m *MembershipsClient) Delete(ctx context.Context, membership *identity.ID) error { return m.client.RoundTrip(ctx, "DELETE", "/memberships/"+membership.String(), nil, nil, nil) }
go
func (m *MembershipsClient) Delete(ctx context.Context, membership *identity.ID) error { return m.client.RoundTrip(ctx, "DELETE", "/memberships/"+membership.String(), nil, nil, nil) }
[ "func", "(", "m", "*", "MembershipsClient", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "membership", "*", "identity", ".", "ID", ")", "error", "{", "return", "m", ".", "client", ".", "RoundTrip", "(", "ctx", ",", "\"", "\"", ",", "\""...
// Delete requests deletion of a specific membership row by ID
[ "Delete", "requests", "deletion", "of", "a", "specific", "membership", "row", "by", "ID" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/memberships.go#L73-L75
1,610
manifoldco/torus-cli
registry/self.go
Get
func (s *SelfClient) Get(ctx context.Context, token string) (*apitypes.Self, error) { raw := &rawSelf{} err := tokenRoundTrip(ctx, s.client, token, "GET", "/self", nil, nil, raw) if err != nil { return nil, err } self := raw.Self switch raw.Type { case apitypes.UserSession: user, err := envelope.ConvertUser(raw.Identity) if err != nil { return nil, err } self.Identity = user self.Auth = user case apitypes.MachineSession: self.Identity = &envelope.Machine{ ID: raw.Identity.ID, Version: raw.Identity.Version, Body: raw.Identity.Body.(*primitive.Machine), } self.Auth = &envelope.MachineToken{ ID: raw.Auth.ID, Version: raw.Auth.Version, Body: raw.Auth.Body.(*primitive.MachineToken), } default: return nil, errUnknownSessionType } return self, nil }
go
func (s *SelfClient) Get(ctx context.Context, token string) (*apitypes.Self, error) { raw := &rawSelf{} err := tokenRoundTrip(ctx, s.client, token, "GET", "/self", nil, nil, raw) if err != nil { return nil, err } self := raw.Self switch raw.Type { case apitypes.UserSession: user, err := envelope.ConvertUser(raw.Identity) if err != nil { return nil, err } self.Identity = user self.Auth = user case apitypes.MachineSession: self.Identity = &envelope.Machine{ ID: raw.Identity.ID, Version: raw.Identity.Version, Body: raw.Identity.Body.(*primitive.Machine), } self.Auth = &envelope.MachineToken{ ID: raw.Auth.ID, Version: raw.Auth.Version, Body: raw.Auth.Body.(*primitive.MachineToken), } default: return nil, errUnknownSessionType } return self, nil }
[ "func", "(", "s", "*", "SelfClient", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "token", "string", ")", "(", "*", "apitypes", ".", "Self", ",", "error", ")", "{", "raw", ":=", "&", "rawSelf", "{", "}", "\n", "err", ":=", "tokenRoundTri...
// Get returns the current identities associated with this token
[ "Get", "returns", "the", "current", "identities", "associated", "with", "this", "token" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/self.go#L28-L61
1,611
manifoldco/torus-cli
cmd/cmd.go
NewAPIClient
func NewAPIClient(ctx *context.Context, client *api.Client) (context.Context, *api.Client, error) { if client == nil { cfg, err := config.LoadConfig() if err != nil { return nil, nil, err } client = api.NewClient(cfg) } var c context.Context if ctx == nil { c = context.Background() } else { c = *ctx } return c, client, nil }
go
func NewAPIClient(ctx *context.Context, client *api.Client) (context.Context, *api.Client, error) { if client == nil { cfg, err := config.LoadConfig() if err != nil { return nil, nil, err } client = api.NewClient(cfg) } var c context.Context if ctx == nil { c = context.Background() } else { c = *ctx } return c, client, nil }
[ "func", "NewAPIClient", "(", "ctx", "*", "context", ".", "Context", ",", "client", "*", "api", ".", "Client", ")", "(", "context", ".", "Context", ",", "*", "api", ".", "Client", ",", "error", ")", "{", "if", "client", "==", "nil", "{", "cfg", ",",...
// NewAPIClient loads config and creates a new api client
[ "NewAPIClient", "loads", "config", "and", "creates", "a", "new", "api", "client" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/cmd.go#L28-L43
1,612
manifoldco/torus-cli
api/updates.go
Check
func (c *UpdatesClient) Check(ctx context.Context) (*apitypes.UpdateInfo, error) { var needsUpdate apitypes.UpdateInfo err := c.client.DaemonRoundTrip(ctx, "GET", "/updates", nil, nil, &needsUpdate, nil) return &needsUpdate, err }
go
func (c *UpdatesClient) Check(ctx context.Context) (*apitypes.UpdateInfo, error) { var needsUpdate apitypes.UpdateInfo err := c.client.DaemonRoundTrip(ctx, "GET", "/updates", nil, nil, &needsUpdate, nil) return &needsUpdate, err }
[ "func", "(", "c", "*", "UpdatesClient", ")", "Check", "(", "ctx", "context", ".", "Context", ")", "(", "*", "apitypes", ".", "UpdateInfo", ",", "error", ")", "{", "var", "needsUpdate", "apitypes", ".", "UpdateInfo", "\n", "err", ":=", "c", ".", "client...
// Check returns the latest updates check result, useful for detecting whether // a newer version of Torus is available for download.
[ "Check", "returns", "the", "latest", "updates", "check", "result", "useful", "for", "detecting", "whether", "a", "newer", "version", "of", "Torus", "is", "available", "for", "download", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/updates.go#L17-L21
1,613
manifoldco/torus-cli
daemon/crypto/engine.go
Unseal
func (e *Engine) Unseal(ctx context.Context, ct, nonce []byte) (*secure.Secret, error) { mk, err := e.unsealMasterKey(ctx) defer mk.Destroy() if err != nil { return nil, err } dk, err := deriveKey(ctx, mk.Buffer(), nonce, blakeSize) if err != nil { return nil, err } ts, err := newTriplesec(ctx, dk) if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } b, err := ts.Decrypt(ct) if err != nil { return nil, err } return e.guard.Secret(b) }
go
func (e *Engine) Unseal(ctx context.Context, ct, nonce []byte) (*secure.Secret, error) { mk, err := e.unsealMasterKey(ctx) defer mk.Destroy() if err != nil { return nil, err } dk, err := deriveKey(ctx, mk.Buffer(), nonce, blakeSize) if err != nil { return nil, err } ts, err := newTriplesec(ctx, dk) if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } b, err := ts.Decrypt(ct) if err != nil { return nil, err } return e.guard.Secret(b) }
[ "func", "(", "e", "*", "Engine", ")", "Unseal", "(", "ctx", "context", ".", "Context", ",", "ct", ",", "nonce", "[", "]", "byte", ")", "(", "*", "secure", ".", "Secret", ",", "error", ")", "{", "mk", ",", "err", ":=", "e", ".", "unsealMasterKey",...
// Unseal decrypts the ciphertext ct, encrypted with triplesec-v3, using the // a key derived via blake2b from the user's master key and the provided nonce.
[ "Unseal", "decrypts", "the", "ciphertext", "ct", "encrypted", "with", "triplesec", "-", "v3", "using", "the", "a", "key", "derived", "via", "blake2b", "from", "the", "user", "s", "master", "key", "and", "the", "provided", "nonce", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L118-L146
1,614
manifoldco/torus-cli
daemon/crypto/engine.go
Box
func (e *Engine) Box(ctx context.Context, pt *secure.Secret, privKP *EncryptionKeyPair, pubKey []byte) ([]byte, []byte, error) { err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, nil, err } nonce := [24]byte{} _, err = rand.Read(nonce[:]) if err != nil { return nil, nil, err } privKey, err := e.Unseal(ctx, privKP.Private, privKP.PNonce) if err != nil { return nil, nil, err } defer privKey.Destroy() // Get a pointer to the underlying private key in memory privkb := (*[32]byte)(unsafe.Pointer(&privKey.Buffer()[0])) pubkb := [32]byte{} copy(pubkb[:], pubKey) err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, nil, err } return box.Seal([]byte{}, pt.Buffer(), &nonce, &pubkb, privkb), nonce[:], nil }
go
func (e *Engine) Box(ctx context.Context, pt *secure.Secret, privKP *EncryptionKeyPair, pubKey []byte) ([]byte, []byte, error) { err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, nil, err } nonce := [24]byte{} _, err = rand.Read(nonce[:]) if err != nil { return nil, nil, err } privKey, err := e.Unseal(ctx, privKP.Private, privKP.PNonce) if err != nil { return nil, nil, err } defer privKey.Destroy() // Get a pointer to the underlying private key in memory privkb := (*[32]byte)(unsafe.Pointer(&privKey.Buffer()[0])) pubkb := [32]byte{} copy(pubkb[:], pubKey) err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, nil, err } return box.Seal([]byte{}, pt.Buffer(), &nonce, &pubkb, privkb), nonce[:], nil }
[ "func", "(", "e", "*", "Engine", ")", "Box", "(", "ctx", "context", ".", "Context", ",", "pt", "*", "secure", ".", "Secret", ",", "privKP", "*", "EncryptionKeyPair", ",", "pubKey", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "[", "]", "byt...
// Box encrypts the plaintext pt bytes with Box, using the private key found in // privKP, first decrypted with the user's master key, and encrypted for the // public key pubKey. // // It returns the ciphertext, the nonce used for encrypting the plaintext, // and an optional error.
[ "Box", "encrypts", "the", "plaintext", "pt", "bytes", "with", "Box", "using", "the", "private", "key", "found", "in", "privKP", "first", "decrypted", "with", "the", "user", "s", "master", "key", "and", "encrypted", "for", "the", "public", "key", "pubKey", ...
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L154-L186
1,615
manifoldco/torus-cli
daemon/crypto/engine.go
Unbox
func (e *Engine) Unbox(ctx context.Context, ct, nonce []byte, privKP *EncryptionKeyPair, pubKey []byte) (*secure.Secret, error) { privKey, err := e.Unseal(ctx, privKP.Private, privKP.PNonce) if err != nil { return nil, err } defer privKey.Destroy() nonceb := [24]byte{} copy(nonceb[:], nonce) // Get a pointer to the underlying private key in memory privkb := (*[32]byte)(unsafe.Pointer(&privKey.Buffer()[0])) pubkb := [32]byte{} copy(pubkb[:], pubKey) err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pt, success := box.Open([]byte{}, ct, &nonceb, &pubkb, privkb) if !success { return nil, errors.New("Failed to decrypt ciphertext") } return e.guard.Secret(pt) }
go
func (e *Engine) Unbox(ctx context.Context, ct, nonce []byte, privKP *EncryptionKeyPair, pubKey []byte) (*secure.Secret, error) { privKey, err := e.Unseal(ctx, privKP.Private, privKP.PNonce) if err != nil { return nil, err } defer privKey.Destroy() nonceb := [24]byte{} copy(nonceb[:], nonce) // Get a pointer to the underlying private key in memory privkb := (*[32]byte)(unsafe.Pointer(&privKey.Buffer()[0])) pubkb := [32]byte{} copy(pubkb[:], pubKey) err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pt, success := box.Open([]byte{}, ct, &nonceb, &pubkb, privkb) if !success { return nil, errors.New("Failed to decrypt ciphertext") } return e.guard.Secret(pt) }
[ "func", "(", "e", "*", "Engine", ")", "Unbox", "(", "ctx", "context", ".", "Context", ",", "ct", ",", "nonce", "[", "]", "byte", ",", "privKP", "*", "EncryptionKeyPair", ",", "pubKey", "[", "]", "byte", ")", "(", "*", "secure", ".", "Secret", ",", ...
// Unbox Decrypts and verifies ciphertext ct that was previously encrypted using // the provided nonce, and the inverse parts of the provided keypairs.
[ "Unbox", "Decrypts", "and", "verifies", "ciphertext", "ct", "that", "was", "previously", "encrypted", "using", "the", "provided", "nonce", "and", "the", "inverse", "parts", "of", "the", "provided", "keypairs", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L190-L219
1,616
manifoldco/torus-cli
daemon/crypto/engine.go
UnboxCredential
func (e *Engine) UnboxCredential(ctx context.Context, ct, encMec, mecNonce, cekNonce, ctNonce []byte, privKP *EncryptionKeyPair, pubKey []byte) ([]byte, error) { mek, err := e.Unbox(ctx, encMec, mecNonce, privKP, pubKey) if err != nil { return nil, err } defer mek.Destroy() cek, err := deriveKey(ctx, mek.Buffer(), cekNonce, 32) if err != nil { return nil, err } cekb := [32]byte{} copy(cekb[:], cek) ctNonceb := [24]byte{} copy(ctNonceb[:], ctNonce) err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pt, success := secretbox.Open([]byte{}, ct, &ctNonceb, &cekb) if !success { return nil, errors.New("Failed to decrypt ciphertext") } return pt, nil }
go
func (e *Engine) UnboxCredential(ctx context.Context, ct, encMec, mecNonce, cekNonce, ctNonce []byte, privKP *EncryptionKeyPair, pubKey []byte) ([]byte, error) { mek, err := e.Unbox(ctx, encMec, mecNonce, privKP, pubKey) if err != nil { return nil, err } defer mek.Destroy() cek, err := deriveKey(ctx, mek.Buffer(), cekNonce, 32) if err != nil { return nil, err } cekb := [32]byte{} copy(cekb[:], cek) ctNonceb := [24]byte{} copy(ctNonceb[:], ctNonce) err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pt, success := secretbox.Open([]byte{}, ct, &ctNonceb, &cekb) if !success { return nil, errors.New("Failed to decrypt ciphertext") } return pt, nil }
[ "func", "(", "e", "*", "Engine", ")", "UnboxCredential", "(", "ctx", "context", ".", "Context", ",", "ct", ",", "encMec", ",", "mecNonce", ",", "cekNonce", ",", "ctNonce", "[", "]", "byte", ",", "privKP", "*", "EncryptionKeyPair", ",", "pubKey", "[", "...
// UnboxCredential does the inverse of BoxCredential to retrieve the plaintext // version of a credential.
[ "UnboxCredential", "does", "the", "inverse", "of", "BoxCredential", "to", "retrieve", "the", "plaintext", "version", "of", "a", "credential", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L278-L309
1,617
manifoldco/torus-cli
daemon/crypto/engine.go
WithUnboxer
func (u *unsealerImpl) WithUnboxer(ctx context.Context, encMec, mecNonce []byte, fn func(Unboxer) error) error { nonce := [24]byte{} copy(nonce[:], mecNonce) // Get a pointer to the private key buffer privkb := (*[32]byte)(unsafe.Pointer(&u.privkey.Buffer()[0])) pubkb := [32]byte{} copy(pubkb[:], u.pubkey) err := ctxutil.ErrIfDone(ctx) if err != nil { return err } mek, success := box.Open([]byte{}, encMec, &nonce, &pubkb, privkb) if !success { return errors.New("Failed to decrypt keyring") } s, err := u.engine.guard.Secret(mek) if err != nil { return err } defer s.Destroy() unboxer := unboxerImpl{mek: s} return fn(&unboxer) }
go
func (u *unsealerImpl) WithUnboxer(ctx context.Context, encMec, mecNonce []byte, fn func(Unboxer) error) error { nonce := [24]byte{} copy(nonce[:], mecNonce) // Get a pointer to the private key buffer privkb := (*[32]byte)(unsafe.Pointer(&u.privkey.Buffer()[0])) pubkb := [32]byte{} copy(pubkb[:], u.pubkey) err := ctxutil.ErrIfDone(ctx) if err != nil { return err } mek, success := box.Open([]byte{}, encMec, &nonce, &pubkb, privkb) if !success { return errors.New("Failed to decrypt keyring") } s, err := u.engine.guard.Secret(mek) if err != nil { return err } defer s.Destroy() unboxer := unboxerImpl{mek: s} return fn(&unboxer) }
[ "func", "(", "u", "*", "unsealerImpl", ")", "WithUnboxer", "(", "ctx", "context", ".", "Context", ",", "encMec", ",", "mecNonce", "[", "]", "byte", ",", "fn", "func", "(", "Unboxer", ")", "error", ")", "error", "{", "nonce", ":=", "[", "24", "]", "...
// WithUnboxer returns an Unboxer for unboxing credentials tied to the unsealed // keypairs.
[ "WithUnboxer", "returns", "an", "Unboxer", "for", "unboxing", "credentials", "tied", "to", "the", "unsealed", "keypairs", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L325-L354
1,618
manifoldco/torus-cli
daemon/crypto/engine.go
WithUnboxer
func (e *Engine) WithUnboxer(ctx context.Context, encMec, mecNonce []byte, privKP *EncryptionKeyPair, pubKey []byte, fn func(Unboxer) error) error { mek, err := e.Unbox(ctx, encMec, mecNonce, privKP, pubKey) if err != nil { return err } defer mek.Destroy() err = ctxutil.ErrIfDone(ctx) if err != nil { return err } u := unboxerImpl{mek: mek} return fn(&u) }
go
func (e *Engine) WithUnboxer(ctx context.Context, encMec, mecNonce []byte, privKP *EncryptionKeyPair, pubKey []byte, fn func(Unboxer) error) error { mek, err := e.Unbox(ctx, encMec, mecNonce, privKP, pubKey) if err != nil { return err } defer mek.Destroy() err = ctxutil.ErrIfDone(ctx) if err != nil { return err } u := unboxerImpl{mek: mek} return fn(&u) }
[ "func", "(", "e", "*", "Engine", ")", "WithUnboxer", "(", "ctx", "context", ".", "Context", ",", "encMec", ",", "mecNonce", "[", "]", "byte", ",", "privKP", "*", "EncryptionKeyPair", ",", "pubKey", "[", "]", "byte", ",", "fn", "func", "(", "Unboxer", ...
// WithUnboxer returns an Unboxer for unboxing credentials within the context // of the provided keypairs.
[ "WithUnboxer", "returns", "an", "Unboxer", "for", "unboxing", "credentials", "within", "the", "context", "of", "the", "provided", "keypairs", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L392-L408
1,619
manifoldco/torus-cli
daemon/crypto/engine.go
WithUnsealer
func (e *Engine) WithUnsealer(ctx context.Context, privKP *EncryptionKeyPair, pubKey []byte, fn func(Unsealer) error) error { privKey, err := e.Unseal(ctx, privKP.Private, privKP.PNonce) if err != nil { return err } defer privKey.Destroy() err = ctxutil.ErrIfDone(ctx) if err != nil { return err } u := unsealerImpl{privkey: privKey, pubkey: pubKey, engine: e} return fn(&u) }
go
func (e *Engine) WithUnsealer(ctx context.Context, privKP *EncryptionKeyPair, pubKey []byte, fn func(Unsealer) error) error { privKey, err := e.Unseal(ctx, privKP.Private, privKP.PNonce) if err != nil { return err } defer privKey.Destroy() err = ctxutil.ErrIfDone(ctx) if err != nil { return err } u := unsealerImpl{privkey: privKey, pubkey: pubKey, engine: e} return fn(&u) }
[ "func", "(", "e", "*", "Engine", ")", "WithUnsealer", "(", "ctx", "context", ".", "Context", ",", "privKP", "*", "EncryptionKeyPair", ",", "pubKey", "[", "]", "byte", ",", "fn", "func", "(", "Unsealer", ")", "error", ")", "error", "{", "privKey", ",", ...
// WithUnsealer returns an Unsealer to unseal keypairs which can // subsequentently perform crypto operations through the Unsealer interface.
[ "WithUnsealer", "returns", "an", "Unsealer", "to", "unseal", "keypairs", "which", "can", "subsequentently", "perform", "crypto", "operations", "through", "the", "Unsealer", "interface", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L412-L428
1,620
manifoldco/torus-cli
daemon/crypto/engine.go
CloneMembership
func (e *Engine) CloneMembership(ctx context.Context, encMec, mecNonce []byte, privKP *EncryptionKeyPair, encPubKey, targetPubKey []byte) ([]byte, []byte, error) { mek, err := e.Unbox(ctx, encMec, mecNonce, privKP, encPubKey) if err != nil { return nil, nil, err } defer mek.Destroy() return e.Box(ctx, mek, privKP, targetPubKey) }
go
func (e *Engine) CloneMembership(ctx context.Context, encMec, mecNonce []byte, privKP *EncryptionKeyPair, encPubKey, targetPubKey []byte) ([]byte, []byte, error) { mek, err := e.Unbox(ctx, encMec, mecNonce, privKP, encPubKey) if err != nil { return nil, nil, err } defer mek.Destroy() return e.Box(ctx, mek, privKP, targetPubKey) }
[ "func", "(", "e", "*", "Engine", ")", "CloneMembership", "(", "ctx", "context", ".", "Context", ",", "encMec", ",", "mecNonce", "[", "]", "byte", ",", "privKP", "*", "EncryptionKeyPair", ",", "encPubKey", ",", "targetPubKey", "[", "]", "byte", ")", "(", ...
// CloneMembership decrypts the given KeyringMember object, and creates another // for the targeted user.
[ "CloneMembership", "decrypts", "the", "given", "KeyringMember", "object", "and", "creates", "another", "for", "the", "targeted", "user", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L432-L440
1,621
manifoldco/torus-cli
daemon/crypto/engine.go
GenerateKeyPairs
func (e *Engine) GenerateKeyPairs(ctx context.Context) (*KeyPairs, error) { kp := &KeyPairs{} err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pubSig, privSig, err := ed25519.GenerateKey(rand.Reader) if err != nil { return nil, err } sealedSig, nonceSig, err := e.Seal(ctx, privSig) if err != nil { return nil, err } kp.Signature.Private = sealedSig kp.Signature.Public = pubSig kp.Signature.PNonce = nonceSig err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pubEnc, privEnc, err := box.GenerateKey(rand.Reader) if err != nil { return nil, err } sealedEnc, nonceEnc, err := e.Seal(ctx, (*privEnc)[:]) if err != nil { return nil, err } kp.Encryption.Private = sealedEnc kp.Encryption.Public = *pubEnc kp.Encryption.PNonce = nonceEnc return kp, nil }
go
func (e *Engine) GenerateKeyPairs(ctx context.Context) (*KeyPairs, error) { kp := &KeyPairs{} err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pubSig, privSig, err := ed25519.GenerateKey(rand.Reader) if err != nil { return nil, err } sealedSig, nonceSig, err := e.Seal(ctx, privSig) if err != nil { return nil, err } kp.Signature.Private = sealedSig kp.Signature.Public = pubSig kp.Signature.PNonce = nonceSig err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } pubEnc, privEnc, err := box.GenerateKey(rand.Reader) if err != nil { return nil, err } sealedEnc, nonceEnc, err := e.Seal(ctx, (*privEnc)[:]) if err != nil { return nil, err } kp.Encryption.Private = sealedEnc kp.Encryption.Public = *pubEnc kp.Encryption.PNonce = nonceEnc return kp, nil }
[ "func", "(", "e", "*", "Engine", ")", "GenerateKeyPairs", "(", "ctx", "context", ".", "Context", ")", "(", "*", "KeyPairs", ",", "error", ")", "{", "kp", ":=", "&", "KeyPairs", "{", "}", "\n\n", "err", ":=", "ctxutil", ".", "ErrIfDone", "(", "ctx", ...
// GenerateKeyPairs generates and ed25519 signing key pair, and a curve25519 // encryption key pair for the user, encrypting the private keys in // triplesec-v3 with the user's master key.
[ "GenerateKeyPairs", "generates", "and", "ed25519", "signing", "key", "pair", "and", "a", "curve25519", "encryption", "key", "pair", "for", "the", "user", "encrypting", "the", "private", "keys", "in", "triplesec", "-", "v3", "with", "the", "user", "s", "master"...
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L445-L487
1,622
manifoldco/torus-cli
daemon/crypto/engine.go
Sign
func (e *Engine) Sign(ctx context.Context, s SignatureKeyPair, b []byte) ([]byte, error) { pk, err := e.Unseal(ctx, s.Private, s.PNonce) if err != nil { return nil, err } defer pk.Destroy() err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } return ed25519.Sign(pk.Buffer(), b), nil }
go
func (e *Engine) Sign(ctx context.Context, s SignatureKeyPair, b []byte) ([]byte, error) { pk, err := e.Unseal(ctx, s.Private, s.PNonce) if err != nil { return nil, err } defer pk.Destroy() err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } return ed25519.Sign(pk.Buffer(), b), nil }
[ "func", "(", "e", "*", "Engine", ")", "Sign", "(", "ctx", "context", ".", "Context", ",", "s", "SignatureKeyPair", ",", "b", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "pk", ",", "err", ":=", "e", ".", "Unseal", "(", ...
// Sign signs b bytes using the provided Sealed ed25519 keypair.
[ "Sign", "signs", "b", "bytes", "using", "the", "provided", "Sealed", "ed25519", "keypair", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L490-L503
1,623
manifoldco/torus-cli
daemon/crypto/engine.go
Verify
func (e *Engine) Verify(ctx context.Context, s SignatureKeyPair, b, sig []byte) (bool, error) { err := ctxutil.ErrIfDone(ctx) if err != nil { return false, err } return ed25519.Verify(s.Public, b, sig), nil }
go
func (e *Engine) Verify(ctx context.Context, s SignatureKeyPair, b, sig []byte) (bool, error) { err := ctxutil.ErrIfDone(ctx) if err != nil { return false, err } return ed25519.Verify(s.Public, b, sig), nil }
[ "func", "(", "e", "*", "Engine", ")", "Verify", "(", "ctx", "context", ".", "Context", ",", "s", "SignatureKeyPair", ",", "b", ",", "sig", "[", "]", "byte", ")", "(", "bool", ",", "error", ")", "{", "err", ":=", "ctxutil", ".", "ErrIfDone", "(", ...
// Verify verifies that sig is the correct signature for b given // SignatureKeyPair s.
[ "Verify", "verifies", "that", "sig", "is", "the", "correct", "signature", "for", "b", "given", "SignatureKeyPair", "s", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L507-L514
1,624
manifoldco/torus-cli
daemon/crypto/engine.go
unsealMasterKey
func (e *Engine) unsealMasterKey(ctx context.Context) (*secure.Secret, error) { if !e.sess.HasPassphrase() { return nil, ErrMissingPassphrase } ts, err := newTriplesec(ctx, e.sess.Passphrase()) if err != nil { return nil, err } masterKey, err := e.sess.MasterKey() if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } mk, err := ts.Decrypt(*masterKey) if err != nil { return nil, err } return e.guard.Secret(mk) }
go
func (e *Engine) unsealMasterKey(ctx context.Context) (*secure.Secret, error) { if !e.sess.HasPassphrase() { return nil, ErrMissingPassphrase } ts, err := newTriplesec(ctx, e.sess.Passphrase()) if err != nil { return nil, err } masterKey, err := e.sess.MasterKey() if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } mk, err := ts.Decrypt(*masterKey) if err != nil { return nil, err } return e.guard.Secret(mk) }
[ "func", "(", "e", "*", "Engine", ")", "unsealMasterKey", "(", "ctx", "context", ".", "Context", ")", "(", "*", "secure", ".", "Secret", ",", "error", ")", "{", "if", "!", "e", ".", "sess", ".", "HasPassphrase", "(", ")", "{", "return", "nil", ",", ...
// unsealMasterKey uses the scrypt stretched password to decrypt the master // password, which is encrypted with triplesec-v3
[ "unsealMasterKey", "uses", "the", "scrypt", "stretched", "password", "to", "decrypt", "the", "master", "password", "which", "is", "encrypted", "with", "triplesec", "-", "v3" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L550-L575
1,625
manifoldco/torus-cli
daemon/crypto/engine.go
ChangePassword
func (e *Engine) ChangePassword(ctx context.Context, newPassword string) (*primitive.UserPassword, *primitive.MasterKey, *primitive.LoginPublicKey, error) { // We need to re-use the master key cmk, err := e.unsealMasterKey(ctx) defer cmk.Destroy() if err != nil { return nil, nil, nil, err } // Encrypt the new password and re-encrypt the original master key b := cmk.Buffer() pw, master, err := EncryptPasswordObject(ctx, newPassword, &b) if err != nil { return nil, nil, nil, err } // Now derive LoginKeypair s, err := base64.NewFromString(pw.Salt) if err != nil { return nil, nil, nil, err } keypair, err := DeriveLoginKeypair(ctx, []byte(newPassword), s) if err != nil { return nil, nil, nil, err } return pw, master, &primitive.LoginPublicKey{ Salt: keypair.Salt(), Value: keypair.PublicKey(), Alg: EdDSA, }, nil }
go
func (e *Engine) ChangePassword(ctx context.Context, newPassword string) (*primitive.UserPassword, *primitive.MasterKey, *primitive.LoginPublicKey, error) { // We need to re-use the master key cmk, err := e.unsealMasterKey(ctx) defer cmk.Destroy() if err != nil { return nil, nil, nil, err } // Encrypt the new password and re-encrypt the original master key b := cmk.Buffer() pw, master, err := EncryptPasswordObject(ctx, newPassword, &b) if err != nil { return nil, nil, nil, err } // Now derive LoginKeypair s, err := base64.NewFromString(pw.Salt) if err != nil { return nil, nil, nil, err } keypair, err := DeriveLoginKeypair(ctx, []byte(newPassword), s) if err != nil { return nil, nil, nil, err } return pw, master, &primitive.LoginPublicKey{ Salt: keypair.Salt(), Value: keypair.PublicKey(), Alg: EdDSA, }, nil }
[ "func", "(", "e", "*", "Engine", ")", "ChangePassword", "(", "ctx", "context", ".", "Context", ",", "newPassword", "string", ")", "(", "*", "primitive", ".", "UserPassword", ",", "*", "primitive", ".", "MasterKey", ",", "*", "primitive", ".", "LoginPublicK...
// ChangePassword creates a password object and re-encrypts the master key
[ "ChangePassword", "creates", "a", "password", "object", "and", "re", "-", "encrypts", "the", "master", "key" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L592-L623
1,626
manifoldco/torus-cli
daemon/crypto/engine.go
deriveKey
func deriveKey(ctx context.Context, mk, nonce []byte, size uint8) ([]byte, error) { err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } h := blake2b.NewMAC(size, nonce) // NewMAC can panic if size is too big. h.Sum(mk) return h.Sum(nil), nil }
go
func deriveKey(ctx context.Context, mk, nonce []byte, size uint8) ([]byte, error) { err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } h := blake2b.NewMAC(size, nonce) // NewMAC can panic if size is too big. h.Sum(mk) return h.Sum(nil), nil }
[ "func", "deriveKey", "(", "ctx", "context", ".", "Context", ",", "mk", ",", "nonce", "[", "]", "byte", ",", "size", "uint8", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "err", ":=", "ctxutil", ".", "ErrIfDone", "(", "ctx", ")", "\n", "if"...
// deriveKey Derives a single use key from the given master key via blake2b // and a nonce.
[ "deriveKey", "Derives", "a", "single", "use", "key", "from", "the", "given", "master", "key", "via", "blake2b", "and", "a", "nonce", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/engine.go#L627-L636
1,627
manifoldco/torus-cli
daemon/daemon.go
New
func New(cfg *config.Config, groupShared bool) (*Daemon, error) { lock, err := lockfile.New(cfg.PidPath) if err != nil { return nil, fmt.Errorf("Failed to create lockfile object: %s", err) } err = lock.TryLock() if err != nil { return nil, fmt.Errorf( "Failed to create lockfile[%s]: %s", cfg.PidPath, err) } // Recover from the panic and return the error; this way we can // delete the lockfile! defer func() { if r := recover(); r != nil { err, _ = r.(error) } }() if groupShared { if err = os.Chmod(string(lock), 0640); err != nil { return nil, err } } db, err := db.NewDB(cfg.DBPath) if err != nil { return nil, err } guard := secure.NewGuard() session := session.NewSession(guard) cryptoEngine := crypto.NewEngine(session, guard) transport := utils.CreateHTTPTransport(cfg.CABundle, strings.Split(cfg.RegistryURI.Host, ":")[0]) client := registry.NewClient(cfg.RegistryURI.String(), cfg.APIVersion, cfg.Version, session, transport) logic := logic.NewEngine(session, db, cryptoEngine, client, guard) mTransport := utils.CreateHTTPTransport(cfg.CABundle, strings.Split(cfg.ManifestURI.Host, ":")[0]) updates := updates.NewEngine(cfg, mTransport) proxy, err := socket.NewAuthProxy(cfg, session, db, transport, client, logic, updates, groupShared) if err != nil { return nil, fmt.Errorf("Failed to create auth proxy: %s", err) } daemon := &Daemon{ proxy: proxy, lock: lock, session: session, config: cfg, db: db, logic: logic, hasShutdown: false, updates: updates, } return daemon, nil }
go
func New(cfg *config.Config, groupShared bool) (*Daemon, error) { lock, err := lockfile.New(cfg.PidPath) if err != nil { return nil, fmt.Errorf("Failed to create lockfile object: %s", err) } err = lock.TryLock() if err != nil { return nil, fmt.Errorf( "Failed to create lockfile[%s]: %s", cfg.PidPath, err) } // Recover from the panic and return the error; this way we can // delete the lockfile! defer func() { if r := recover(); r != nil { err, _ = r.(error) } }() if groupShared { if err = os.Chmod(string(lock), 0640); err != nil { return nil, err } } db, err := db.NewDB(cfg.DBPath) if err != nil { return nil, err } guard := secure.NewGuard() session := session.NewSession(guard) cryptoEngine := crypto.NewEngine(session, guard) transport := utils.CreateHTTPTransport(cfg.CABundle, strings.Split(cfg.RegistryURI.Host, ":")[0]) client := registry.NewClient(cfg.RegistryURI.String(), cfg.APIVersion, cfg.Version, session, transport) logic := logic.NewEngine(session, db, cryptoEngine, client, guard) mTransport := utils.CreateHTTPTransport(cfg.CABundle, strings.Split(cfg.ManifestURI.Host, ":")[0]) updates := updates.NewEngine(cfg, mTransport) proxy, err := socket.NewAuthProxy(cfg, session, db, transport, client, logic, updates, groupShared) if err != nil { return nil, fmt.Errorf("Failed to create auth proxy: %s", err) } daemon := &Daemon{ proxy: proxy, lock: lock, session: session, config: cfg, db: db, logic: logic, hasShutdown: false, updates: updates, } return daemon, nil }
[ "func", "New", "(", "cfg", "*", "config", ".", "Config", ",", "groupShared", "bool", ")", "(", "*", "Daemon", ",", "error", ")", "{", "lock", ",", "err", ":=", "lockfile", ".", "New", "(", "cfg", ".", "PidPath", ")", "\n", "if", "err", "!=", "nil...
// New creates a new Daemon.
[ "New", "creates", "a", "new", "Daemon", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/daemon.go#L43-L102
1,628
manifoldco/torus-cli
daemon/daemon.go
Run
func (d *Daemon) Run() error { email, hasEmail := os.LookupEnv("TORUS_EMAIL") password, hasPassword := os.LookupEnv("TORUS_PASSWORD") tokenID, hasTokenID := os.LookupEnv("TORUS_TOKEN_ID") tokenSecret, hasTokenSecret := os.LookupEnv("TORUS_TOKEN_SECRET") if hasEmail && hasPassword { log.Printf("Attempting to login as: %s", email) userLogin := &apitypes.UserLogin{ Email: email, Password: password, } err := d.logic.Session.Login(context.Background(), userLogin) if err != nil { return err } } if hasTokenID && hasTokenSecret { log.Printf("Attempting to login as machine token id: %s", tokenID) ID, err := identity.DecodeFromString(tokenID) if err != nil { log.Printf("Could not parse TORUS_TOKEN_ID") return err } secret, err := base64.NewFromString(tokenSecret) if err != nil { log.Printf("Could not parse TORUS_TOKEN_SECRET") return err } machineLogin := &apitypes.MachineLogin{ TokenID: &ID, Secret: secret, } err = d.logic.Session.Login(context.Background(), machineLogin) if err != nil { return err } } if err := d.updates.Start(); err != nil { log.Printf("cannot start updates checker: %s", err) } return d.proxy.Listen() }
go
func (d *Daemon) Run() error { email, hasEmail := os.LookupEnv("TORUS_EMAIL") password, hasPassword := os.LookupEnv("TORUS_PASSWORD") tokenID, hasTokenID := os.LookupEnv("TORUS_TOKEN_ID") tokenSecret, hasTokenSecret := os.LookupEnv("TORUS_TOKEN_SECRET") if hasEmail && hasPassword { log.Printf("Attempting to login as: %s", email) userLogin := &apitypes.UserLogin{ Email: email, Password: password, } err := d.logic.Session.Login(context.Background(), userLogin) if err != nil { return err } } if hasTokenID && hasTokenSecret { log.Printf("Attempting to login as machine token id: %s", tokenID) ID, err := identity.DecodeFromString(tokenID) if err != nil { log.Printf("Could not parse TORUS_TOKEN_ID") return err } secret, err := base64.NewFromString(tokenSecret) if err != nil { log.Printf("Could not parse TORUS_TOKEN_SECRET") return err } machineLogin := &apitypes.MachineLogin{ TokenID: &ID, Secret: secret, } err = d.logic.Session.Login(context.Background(), machineLogin) if err != nil { return err } } if err := d.updates.Start(); err != nil { log.Printf("cannot start updates checker: %s", err) } return d.proxy.Listen() }
[ "func", "(", "d", "*", "Daemon", ")", "Run", "(", ")", "error", "{", "email", ",", "hasEmail", ":=", "os", ".", "LookupEnv", "(", "\"", "\"", ")", "\n", "password", ",", "hasPassword", ":=", "os", ".", "LookupEnv", "(", "\"", "\"", ")", "\n", "to...
// Run starts the daemon main loop. It returns on failure, or when the daemon // has been gracefully shut down.
[ "Run", "starts", "the", "daemon", "main", "loop", ".", "It", "returns", "on", "failure", "or", "when", "the", "daemon", "has", "been", "gracefully", "shut", "down", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/daemon.go#L111-L161
1,629
manifoldco/torus-cli
daemon/daemon.go
Shutdown
func (d *Daemon) Shutdown() error { if d.hasShutdown { return nil } d.hasShutdown = true if err := d.lock.Unlock(); err != nil { return fmt.Errorf("Could not unlock: %s", err) } if err := d.proxy.Close(); err != nil { return fmt.Errorf("Could not stop http proxy: %s", err) } if err := d.db.Close(); err != nil { return fmt.Errorf("Could not close db: %s", err) } if err := d.updates.Stop(); err != nil { return fmt.Errorf("Could not stop update checker: %s", err) } return nil }
go
func (d *Daemon) Shutdown() error { if d.hasShutdown { return nil } d.hasShutdown = true if err := d.lock.Unlock(); err != nil { return fmt.Errorf("Could not unlock: %s", err) } if err := d.proxy.Close(); err != nil { return fmt.Errorf("Could not stop http proxy: %s", err) } if err := d.db.Close(); err != nil { return fmt.Errorf("Could not close db: %s", err) } if err := d.updates.Stop(); err != nil { return fmt.Errorf("Could not stop update checker: %s", err) } return nil }
[ "func", "(", "d", "*", "Daemon", ")", "Shutdown", "(", ")", "error", "{", "if", "d", ".", "hasShutdown", "{", "return", "nil", "\n", "}", "\n\n", "d", ".", "hasShutdown", "=", "true", "\n", "if", "err", ":=", "d", ".", "lock", ".", "Unlock", "(",...
// Shutdown gracefully shuts down the daemon.
[ "Shutdown", "gracefully", "shuts", "down", "the", "daemon", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/daemon.go#L164-L187
1,630
manifoldco/torus-cli
registry/keyring.go
FindMember
func (k *KeyringSectionV1) FindMember(id *identity.ID) (*primitive.KeyringMember, *primitive.MEKShare, error) { var krm *primitive.KeyringMember var mekshare *primitive.MEKShare for _, m := range k.Members { if *m.Body.OwnerID == *id { krm, mekshare = convertV1KRM(&m) break } } if krm == nil { return nil, nil, ErrMemberNotFound } return krm, mekshare, nil }
go
func (k *KeyringSectionV1) FindMember(id *identity.ID) (*primitive.KeyringMember, *primitive.MEKShare, error) { var krm *primitive.KeyringMember var mekshare *primitive.MEKShare for _, m := range k.Members { if *m.Body.OwnerID == *id { krm, mekshare = convertV1KRM(&m) break } } if krm == nil { return nil, nil, ErrMemberNotFound } return krm, mekshare, nil }
[ "func", "(", "k", "*", "KeyringSectionV1", ")", "FindMember", "(", "id", "*", "identity", ".", "ID", ")", "(", "*", "primitive", ".", "KeyringMember", ",", "*", "primitive", ".", "MEKShare", ",", "error", ")", "{", "var", "krm", "*", "primitive", ".", ...
// FindMember returns the membership and mekshare for the given user id. // The data is returned in V2 format.
[ "FindMember", "returns", "the", "membership", "and", "mekshare", "for", "the", "given", "user", "id", ".", "The", "data", "is", "returned", "in", "V2", "format", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/keyring.go#L54-L69
1,631
manifoldco/torus-cli
registry/keyring.go
FindMEKByKeyID
func (k *KeyringSectionV1) FindMEKByKeyID(id *identity.ID) (*primitive.MEKShare, error) { var mekshare *primitive.MEKShare for _, m := range k.Members { if *m.Body.EncryptingKeyID == *id { mekshare = &primitive.MEKShare{ Key: m.Body.Key, } break } } if mekshare == nil { return nil, ErrMemberNotFound } return mekshare, nil }
go
func (k *KeyringSectionV1) FindMEKByKeyID(id *identity.ID) (*primitive.MEKShare, error) { var mekshare *primitive.MEKShare for _, m := range k.Members { if *m.Body.EncryptingKeyID == *id { mekshare = &primitive.MEKShare{ Key: m.Body.Key, } break } } if mekshare == nil { return nil, ErrMemberNotFound } return mekshare, nil }
[ "func", "(", "k", "*", "KeyringSectionV1", ")", "FindMEKByKeyID", "(", "id", "*", "identity", ".", "ID", ")", "(", "*", "primitive", ".", "MEKShare", ",", "error", ")", "{", "var", "mekshare", "*", "primitive", ".", "MEKShare", "\n", "for", "_", ",", ...
// FindMEKByKeyID returns the MEKShare for the given encrypting key id. // // The data is returned in the V2 format.
[ "FindMEKByKeyID", "returns", "the", "MEKShare", "for", "the", "given", "encrypting", "key", "id", ".", "The", "data", "is", "returned", "in", "the", "V2", "format", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/keyring.go#L74-L90
1,632
manifoldco/torus-cli
registry/keyring.go
HasRevocations
func (k *KeyringSectionV2) HasRevocations() bool { for _, claim := range k.Claims { if claim.Body.ClaimType == primitive.RevocationClaimType { return true } } return false }
go
func (k *KeyringSectionV2) HasRevocations() bool { for _, claim := range k.Claims { if claim.Body.ClaimType == primitive.RevocationClaimType { return true } } return false }
[ "func", "(", "k", "*", "KeyringSectionV2", ")", "HasRevocations", "(", ")", "bool", "{", "for", "_", ",", "claim", ":=", "range", "k", ".", "Claims", "{", "if", "claim", ".", "Body", ".", "ClaimType", "==", "primitive", ".", "RevocationClaimType", "{", ...
// HasRevocations indicates that a Keyring holds revoked user keys.
[ "HasRevocations", "indicates", "that", "a", "Keyring", "holds", "revoked", "user", "keys", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/keyring.go#L213-L220
1,633
manifoldco/torus-cli
registry/keyring.go
List
func (k *KeyringClient) List(ctx context.Context, orgID *identity.ID, ownerID *identity.ID) ([]KeyringSection, error) { query := &url.Values{} if orgID != nil { query.Set("org_id", orgID.String()) } if ownerID != nil { query.Set("owner_id", ownerID.String()) } resp := []struct { Keyring *envelope.Signed `json:"keyring"` Members json.RawMessage `json:"members"` Claims []envelope.KeyringMemberClaim `json:"claims"` }{} err := k.client.RoundTrip(ctx, "GET", "/keyrings", query, nil, &resp) if err != nil { return nil, err } converted := make([]KeyringSection, len(resp)) for i, k := range resp { if k.Keyring.Version == 1 { kre := &envelope.KeyringV1{ ID: k.Keyring.ID, Version: k.Keyring.Version, Signature: k.Keyring.Signature, Body: k.Keyring.Body.(*primitive.KeyringV1), } s := KeyringSectionV1{ Keyring: kre, } err := json.Unmarshal(k.Members, &s.Members) if err != nil { return nil, err } converted[i] = &s } else { kre := &envelope.Keyring{ ID: k.Keyring.ID, Version: k.Keyring.Version, Signature: k.Keyring.Signature, Body: k.Keyring.Body.(*primitive.Keyring), } s := KeyringSectionV2{ Keyring: kre, Claims: k.Claims, } err := json.Unmarshal(k.Members, &s.Members) if err != nil { return nil, err } converted[i] = &s } } return converted, nil }
go
func (k *KeyringClient) List(ctx context.Context, orgID *identity.ID, ownerID *identity.ID) ([]KeyringSection, error) { query := &url.Values{} if orgID != nil { query.Set("org_id", orgID.String()) } if ownerID != nil { query.Set("owner_id", ownerID.String()) } resp := []struct { Keyring *envelope.Signed `json:"keyring"` Members json.RawMessage `json:"members"` Claims []envelope.KeyringMemberClaim `json:"claims"` }{} err := k.client.RoundTrip(ctx, "GET", "/keyrings", query, nil, &resp) if err != nil { return nil, err } converted := make([]KeyringSection, len(resp)) for i, k := range resp { if k.Keyring.Version == 1 { kre := &envelope.KeyringV1{ ID: k.Keyring.ID, Version: k.Keyring.Version, Signature: k.Keyring.Signature, Body: k.Keyring.Body.(*primitive.KeyringV1), } s := KeyringSectionV1{ Keyring: kre, } err := json.Unmarshal(k.Members, &s.Members) if err != nil { return nil, err } converted[i] = &s } else { kre := &envelope.Keyring{ ID: k.Keyring.ID, Version: k.Keyring.Version, Signature: k.Keyring.Signature, Body: k.Keyring.Body.(*primitive.Keyring), } s := KeyringSectionV2{ Keyring: kre, Claims: k.Claims, } err := json.Unmarshal(k.Members, &s.Members) if err != nil { return nil, err } converted[i] = &s } } return converted, nil }
[ "func", "(", "k", "*", "KeyringClient", ")", "List", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ",", "ownerID", "*", "identity", ".", "ID", ")", "(", "[", "]", "KeyringSection", ",", "error", ")", "{", "query", ...
// List retrieves an array of KeyringSections from the registry.
[ "List", "retrieves", "an", "array", "of", "KeyringSections", "from", "the", "registry", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/keyring.go#L235-L296
1,634
manifoldco/torus-cli
registry/teams.go
List
func (t *TeamsClient) List(ctx context.Context, orgID *identity.ID, name string, teamType primitive.TeamType) ([]envelope.Team, error) { v := &url.Values{} if orgID != nil { v.Set("org_id", orgID.String()) } if name != "" { v.Set("name", name) } if teamType != primitive.AnyTeamType { v.Set("type", string(teamType)) } var teams []envelope.Team err := t.client.RoundTrip(ctx, "GET", "/teams", v, nil, &teams) return teams, err }
go
func (t *TeamsClient) List(ctx context.Context, orgID *identity.ID, name string, teamType primitive.TeamType) ([]envelope.Team, error) { v := &url.Values{} if orgID != nil { v.Set("org_id", orgID.String()) } if name != "" { v.Set("name", name) } if teamType != primitive.AnyTeamType { v.Set("type", string(teamType)) } var teams []envelope.Team err := t.client.RoundTrip(ctx, "GET", "/teams", v, nil, &teams) return teams, err }
[ "func", "(", "t", "*", "TeamsClient", ")", "List", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ",", "name", "string", ",", "teamType", "primitive", ".", "TeamType", ")", "(", "[", "]", "envelope", ".", "Team", ","...
// List retrieves all teams for an org based on the filtered values
[ "List", "retrieves", "all", "teams", "for", "an", "org", "based", "on", "the", "filtered", "values" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/teams.go#L19-L35
1,635
manifoldco/torus-cli
registry/teams.go
GetByOrg
func (t *TeamsClient) GetByOrg(ctx context.Context, orgID *identity.ID) ([]envelope.Team, error) { return t.List(ctx, orgID, "", primitive.AnyTeamType) }
go
func (t *TeamsClient) GetByOrg(ctx context.Context, orgID *identity.ID) ([]envelope.Team, error) { return t.List(ctx, orgID, "", primitive.AnyTeamType) }
[ "func", "(", "t", "*", "TeamsClient", ")", "GetByOrg", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ")", "(", "[", "]", "envelope", ".", "Team", ",", "error", ")", "{", "return", "t", ".", "List", "(", "ctx", "...
// GetByOrg retrieves all teams for an org id
[ "GetByOrg", "retrieves", "all", "teams", "for", "an", "org", "id" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/teams.go#L38-L40
1,636
manifoldco/torus-cli
registry/teams.go
GetByName
func (t *TeamsClient) GetByName(ctx context.Context, orgID *identity.ID, name string) ([]envelope.Team, error) { return t.List(ctx, orgID, name, primitive.AnyTeamType) }
go
func (t *TeamsClient) GetByName(ctx context.Context, orgID *identity.ID, name string) ([]envelope.Team, error) { return t.List(ctx, orgID, name, primitive.AnyTeamType) }
[ "func", "(", "t", "*", "TeamsClient", ")", "GetByName", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ",", "name", "string", ")", "(", "[", "]", "envelope", ".", "Team", ",", "error", ")", "{", "return", "t", ".",...
// GetByName retrieves the team with the specified name
[ "GetByName", "retrieves", "the", "team", "with", "the", "specified", "name" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/teams.go#L43-L45
1,637
manifoldco/torus-cli
registry/teams.go
Create
func (t *TeamsClient) Create(ctx context.Context, orgID *identity.ID, name string, teamType primitive.TeamType) (*envelope.Team, error) { if orgID == nil { return nil, errors.New("invalid org") } teamBody := primitive.Team{ Name: name, OrgID: orgID, TeamType: teamType, } ID, err := identity.NewMutable(&teamBody) if err != nil { return nil, err } team := envelope.Team{ ID: &ID, Version: 1, Body: &teamBody, } result := &envelope.Team{} err = t.client.RoundTrip(ctx, "POST", "/teams", nil, &team, result) return result, err }
go
func (t *TeamsClient) Create(ctx context.Context, orgID *identity.ID, name string, teamType primitive.TeamType) (*envelope.Team, error) { if orgID == nil { return nil, errors.New("invalid org") } teamBody := primitive.Team{ Name: name, OrgID: orgID, TeamType: teamType, } ID, err := identity.NewMutable(&teamBody) if err != nil { return nil, err } team := envelope.Team{ ID: &ID, Version: 1, Body: &teamBody, } result := &envelope.Team{} err = t.client.RoundTrip(ctx, "POST", "/teams", nil, &team, result) return result, err }
[ "func", "(", "t", "*", "TeamsClient", ")", "Create", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ",", "name", "string", ",", "teamType", "primitive", ".", "TeamType", ")", "(", "*", "envelope", ".", "Team", ",", "...
// Create performs a request to create a new team object
[ "Create", "performs", "a", "request", "to", "create", "a", "new", "team", "object" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/teams.go#L48-L74
1,638
manifoldco/torus-cli
daemon/crypto/secure/secure.go
NewGuard
func NewGuard() *Guard { lock.Lock() defer lock.Unlock() if current != nil { return current } current = &Guard{ secrets: []*Secret{}, lock: &sync.Mutex{}, } return current }
go
func NewGuard() *Guard { lock.Lock() defer lock.Unlock() if current != nil { return current } current = &Guard{ secrets: []*Secret{}, lock: &sync.Mutex{}, } return current }
[ "func", "NewGuard", "(", ")", "*", "Guard", "{", "lock", ".", "Lock", "(", ")", "\n", "defer", "lock", ".", "Unlock", "(", ")", "\n\n", "if", "current", "!=", "nil", "{", "return", "current", "\n", "}", "\n\n", "current", "=", "&", "Guard", "{", ...
// NewGuard returns a Guard instance or errors if a guard already exists.
[ "NewGuard", "returns", "a", "Guard", "instance", "or", "errors", "if", "a", "guard", "already", "exists", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/secure/secure.go#L37-L51
1,639
manifoldco/torus-cli
daemon/crypto/secure/secure.go
Destroy
func (g *Guard) Destroy() { lock.Lock() defer lock.Unlock() for _, s := range g.secrets { s.Destroy() } current = nil }
go
func (g *Guard) Destroy() { lock.Lock() defer lock.Unlock() for _, s := range g.secrets { s.Destroy() } current = nil }
[ "func", "(", "g", "*", "Guard", ")", "Destroy", "(", ")", "{", "lock", ".", "Lock", "(", ")", "\n", "defer", "lock", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "s", ":=", "range", "g", ".", "secrets", "{", "s", ".", "Destroy", "(", ")"...
// Destroy removes all secrets and cleans up everything up appropriately.
[ "Destroy", "removes", "all", "secrets", "and", "cleans", "up", "everything", "up", "appropriately", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/secure/secure.go#L79-L88
1,640
manifoldco/torus-cli
daemon/crypto/secure/secure.go
Random
func (g *Guard) Random(size int) (*Secret, error) { g.lock.Lock() defer g.lock.Unlock() b, err := memguard.NewImmutableRandom(size) if err != nil { return nil, err } s := Secret{ buffer: b, guard: g, } g.secrets = append(g.secrets, &s) return &s, nil }
go
func (g *Guard) Random(size int) (*Secret, error) { g.lock.Lock() defer g.lock.Unlock() b, err := memguard.NewImmutableRandom(size) if err != nil { return nil, err } s := Secret{ buffer: b, guard: g, } g.secrets = append(g.secrets, &s) return &s, nil }
[ "func", "(", "g", "*", "Guard", ")", "Random", "(", "size", "int", ")", "(", "*", "Secret", ",", "error", ")", "{", "g", ".", "lock", ".", "Lock", "(", ")", "\n", "defer", "g", ".", "lock", ".", "Unlock", "(", ")", "\n\n", "b", ",", "err", ...
// Random returns a new secret of the given length in bytes.
[ "Random", "returns", "a", "new", "secret", "of", "the", "given", "length", "in", "bytes", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/secure/secure.go#L111-L127
1,641
manifoldco/torus-cli
daemon/crypto/secure/secure.go
Destroy
func (s *Secret) Destroy() { defer s.buffer.Destroy() s.guard.remove(s) }
go
func (s *Secret) Destroy() { defer s.buffer.Destroy() s.guard.remove(s) }
[ "func", "(", "s", "*", "Secret", ")", "Destroy", "(", ")", "{", "defer", "s", ".", "buffer", ".", "Destroy", "(", ")", "\n", "s", ".", "guard", ".", "remove", "(", "s", ")", "\n", "}" ]
// Destroy properly dispenses of the underlying secret stored in secure memory.
[ "Destroy", "properly", "dispenses", "of", "the", "underlying", "secret", "stored", "in", "secure", "memory", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/secure/secure.go#L135-L138
1,642
manifoldco/torus-cli
api/worklog.go
List
func (w *WorklogClient) List(ctx context.Context, orgID *identity.ID) ([]apitypes.WorklogItem, error) { v := &url.Values{} if orgID != nil { v.Set("org_id", orgID.String()) } var resp []rawWorklogItem err := w.client.DaemonRoundTrip(ctx, "GET", "/worklog", v, nil, &resp, nil) if err != nil { return nil, err } out := make([]apitypes.WorklogItem, 0, len(resp)) for _, w := range resp { err := w.setDetails() if err != nil { return nil, err } out = append(out, *w.WorklogItem) } return out, err }
go
func (w *WorklogClient) List(ctx context.Context, orgID *identity.ID) ([]apitypes.WorklogItem, error) { v := &url.Values{} if orgID != nil { v.Set("org_id", orgID.String()) } var resp []rawWorklogItem err := w.client.DaemonRoundTrip(ctx, "GET", "/worklog", v, nil, &resp, nil) if err != nil { return nil, err } out := make([]apitypes.WorklogItem, 0, len(resp)) for _, w := range resp { err := w.setDetails() if err != nil { return nil, err } out = append(out, *w.WorklogItem) } return out, err }
[ "func", "(", "w", "*", "WorklogClient", ")", "List", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ")", "(", "[", "]", "apitypes", ".", "WorklogItem", ",", "error", ")", "{", "v", ":=", "&", "url", ".", "Values", ...
// List returns the list of all worklog items in the given org.
[ "List", "returns", "the", "list", "of", "all", "worklog", "items", "in", "the", "given", "org", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/worklog.go#L21-L43
1,643
manifoldco/torus-cli
api/worklog.go
Get
func (w *WorklogClient) Get(ctx context.Context, orgID *identity.ID, ident *apitypes.WorklogID) (*apitypes.WorklogItem, error) { var res rawWorklogItem err := w.singleItemWorker(ctx, "GET", orgID, ident, &res) if err != nil { return nil, err } err = res.setDetails() return res.WorklogItem, err }
go
func (w *WorklogClient) Get(ctx context.Context, orgID *identity.ID, ident *apitypes.WorklogID) (*apitypes.WorklogItem, error) { var res rawWorklogItem err := w.singleItemWorker(ctx, "GET", orgID, ident, &res) if err != nil { return nil, err } err = res.setDetails() return res.WorklogItem, err }
[ "func", "(", "w", "*", "WorklogClient", ")", "Get", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ",", "ident", "*", "apitypes", ".", "WorklogID", ")", "(", "*", "apitypes", ".", "WorklogItem", ",", "error", ")", "{...
// Get returns the worklog item with the given id in the given org.
[ "Get", "returns", "the", "worklog", "item", "with", "the", "given", "id", "in", "the", "given", "org", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/worklog.go#L46-L55
1,644
manifoldco/torus-cli
api/worklog.go
Resolve
func (w *WorklogClient) Resolve(ctx context.Context, orgID *identity.ID, ident *apitypes.WorklogID) error { return w.singleItemWorker(ctx, "POST", orgID, ident, nil) }
go
func (w *WorklogClient) Resolve(ctx context.Context, orgID *identity.ID, ident *apitypes.WorklogID) error { return w.singleItemWorker(ctx, "POST", orgID, ident, nil) }
[ "func", "(", "w", "*", "WorklogClient", ")", "Resolve", "(", "ctx", "context", ".", "Context", ",", "orgID", "*", "identity", ".", "ID", ",", "ident", "*", "apitypes", ".", "WorklogID", ")", "error", "{", "return", "w", ".", "singleItemWorker", "(", "c...
// Resolve resolves the worklog item with the given id in the given org.
[ "Resolve", "resolves", "the", "worklog", "item", "with", "the", "given", "id", "in", "the", "given", "org", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/worklog.go#L58-L60
1,645
manifoldco/torus-cli
cmd/set.go
determinePath
func determinePath(ctx *cli.Context, path string) (*pathexp.PathExp, *string, error) { // First try and use the cli args as a full path. it should override any // options. idx := strings.LastIndex(path, "/") name := path[idx+1:] // It looks like the user gave a path expression. use that instead of flags. var pe *pathexp.PathExp var err error if idx != -1 { path := path[:idx] pe, err = parsePathExp(path) if err != nil { return nil, nil, errs.NewExitError(err.Error()) } if name == "*" { return nil, nil, errs.NewExitError("Secret name cannot be wildcard") } } else { pe, err = determinePathFromFlags(ctx) if err != nil { return nil, nil, err } } return pe, &name, nil }
go
func determinePath(ctx *cli.Context, path string) (*pathexp.PathExp, *string, error) { // First try and use the cli args as a full path. it should override any // options. idx := strings.LastIndex(path, "/") name := path[idx+1:] // It looks like the user gave a path expression. use that instead of flags. var pe *pathexp.PathExp var err error if idx != -1 { path := path[:idx] pe, err = parsePathExp(path) if err != nil { return nil, nil, errs.NewExitError(err.Error()) } if name == "*" { return nil, nil, errs.NewExitError("Secret name cannot be wildcard") } } else { pe, err = determinePathFromFlags(ctx) if err != nil { return nil, nil, err } } return pe, &name, nil }
[ "func", "determinePath", "(", "ctx", "*", "cli", ".", "Context", ",", "path", "string", ")", "(", "*", "pathexp", ".", "PathExp", ",", "*", "string", ",", "error", ")", "{", "// First try and use the cli args as a full path. it should override any", "// options.", ...
// determinePath returns a PathExp and a possible credential name if a full // path was provided.
[ "determinePath", "returns", "a", "PathExp", "and", "a", "possible", "credential", "name", "if", "a", "full", "path", "was", "provided", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/set.go#L106-L132
1,646
manifoldco/torus-cli
apitypes/claimtree.go
Revoked
func (pks *PublicKeySegment) Revoked() bool { for _, claim := range pks.Claims { if claim.Body.ClaimType == primitive.RevocationClaimType { return true } } return false }
go
func (pks *PublicKeySegment) Revoked() bool { for _, claim := range pks.Claims { if claim.Body.ClaimType == primitive.RevocationClaimType { return true } } return false }
[ "func", "(", "pks", "*", "PublicKeySegment", ")", "Revoked", "(", ")", "bool", "{", "for", "_", ",", "claim", ":=", "range", "pks", ".", "Claims", "{", "if", "claim", ".", "Body", ".", "ClaimType", "==", "primitive", ".", "RevocationClaimType", "{", "r...
// Revoked returns a bool indicating if any revocation claims exist against this // PublicKey
[ "Revoked", "returns", "a", "bool", "indicating", "if", "any", "revocation", "claims", "exist", "against", "this", "PublicKey" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/claimtree.go#L23-L31
1,647
manifoldco/torus-cli
apitypes/claimtree.go
HeadClaim
func (pks *PublicKeySegment) HeadClaim() (*envelope.Claim, error) { // The head claim is the one that is not the previous claim of any others outerLoop: for _, c1 := range pks.Claims { for _, c2 := range pks.Claims { if *c2.Body.Previous == *c1.ID { // Something else is newer than c1 continue outerLoop } } // nothing is newer than c1. return it return &c1, nil } return nil, ErrClaimCycleFound }
go
func (pks *PublicKeySegment) HeadClaim() (*envelope.Claim, error) { // The head claim is the one that is not the previous claim of any others outerLoop: for _, c1 := range pks.Claims { for _, c2 := range pks.Claims { if *c2.Body.Previous == *c1.ID { // Something else is newer than c1 continue outerLoop } } // nothing is newer than c1. return it return &c1, nil } return nil, ErrClaimCycleFound }
[ "func", "(", "pks", "*", "PublicKeySegment", ")", "HeadClaim", "(", ")", "(", "*", "envelope", ".", "Claim", ",", "error", ")", "{", "// The head claim is the one that is not the previous claim of any others", "outerLoop", ":", "for", "_", ",", "c1", ":=", "range"...
// HeadClaim returns the most recent Claim made against this PublicKey
[ "HeadClaim", "returns", "the", "most", "recent", "Claim", "made", "against", "this", "PublicKey" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/claimtree.go#L34-L50
1,648
manifoldco/torus-cli
registry/client.go
NewClientWithRoundTripper
func NewClientWithRoundTripper(rt RoundTripper) *Client { c := &Client{} c.KeyPairs = &KeyPairsClient{client: rt} c.Tokens = &TokensClient{client: rt} c.Users = &UsersClient{client: rt} c.Teams = &TeamsClient{client: rt} c.Memberships = &MembershipsClient{client: rt} c.Credentials = &Credentials{client: rt} c.Orgs = &OrgsClient{client: rt} c.OrgInvites = &OrgInvitesClient{client: rt} c.Policies = &PoliciesClient{client: rt} c.Projects = &ProjectsClient{client: rt} c.Environments = &EnvironmentsClient{client: rt} c.Services = &ServicesClient{client: rt} c.Claims = &ClaimsClient{client: rt} c.ClaimTree = &ClaimTreeClient{client: rt} c.Keyring = &KeyringClient{client: rt} c.Keyring.Members = &KeyringMembersClient{client: rt} c.KeyringMember = &KeyringMemberClientV1{client: rt} c.CredentialGraph = &CredentialGraphClient{client: rt} c.Machines = &MachinesClient{client: rt} c.Profiles = &ProfilesClient{client: rt} c.Self = &SelfClient{client: rt} c.Version = &VersionClient{client: rt} return c }
go
func NewClientWithRoundTripper(rt RoundTripper) *Client { c := &Client{} c.KeyPairs = &KeyPairsClient{client: rt} c.Tokens = &TokensClient{client: rt} c.Users = &UsersClient{client: rt} c.Teams = &TeamsClient{client: rt} c.Memberships = &MembershipsClient{client: rt} c.Credentials = &Credentials{client: rt} c.Orgs = &OrgsClient{client: rt} c.OrgInvites = &OrgInvitesClient{client: rt} c.Policies = &PoliciesClient{client: rt} c.Projects = &ProjectsClient{client: rt} c.Environments = &EnvironmentsClient{client: rt} c.Services = &ServicesClient{client: rt} c.Claims = &ClaimsClient{client: rt} c.ClaimTree = &ClaimTreeClient{client: rt} c.Keyring = &KeyringClient{client: rt} c.Keyring.Members = &KeyringMembersClient{client: rt} c.KeyringMember = &KeyringMemberClientV1{client: rt} c.CredentialGraph = &CredentialGraphClient{client: rt} c.Machines = &MachinesClient{client: rt} c.Profiles = &ProfilesClient{client: rt} c.Self = &SelfClient{client: rt} c.Version = &VersionClient{client: rt} return c }
[ "func", "NewClientWithRoundTripper", "(", "rt", "RoundTripper", ")", "*", "Client", "{", "c", ":=", "&", "Client", "{", "}", "\n\n", "c", ".", "KeyPairs", "=", "&", "KeyPairsClient", "{", "client", ":", "rt", "}", "\n", "c", ".", "Tokens", "=", "&", ...
// NewClientWithRoundTripper returns a new Client using the provided // RoundTripper. This is used in the api package to embed registry endpoints.
[ "NewClientWithRoundTripper", "returns", "a", "new", "Client", "using", "the", "provided", "RoundTripper", ".", "This", "is", "used", "in", "the", "api", "package", "to", "embed", "registry", "endpoints", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/client.go#L67-L94
1,649
manifoldco/torus-cli
registry/client.go
NewRequest
func (rt *registryRoundTripper) NewRequest(method, path string, query *url.Values, body interface{}) (*http.Request, error) { req, err := rt.DefaultRequestDoer.NewRequest(method, path, query, body) if err != nil { return nil, err } if rt.holder.HasToken() { req.Header.Set("Authorization", "Bearer "+string(rt.holder.Token())) } req.Header.Set("User-Agent", "Torus-Daemon/"+rt.version) req.Header.Set("X-Registry-Version", rt.apiVersion) return req, nil }
go
func (rt *registryRoundTripper) NewRequest(method, path string, query *url.Values, body interface{}) (*http.Request, error) { req, err := rt.DefaultRequestDoer.NewRequest(method, path, query, body) if err != nil { return nil, err } if rt.holder.HasToken() { req.Header.Set("Authorization", "Bearer "+string(rt.holder.Token())) } req.Header.Set("User-Agent", "Torus-Daemon/"+rt.version) req.Header.Set("X-Registry-Version", rt.apiVersion) return req, nil }
[ "func", "(", "rt", "*", "registryRoundTripper", ")", "NewRequest", "(", "method", ",", "path", "string", ",", "query", "*", "url", ".", "Values", ",", "body", "interface", "{", "}", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "req"...
// Augment the default NewRequest to set additional required headers
[ "Augment", "the", "default", "NewRequest", "to", "set", "additional", "required", "headers" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/client.go#L105-L122
1,650
manifoldco/torus-cli
registry/client.go
Do
func (rt *registryRoundTripper) Do(ctx context.Context, r *http.Request, v interface{}) (*http.Response, error) { ctx, cancelFunc := context.WithTimeout(ctx, 60*time.Second) r = r.WithContext(ctx) defer cancelFunc() resp, err := rt.DefaultRequestDoer.Do(ctx, r, v) if err != nil { if ctx.Err() == context.DeadlineExceeded { err = &apitypes.Error{ Type: apitypes.RequestTimeoutError, Err: []string{"Request timed out"}, } } return nil, err } return resp, nil }
go
func (rt *registryRoundTripper) Do(ctx context.Context, r *http.Request, v interface{}) (*http.Response, error) { ctx, cancelFunc := context.WithTimeout(ctx, 60*time.Second) r = r.WithContext(ctx) defer cancelFunc() resp, err := rt.DefaultRequestDoer.Do(ctx, r, v) if err != nil { if ctx.Err() == context.DeadlineExceeded { err = &apitypes.Error{ Type: apitypes.RequestTimeoutError, Err: []string{"Request timed out"}, } } return nil, err } return resp, nil }
[ "func", "(", "rt", "*", "registryRoundTripper", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "r", "*", "http", ".", "Request", ",", "v", "interface", "{", "}", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "ctx", ",", ...
// Augment the default Do to set a timeout.
[ "Augment", "the", "default", "Do", "to", "set", "a", "timeout", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/registry/client.go#L125-L145
1,651
manifoldco/torus-cli
config/config.go
NewConfig
func NewConfig(torusRoot string) (*Config, error) { preferences, err := prefs.NewPreferences() if err != nil { return nil, err } publicKey, err := prefs.LoadPublicKey(preferences) if err != nil { return nil, fmt.Errorf("failed to load public key") } caBundle, err := loadCABundle(preferences.Core.CABundleFile) if err != nil { return nil, err } registryURI, err := url.Parse(preferences.Core.RegistryURI) if err != nil { return nil, fmt.Errorf("invalid registry_uri") } manifestURI, err := url.Parse(preferences.Core.ManifestURI) if err != nil { return nil, fmt.Errorf("invalid manifest_uri") } _, _, err = net.SplitHostPort(preferences.Core.GatekeeperAddress) if err != nil { return nil, fmt.Errorf("invalid gatekeeper listener address") } cfg := &Config{ APIVersion: apiVersion, Version: Version, TorusRoot: torusRoot, PidPath: path.Join(torusRoot, "daemon.pid"), GatekeeperPidPath: path.Join(torusRoot, "gateway.pid"), DBPath: path.Join(torusRoot, "daemon.db"), LastUpdatePath: path.Join(torusRoot, "last_update"), RegistryURI: registryURI, ManifestURI: manifestURI, GatekeeperAddress: preferences.Core.GatekeeperAddress, CABundle: caBundle, PublicKey: publicKey, } // set OS specific transport address setTransportAddress(cfg) return cfg, nil }
go
func NewConfig(torusRoot string) (*Config, error) { preferences, err := prefs.NewPreferences() if err != nil { return nil, err } publicKey, err := prefs.LoadPublicKey(preferences) if err != nil { return nil, fmt.Errorf("failed to load public key") } caBundle, err := loadCABundle(preferences.Core.CABundleFile) if err != nil { return nil, err } registryURI, err := url.Parse(preferences.Core.RegistryURI) if err != nil { return nil, fmt.Errorf("invalid registry_uri") } manifestURI, err := url.Parse(preferences.Core.ManifestURI) if err != nil { return nil, fmt.Errorf("invalid manifest_uri") } _, _, err = net.SplitHostPort(preferences.Core.GatekeeperAddress) if err != nil { return nil, fmt.Errorf("invalid gatekeeper listener address") } cfg := &Config{ APIVersion: apiVersion, Version: Version, TorusRoot: torusRoot, PidPath: path.Join(torusRoot, "daemon.pid"), GatekeeperPidPath: path.Join(torusRoot, "gateway.pid"), DBPath: path.Join(torusRoot, "daemon.db"), LastUpdatePath: path.Join(torusRoot, "last_update"), RegistryURI: registryURI, ManifestURI: manifestURI, GatekeeperAddress: preferences.Core.GatekeeperAddress, CABundle: caBundle, PublicKey: publicKey, } // set OS specific transport address setTransportAddress(cfg) return cfg, nil }
[ "func", "NewConfig", "(", "torusRoot", "string", ")", "(", "*", "Config", ",", "error", ")", "{", "preferences", ",", "err", ":=", "prefs", ".", "NewPreferences", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", ...
// NewConfig returns a new Config, with loaded user preferences.
[ "NewConfig", "returns", "a", "new", "Config", "with", "loaded", "user", "preferences", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/config/config.go#L44-L96
1,652
manifoldco/torus-cli
config/config.go
CreateTorusRoot
func CreateTorusRoot(checkPermissions bool) (string, error) { torusRoot := torusRootPath() src, err := os.Stat(torusRoot) if err != nil && !os.IsNotExist(err) { return "", err } if err == nil && !src.IsDir() { return "", fmt.Errorf("%s exists but is not a dir", torusRoot) } if os.IsNotExist(err) { err = os.Mkdir(torusRoot, requiredPermissions) if err != nil { return "", err } src, err = os.Stat(torusRoot) if err != nil { return "", err } } fMode := src.Mode() if checkPermissions && fMode.Perm() != requiredPermissions { return "", fmt.Errorf("%s has permissions %d requires %d", torusRoot, fMode.Perm(), requiredPermissions) } return torusRoot, nil }
go
func CreateTorusRoot(checkPermissions bool) (string, error) { torusRoot := torusRootPath() src, err := os.Stat(torusRoot) if err != nil && !os.IsNotExist(err) { return "", err } if err == nil && !src.IsDir() { return "", fmt.Errorf("%s exists but is not a dir", torusRoot) } if os.IsNotExist(err) { err = os.Mkdir(torusRoot, requiredPermissions) if err != nil { return "", err } src, err = os.Stat(torusRoot) if err != nil { return "", err } } fMode := src.Mode() if checkPermissions && fMode.Perm() != requiredPermissions { return "", fmt.Errorf("%s has permissions %d requires %d", torusRoot, fMode.Perm(), requiredPermissions) } return torusRoot, nil }
[ "func", "CreateTorusRoot", "(", "checkPermissions", "bool", ")", "(", "string", ",", "error", ")", "{", "torusRoot", ":=", "torusRootPath", "(", ")", "\n", "src", ",", "err", ":=", "os", ".", "Stat", "(", "torusRoot", ")", "\n", "if", "err", "!=", "nil...
// CreateTorusRoot creates the root directory for the Torus daemon.
[ "CreateTorusRoot", "creates", "the", "root", "directory", "for", "the", "Torus", "daemon", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/config/config.go#L99-L129
1,653
manifoldco/torus-cli
config/config.go
loadCABundle
func loadCABundle(cafile string) (*x509.CertPool, error) { var pem []byte var err error if cafile == "" { pem, err = data.Asset("data/ca_bundle.pem") } else { pem, err = ioutil.ReadFile(cafile) } if err != nil { return nil, fmt.Errorf("unable to find CA bundle") } c := x509.NewCertPool() ok := c.AppendCertsFromPEM(pem) if !ok { return nil, fmt.Errorf("unable to load CA bundle from %s", cafile) } return c, nil }
go
func loadCABundle(cafile string) (*x509.CertPool, error) { var pem []byte var err error if cafile == "" { pem, err = data.Asset("data/ca_bundle.pem") } else { pem, err = ioutil.ReadFile(cafile) } if err != nil { return nil, fmt.Errorf("unable to find CA bundle") } c := x509.NewCertPool() ok := c.AppendCertsFromPEM(pem) if !ok { return nil, fmt.Errorf("unable to load CA bundle from %s", cafile) } return c, nil }
[ "func", "loadCABundle", "(", "cafile", "string", ")", "(", "*", "x509", ".", "CertPool", ",", "error", ")", "{", "var", "pem", "[", "]", "byte", "\n", "var", "err", "error", "\n\n", "if", "cafile", "==", "\"", "\"", "{", "pem", ",", "err", "=", "...
// Load CABundle creates a new CertPool from the given filename
[ "Load", "CABundle", "creates", "a", "new", "CertPool", "from", "the", "given", "filename" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/config/config.go#L132-L153
1,654
manifoldco/torus-cli
config/config.go
LoadConfig
func LoadConfig() (*Config, error) { cfg, err := NewConfig(torusRootPath()) if err != nil { return nil, errs.NewErrorExitError("Failed to load config.", err) } return cfg, nil }
go
func LoadConfig() (*Config, error) { cfg, err := NewConfig(torusRootPath()) if err != nil { return nil, errs.NewErrorExitError("Failed to load config.", err) } return cfg, nil }
[ "func", "LoadConfig", "(", ")", "(", "*", "Config", ",", "error", ")", "{", "cfg", ",", "err", ":=", "NewConfig", "(", "torusRootPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errs", ".", "NewErrorExitError", "(", ...
// LoadConfig loads the config, standardizing cli errors on failure.
[ "LoadConfig", "loads", "the", "config", "standardizing", "cli", "errors", "on", "failure", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/config/config.go#L156-L163
1,655
manifoldco/torus-cli
cmd/import.go
importSecretFile
func importSecretFile(args []string) ([]secretPair, error) { switch len(args) { case 0: return readStdin() case 1: return readFile(args[0]) default: return nil, errors.New("Too many arguments were provided") } }
go
func importSecretFile(args []string) ([]secretPair, error) { switch len(args) { case 0: return readStdin() case 1: return readFile(args[0]) default: return nil, errors.New("Too many arguments were provided") } }
[ "func", "importSecretFile", "(", "args", "[", "]", "string", ")", "(", "[", "]", "secretPair", ",", "error", ")", "{", "switch", "len", "(", "args", ")", "{", "case", "0", ":", "return", "readStdin", "(", ")", "\n", "case", "1", ":", "return", "rea...
// importSecretFile returns a list of secret pairs either reading a file // provided or from the standard input. It returns an error if there is a // problem parsing secrets or stdin fails to read.
[ "importSecretFile", "returns", "a", "list", "of", "secret", "pairs", "either", "reading", "a", "file", "provided", "or", "from", "the", "standard", "input", ".", "It", "returns", "an", "error", "if", "there", "is", "a", "problem", "parsing", "secrets", "or",...
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/import.go#L83-L92
1,656
manifoldco/torus-cli
cmd/import.go
scanSecrets
func scanSecrets(r io.Reader) ([]secretPair, error) { var pairs []secretPair lexer := shlex.NewLexer(r) for { word, err := lexer.Next() if err != nil { if err == io.EOF { return pairs, nil } return nil, fmt.Errorf("Error reading input file. %s", err) } tokens := strings.SplitN(word, "=", 2) if len(tokens) < 2 { return nil, fmt.Errorf("Error parsing secret %q", word) } key := tokens[0] value := tokens[1] if key == "" || value == "" { return nil, fmt.Errorf("Error parsing secret %q", word) } pairs = append(pairs, secretPair{key: key, value: value}) } }
go
func scanSecrets(r io.Reader) ([]secretPair, error) { var pairs []secretPair lexer := shlex.NewLexer(r) for { word, err := lexer.Next() if err != nil { if err == io.EOF { return pairs, nil } return nil, fmt.Errorf("Error reading input file. %s", err) } tokens := strings.SplitN(word, "=", 2) if len(tokens) < 2 { return nil, fmt.Errorf("Error parsing secret %q", word) } key := tokens[0] value := tokens[1] if key == "" || value == "" { return nil, fmt.Errorf("Error parsing secret %q", word) } pairs = append(pairs, secretPair{key: key, value: value}) } }
[ "func", "scanSecrets", "(", "r", "io", ".", "Reader", ")", "(", "[", "]", "secretPair", ",", "error", ")", "{", "var", "pairs", "[", "]", "secretPair", "\n\n", "lexer", ":=", "shlex", ".", "NewLexer", "(", "r", ")", "\n\n", "for", "{", "word", ",",...
// scanSecrets reads secret pairs using an UNIX shell-like syntax parser. Empty // lines and comments are ignored.
[ "scanSecrets", "reads", "secret", "pairs", "using", "an", "UNIX", "shell", "-", "like", "syntax", "parser", ".", "Empty", "lines", "and", "comments", "are", "ignored", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/import.go#L124-L152
1,657
manifoldco/torus-cli
daemon/routes/machines.go
createMachine
func createMachine(orgID, teamID, creatorID *identity.ID, name string) ( *envelope.Machine, []envelope.Membership, error) { machineBody := &primitive.Machine{ Name: name, OrgID: orgID, CreatedBy: creatorID, Created: time.Now().UTC(), DestroyedBy: nil, Destroyed: nil, State: primitive.MachineActiveState, } machineID, err := identity.NewMutable(machineBody) if err != nil { return nil, nil, err } machine := envelope.Machine{ ID: &machineID, Version: 1, Body: machineBody, } machineTeamID := identity.DeriveMutable(&primitive.Team{}, orgID, primitive.DerivableMachineTeamSymbol) teamIDList := []*identity.ID{&machineTeamID, teamID} var memberships []envelope.Membership for _, curTeamID := range teamIDList { body := primitive.Membership{ OwnerID: &machineID, OrgID: orgID, TeamID: curTeamID, } ID, err := identity.NewMutable(&body) if err != nil { return nil, nil, err } membership := envelope.Membership{ ID: &ID, Version: 1, Body: &body, } memberships = append(memberships, membership) } return &machine, memberships, nil }
go
func createMachine(orgID, teamID, creatorID *identity.ID, name string) ( *envelope.Machine, []envelope.Membership, error) { machineBody := &primitive.Machine{ Name: name, OrgID: orgID, CreatedBy: creatorID, Created: time.Now().UTC(), DestroyedBy: nil, Destroyed: nil, State: primitive.MachineActiveState, } machineID, err := identity.NewMutable(machineBody) if err != nil { return nil, nil, err } machine := envelope.Machine{ ID: &machineID, Version: 1, Body: machineBody, } machineTeamID := identity.DeriveMutable(&primitive.Team{}, orgID, primitive.DerivableMachineTeamSymbol) teamIDList := []*identity.ID{&machineTeamID, teamID} var memberships []envelope.Membership for _, curTeamID := range teamIDList { body := primitive.Membership{ OwnerID: &machineID, OrgID: orgID, TeamID: curTeamID, } ID, err := identity.NewMutable(&body) if err != nil { return nil, nil, err } membership := envelope.Membership{ ID: &ID, Version: 1, Body: &body, } memberships = append(memberships, membership) } return &machine, memberships, nil }
[ "func", "createMachine", "(", "orgID", ",", "teamID", ",", "creatorID", "*", "identity", ".", "ID", ",", "name", "string", ")", "(", "*", "envelope", ".", "Machine", ",", "[", "]", "envelope", ".", "Membership", ",", "error", ")", "{", "machineBody", "...
// createMachine generates a Machine object and associated Membership objects // to be uploaded to the registry in the future.
[ "createMachine", "generates", "a", "Machine", "object", "and", "associated", "Membership", "objects", "to", "be", "uploaded", "to", "the", "registry", "in", "the", "future", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/routes/machines.go#L91-L137
1,658
manifoldco/torus-cli
daemon/crypto/zz_generated_crypto.go
SignedPublicKey
func (e *Engine) SignedPublicKey(ctx context.Context, body *primitive.PublicKey, sigID *identity.ID, sigKP *SignatureKeyPair) (*envelope.PublicKey, error) { id, sig, err := e.signAndID(ctx, body, sigID, sigKP) if err != nil { return nil, err } return &envelope.PublicKey{ ID: id, Version: uint8(body.Version()), Body: body, Signature: *sig, }, nil }
go
func (e *Engine) SignedPublicKey(ctx context.Context, body *primitive.PublicKey, sigID *identity.ID, sigKP *SignatureKeyPair) (*envelope.PublicKey, error) { id, sig, err := e.signAndID(ctx, body, sigID, sigKP) if err != nil { return nil, err } return &envelope.PublicKey{ ID: id, Version: uint8(body.Version()), Body: body, Signature: *sig, }, nil }
[ "func", "(", "e", "*", "Engine", ")", "SignedPublicKey", "(", "ctx", "context", ".", "Context", ",", "body", "*", "primitive", ".", "PublicKey", ",", "sigID", "*", "identity", ".", "ID", ",", "sigKP", "*", "SignatureKeyPair", ")", "(", "*", "envelope", ...
// SignedPublicKey returns a PublicKeyEnvelope that is signed, and includes // a tamper-proof ID.
[ "SignedPublicKey", "returns", "a", "PublicKeyEnvelope", "that", "is", "signed", "and", "includes", "a", "tamper", "-", "proof", "ID", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/zz_generated_crypto.go#L15-L28
1,659
manifoldco/torus-cli
api/session.go
Name
func (s *Session) Name() string { if s.sessionType == apitypes.MachineSession { return s.identity.(*envelope.Machine).Body.Name } return s.identity.(envelope.UserInf).Name() }
go
func (s *Session) Name() string { if s.sessionType == apitypes.MachineSession { return s.identity.(*envelope.Machine).Body.Name } return s.identity.(envelope.UserInf).Name() }
[ "func", "(", "s", "*", "Session", ")", "Name", "(", ")", "string", "{", "if", "s", ".", "sessionType", "==", "apitypes", ".", "MachineSession", "{", "return", "s", ".", "identity", ".", "(", "*", "envelope", ".", "Machine", ")", ".", "Body", ".", "...
// Name returns the fullname of the user or the machine name
[ "Name", "returns", "the", "fullname", "of", "the", "user", "or", "the", "machine", "name" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L50-L56
1,660
manifoldco/torus-cli
api/session.go
Email
func (s *Session) Email() string { if s.sessionType == apitypes.MachineSession { return "none" } return s.identity.(envelope.UserInf).Email() }
go
func (s *Session) Email() string { if s.sessionType == apitypes.MachineSession { return "none" } return s.identity.(envelope.UserInf).Email() }
[ "func", "(", "s", "*", "Session", ")", "Email", "(", ")", "string", "{", "if", "s", ".", "sessionType", "==", "apitypes", ".", "MachineSession", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "s", ".", "identity", ".", "(", "envelope", ".", ...
// Email returns none for a machine or the users email address
[ "Email", "returns", "none", "for", "a", "machine", "or", "the", "users", "email", "address" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L59-L65
1,661
manifoldco/torus-cli
api/session.go
NewSession
func NewSession(resp *apitypes.Self) (*Session, error) { switch resp.Type { case apitypes.UserSession: if _, ok := resp.Identity.(envelope.UserInf); !ok { return nil, errors.New("Identity must be a user object") } if _, ok := resp.Auth.(envelope.UserInf); !ok { return nil, errors.New("Auth must be a user object") } case apitypes.MachineSession: if _, ok := resp.Identity.(*envelope.Machine); !ok { return nil, errors.New("Identity must be a machine object") } if _, ok := resp.Auth.(*envelope.MachineToken); !ok { return nil, errors.New("Auth must be a machine token object") } default: return nil, errors.New("did not recognize session type") } return &Session{ sessionType: resp.Type, identity: resp.Identity, auth: resp.Auth, }, nil }
go
func NewSession(resp *apitypes.Self) (*Session, error) { switch resp.Type { case apitypes.UserSession: if _, ok := resp.Identity.(envelope.UserInf); !ok { return nil, errors.New("Identity must be a user object") } if _, ok := resp.Auth.(envelope.UserInf); !ok { return nil, errors.New("Auth must be a user object") } case apitypes.MachineSession: if _, ok := resp.Identity.(*envelope.Machine); !ok { return nil, errors.New("Identity must be a machine object") } if _, ok := resp.Auth.(*envelope.MachineToken); !ok { return nil, errors.New("Auth must be a machine token object") } default: return nil, errors.New("did not recognize session type") } return &Session{ sessionType: resp.Type, identity: resp.Identity, auth: resp.Auth, }, nil }
[ "func", "NewSession", "(", "resp", "*", "apitypes", ".", "Self", ")", "(", "*", "Session", ",", "error", ")", "{", "switch", "resp", ".", "Type", "{", "case", "apitypes", ".", "UserSession", ":", "if", "_", ",", "ok", ":=", "resp", ".", "Identity", ...
// NewSession returns a new session constructed from the payload of the current // identity as returned from the Daemon
[ "NewSession", "returns", "a", "new", "session", "constructed", "from", "the", "payload", "of", "the", "current", "identity", "as", "returned", "from", "the", "Daemon" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L78-L104
1,662
manifoldco/torus-cli
api/session.go
Who
func (s *SessionClient) Who(ctx context.Context) (*Session, error) { raw := &rawSelf{} err := s.client.DaemonRoundTrip(ctx, "GET", "/self", nil, nil, raw, nil) if err != nil { return nil, err } self := raw.Self switch raw.Type { case apitypes.UserSession: self.Identity = &envelope.User{} self.Auth = &envelope.User{} case apitypes.MachineSession: self.Identity = &envelope.Machine{} self.Auth = &envelope.MachineToken{} default: return nil, errUnknownSessionType } err = json.Unmarshal(raw.Identity, self.Identity) if err != nil { return nil, err } err = json.Unmarshal(raw.Auth, self.Auth) if err != nil { return nil, err } return NewSession(self) }
go
func (s *SessionClient) Who(ctx context.Context) (*Session, error) { raw := &rawSelf{} err := s.client.DaemonRoundTrip(ctx, "GET", "/self", nil, nil, raw, nil) if err != nil { return nil, err } self := raw.Self switch raw.Type { case apitypes.UserSession: self.Identity = &envelope.User{} self.Auth = &envelope.User{} case apitypes.MachineSession: self.Identity = &envelope.Machine{} self.Auth = &envelope.MachineToken{} default: return nil, errUnknownSessionType } err = json.Unmarshal(raw.Identity, self.Identity) if err != nil { return nil, err } err = json.Unmarshal(raw.Auth, self.Auth) if err != nil { return nil, err } return NewSession(self) }
[ "func", "(", "s", "*", "SessionClient", ")", "Who", "(", "ctx", "context", ".", "Context", ")", "(", "*", "Session", ",", "error", ")", "{", "raw", ":=", "&", "rawSelf", "{", "}", "\n", "err", ":=", "s", ".", "client", ".", "DaemonRoundTrip", "(", ...
// Who returns the Session object for the current authenticated user or machine
[ "Who", "returns", "the", "Session", "object", "for", "the", "current", "authenticated", "user", "or", "machine" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L121-L151
1,663
manifoldco/torus-cli
api/session.go
Get
func (s *SessionClient) Get(ctx context.Context) (*apitypes.SessionStatus, error) { resp := &apitypes.SessionStatus{} err := s.client.DaemonRoundTrip(ctx, "GET", "/session", nil, nil, resp, nil) return resp, err }
go
func (s *SessionClient) Get(ctx context.Context) (*apitypes.SessionStatus, error) { resp := &apitypes.SessionStatus{} err := s.client.DaemonRoundTrip(ctx, "GET", "/session", nil, nil, resp, nil) return resp, err }
[ "func", "(", "s", "*", "SessionClient", ")", "Get", "(", "ctx", "context", ".", "Context", ")", "(", "*", "apitypes", ".", "SessionStatus", ",", "error", ")", "{", "resp", ":=", "&", "apitypes", ".", "SessionStatus", "{", "}", "\n", "err", ":=", "s",...
// Get returns the status of the user's session.
[ "Get", "returns", "the", "status", "of", "the", "user", "s", "session", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L154-L158
1,664
manifoldco/torus-cli
api/session.go
UserLogin
func (s *SessionClient) UserLogin(ctx context.Context, email, passphrase string) error { // Package up login credentials for the user login := apitypes.UserLogin{ Email: email, Password: passphrase, } rawLogin, err := json.Marshal(login) if err != nil { return err } return performLogin(ctx, s, "user", rawLogin) }
go
func (s *SessionClient) UserLogin(ctx context.Context, email, passphrase string) error { // Package up login credentials for the user login := apitypes.UserLogin{ Email: email, Password: passphrase, } rawLogin, err := json.Marshal(login) if err != nil { return err } return performLogin(ctx, s, "user", rawLogin) }
[ "func", "(", "s", "*", "SessionClient", ")", "UserLogin", "(", "ctx", "context", ".", "Context", ",", "email", ",", "passphrase", "string", ")", "error", "{", "// Package up login credentials for the user", "login", ":=", "apitypes", ".", "UserLogin", "{", "Emai...
// UserLogin logs the user in using the provided email and passphrase
[ "UserLogin", "logs", "the", "user", "in", "using", "the", "provided", "email", "and", "passphrase" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L161-L174
1,665
manifoldco/torus-cli
api/session.go
MachineLogin
func (s *SessionClient) MachineLogin(ctx context.Context, tokenID, tokenSecret string) error { ID, err := identity.DecodeFromString(tokenID) if err != nil { return err } secret, err := base64.NewFromString(tokenSecret) if err != nil { return err } login := apitypes.MachineLogin{ TokenID: &ID, Secret: secret, } rawLogin, err := json.Marshal(login) if err != nil { return err } return performLogin(ctx, s, "machine", rawLogin) }
go
func (s *SessionClient) MachineLogin(ctx context.Context, tokenID, tokenSecret string) error { ID, err := identity.DecodeFromString(tokenID) if err != nil { return err } secret, err := base64.NewFromString(tokenSecret) if err != nil { return err } login := apitypes.MachineLogin{ TokenID: &ID, Secret: secret, } rawLogin, err := json.Marshal(login) if err != nil { return err } return performLogin(ctx, s, "machine", rawLogin) }
[ "func", "(", "s", "*", "SessionClient", ")", "MachineLogin", "(", "ctx", "context", ".", "Context", ",", "tokenID", ",", "tokenSecret", "string", ")", "error", "{", "ID", ",", "err", ":=", "identity", ".", "DecodeFromString", "(", "tokenID", ")", "\n", "...
// MachineLogin logs the user in using the provided token id and secret
[ "MachineLogin", "logs", "the", "user", "in", "using", "the", "provided", "token", "id", "and", "secret" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L177-L199
1,666
manifoldco/torus-cli
api/session.go
Logout
func (s *SessionClient) Logout(ctx context.Context) error { return s.client.DaemonRoundTrip(ctx, "POST", "/logout", nil, nil, nil, nil) }
go
func (s *SessionClient) Logout(ctx context.Context) error { return s.client.DaemonRoundTrip(ctx, "POST", "/logout", nil, nil, nil, nil) }
[ "func", "(", "s", "*", "SessionClient", ")", "Logout", "(", "ctx", "context", ".", "Context", ")", "error", "{", "return", "s", ".", "client", ".", "DaemonRoundTrip", "(", "ctx", ",", "\"", "\"", ",", "\"", "\"", ",", "nil", ",", "nil", ",", "nil",...
// Logout logs the user out of their session
[ "Logout", "logs", "the", "user", "out", "of", "their", "session" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/api/session.go#L211-L213
1,667
manifoldco/torus-cli
daemon/utils/utils.go
CreateHTTPTransport
func CreateHTTPTransport(caBundle *x509.CertPool, hostname string) *http.Transport { return &http.Transport{TLSClientConfig: &tls.Config{ ServerName: hostname, RootCAs: caBundle, }} }
go
func CreateHTTPTransport(caBundle *x509.CertPool, hostname string) *http.Transport { return &http.Transport{TLSClientConfig: &tls.Config{ ServerName: hostname, RootCAs: caBundle, }} }
[ "func", "CreateHTTPTransport", "(", "caBundle", "*", "x509", ".", "CertPool", ",", "hostname", "string", ")", "*", "http", ".", "Transport", "{", "return", "&", "http", ".", "Transport", "{", "TLSClientConfig", ":", "&", "tls", ".", "Config", "{", "ServerN...
// CreateHTTPTransport creates and configures the
[ "CreateHTTPTransport", "creates", "and", "configures", "the" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/utils/utils.go#L10-L15
1,668
manifoldco/torus-cli
cmd/signup.go
signup
func signup(ctx *cli.Context, subCommand bool) error { fmt.Println("Torus is no longer accepting signups.") os.Exit(-1) return nil }
go
func signup(ctx *cli.Context, subCommand bool) error { fmt.Println("Torus is no longer accepting signups.") os.Exit(-1) return nil }
[ "func", "signup", "(", "ctx", "*", "cli", ".", "Context", ",", "subCommand", "bool", ")", "error", "{", "fmt", ".", "Println", "(", "\"", "\"", ")", "\n", "os", ".", "Exit", "(", "-", "1", ")", "\n", "return", "nil", "\n", "}" ]
// signup can be ran as a sub-command when an account is needed prior to running // a particular action. the subCommand boolean signifies it is running as such // and not as a generic signup
[ "signup", "can", "be", "ran", "as", "a", "sub", "-", "command", "when", "an", "account", "is", "needed", "prior", "to", "running", "a", "particular", "action", ".", "the", "subCommand", "boolean", "signifies", "it", "is", "running", "as", "such", "and", ...
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/signup.go#L27-L31
1,669
manifoldco/torus-cli
gatekeeper/routes/boostrap.go
writeError
func writeError(w http.ResponseWriter, status int, err error) { w.WriteHeader(status) enc := json.NewEncoder(w) resp := baseapitypes.Error{ Type: baseapitypes.InternalServerError, Err: []string{err.Error()}, } enc.Encode(resp) }
go
func writeError(w http.ResponseWriter, status int, err error) { w.WriteHeader(status) enc := json.NewEncoder(w) resp := baseapitypes.Error{ Type: baseapitypes.InternalServerError, Err: []string{err.Error()}, } enc.Encode(resp) }
[ "func", "writeError", "(", "w", "http", ".", "ResponseWriter", ",", "status", "int", ",", "err", "error", ")", "{", "w", ".", "WriteHeader", "(", "status", ")", "\n", "enc", ":=", "json", ".", "NewEncoder", "(", "w", ")", "\n", "resp", ":=", "baseapi...
// writeError returns a bootstrapping error
[ "writeError", "returns", "a", "bootstrapping", "error" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/gatekeeper/routes/boostrap.go#L139-L148
1,670
manifoldco/torus-cli
cmd/run.go
manipulateEnv
func manipulateEnv(path *pathexp.PathExp) []string { env := filterEnv() org := path.Org.Components() project := path.Project.Components() envs := path.Envs.Components() services := path.Services.Components() env = append(env, "TORUS_ORG="+org[0]) env = append(env, "TORUS_PROJECT="+project[0]) env = append(env, "TORUS_ENVIRONMENT="+envs[0]) env = append(env, "TORUS_SERVICE="+services[0]) return env }
go
func manipulateEnv(path *pathexp.PathExp) []string { env := filterEnv() org := path.Org.Components() project := path.Project.Components() envs := path.Envs.Components() services := path.Services.Components() env = append(env, "TORUS_ORG="+org[0]) env = append(env, "TORUS_PROJECT="+project[0]) env = append(env, "TORUS_ENVIRONMENT="+envs[0]) env = append(env, "TORUS_SERVICE="+services[0]) return env }
[ "func", "manipulateEnv", "(", "path", "*", "pathexp", ".", "PathExp", ")", "[", "]", "string", "{", "env", ":=", "filterEnv", "(", ")", "\n\n", "org", ":=", "path", ".", "Org", ".", "Components", "(", ")", "\n", "project", ":=", "path", ".", "Project...
// manipulateEnv removes any sensitive torus environment variables and sets // `TORUS_ORG`, `TORUS_PROJECT`, `TORUS_ENVIRONMENT`, and `TORUS_SERVICE` for // use by the running process.
[ "manipulateEnv", "removes", "any", "sensitive", "torus", "environment", "variables", "and", "sets", "TORUS_ORG", "TORUS_PROJECT", "TORUS_ENVIRONMENT", "and", "TORUS_SERVICE", "for", "use", "by", "the", "running", "process", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/run.go#L103-L117
1,671
manifoldco/torus-cli
daemon/crypto/crypto.go
Sign
func (k *LoginKeypair) Sign(token []byte) *base64url.Value { sig := ed25519.Sign(k.private, token) return base64url.New(sig) }
go
func (k *LoginKeypair) Sign(token []byte) *base64url.Value { sig := ed25519.Sign(k.private, token) return base64url.New(sig) }
[ "func", "(", "k", "*", "LoginKeypair", ")", "Sign", "(", "token", "[", "]", "byte", ")", "*", "base64url", ".", "Value", "{", "sig", ":=", "ed25519", ".", "Sign", "(", "k", ".", "private", ",", "token", ")", "\n", "return", "base64url", ".", "New",...
// Sign returns a signature of the given token as a base64 string
[ "Sign", "returns", "a", "signature", "of", "the", "given", "token", "as", "a", "base64", "string" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/crypto.go#L59-L62
1,672
manifoldco/torus-cli
daemon/crypto/crypto.go
DeriveLoginHMAC
func DeriveLoginHMAC(ctx context.Context, password []byte, salt, token string) (string, error) { key, err := derivePassword(ctx, password, salt) if err != nil { return "", err } pwh := make([]byte, base64.RawURLEncoding.EncodedLen(32)) base64.RawURLEncoding.Encode(pwh, key) mac := hmac.New(sha512.New, pwh) mac.Write([]byte(token)) return base64.RawURLEncoding.EncodeToString(mac.Sum(nil)), nil }
go
func DeriveLoginHMAC(ctx context.Context, password []byte, salt, token string) (string, error) { key, err := derivePassword(ctx, password, salt) if err != nil { return "", err } pwh := make([]byte, base64.RawURLEncoding.EncodedLen(32)) base64.RawURLEncoding.Encode(pwh, key) mac := hmac.New(sha512.New, pwh) mac.Write([]byte(token)) return base64.RawURLEncoding.EncodeToString(mac.Sum(nil)), nil }
[ "func", "DeriveLoginHMAC", "(", "ctx", "context", ".", "Context", ",", "password", "[", "]", "byte", ",", "salt", ",", "token", "string", ")", "(", "string", ",", "error", ")", "{", "key", ",", "err", ":=", "derivePassword", "(", "ctx", ",", "password"...
// DeriveLoginHMAC HMACs the provided token with a key derived from password // and the provided base64 encoded salt.
[ "DeriveLoginHMAC", "HMACs", "the", "provided", "token", "with", "a", "key", "derived", "from", "password", "and", "the", "provided", "base64", "encoded", "salt", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/crypto.go#L66-L78
1,673
manifoldco/torus-cli
daemon/crypto/crypto.go
CreateMasterKeyObject
func CreateMasterKeyObject(ctx context.Context, password []byte, masterKey *[]byte) (*primitive.MasterKey, error) { m := &primitive.MasterKey{ Alg: Triplesec, } // We either need to generate a new key, or will use the existing // key during a password change scenario key := make([]byte, masterKeyBytes) if masterKey == nil { // Generate a master key of 256 bytes _, err := rand.Read(key) if err != nil { return nil, err } } else { // Use the provided key key = *masterKey } err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } ts, err := newTriplesec(ctx, password) if err != nil { return nil, err } ct, err := ts.Encrypt(key) if err != nil { return nil, err } // Encode the master key value to base64url m.Value = base64url.New(ct) return m, nil }
go
func CreateMasterKeyObject(ctx context.Context, password []byte, masterKey *[]byte) (*primitive.MasterKey, error) { m := &primitive.MasterKey{ Alg: Triplesec, } // We either need to generate a new key, or will use the existing // key during a password change scenario key := make([]byte, masterKeyBytes) if masterKey == nil { // Generate a master key of 256 bytes _, err := rand.Read(key) if err != nil { return nil, err } } else { // Use the provided key key = *masterKey } err := ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } ts, err := newTriplesec(ctx, password) if err != nil { return nil, err } ct, err := ts.Encrypt(key) if err != nil { return nil, err } // Encode the master key value to base64url m.Value = base64url.New(ct) return m, nil }
[ "func", "CreateMasterKeyObject", "(", "ctx", "context", ".", "Context", ",", "password", "[", "]", "byte", ",", "masterKey", "*", "[", "]", "byte", ")", "(", "*", "primitive", ".", "MasterKey", ",", "error", ")", "{", "m", ":=", "&", "primitive", ".", ...
// CreateMasterKeyObject generates a 256 byte master key which is then // encrypted using TripleSec-v3 using the given password.
[ "CreateMasterKeyObject", "generates", "a", "256", "byte", "master", "key", "which", "is", "then", "encrypted", "using", "TripleSec", "-", "v3", "using", "the", "given", "password", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/crypto.go#L164-L201
1,674
manifoldco/torus-cli
daemon/crypto/crypto.go
DeriveLoginKeypair
func DeriveLoginKeypair(ctx context.Context, secret []byte, salt *base64url.Value) ( *LoginKeypair, error) { key, err := deriveHash(ctx, secret, salt.String()) if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } r := bytes.NewReader(key[224:]) // Use last 32 bytes of 256 to derive key pubKey, privKey, err := ed25519.GenerateKey(r) if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } keypair := &LoginKeypair{ public: pubKey, private: privKey, salt: salt, } return keypair, nil }
go
func DeriveLoginKeypair(ctx context.Context, secret []byte, salt *base64url.Value) ( *LoginKeypair, error) { key, err := deriveHash(ctx, secret, salt.String()) if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } r := bytes.NewReader(key[224:]) // Use last 32 bytes of 256 to derive key pubKey, privKey, err := ed25519.GenerateKey(r) if err != nil { return nil, err } err = ctxutil.ErrIfDone(ctx) if err != nil { return nil, err } keypair := &LoginKeypair{ public: pubKey, private: privKey, salt: salt, } return keypair, nil }
[ "func", "DeriveLoginKeypair", "(", "ctx", "context", ".", "Context", ",", "secret", "[", "]", "byte", ",", "salt", "*", "base64url", ".", "Value", ")", "(", "*", "LoginKeypair", ",", "error", ")", "{", "key", ",", "err", ":=", "deriveHash", "(", "ctx",...
// DeriveLoginKeypair dervies the ed25519 login keypair used for machine // authentication from the given salt and secret values.
[ "DeriveLoginKeypair", "dervies", "the", "ed25519", "login", "keypair", "used", "for", "machine", "authentication", "from", "the", "given", "salt", "and", "secret", "values", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/crypto/crypto.go#L205-L235
1,675
manifoldco/torus-cli
gatekeeper/client/client.go
NewClient
func NewClient(host, caFile string) (*Client, error) { if !strings.HasSuffix(host, "/") { host += "/" } caPool, err := x509.SystemCertPool() if err != nil { log.Printf("Could not load system certificate pool: %s. Creating custom pool", err) caPool = x509.NewCertPool() } if caFile != "" { caBytes, err := ioutil.ReadFile(caFile) if err != nil { return nil, fmt.Errorf("unable to read ca file: %s", err) } ok := caPool.AppendCertsFromPEM(caBytes) if !ok { return nil, fmt.Errorf("unable to parse and append ca file: %s", err) } } tlsConfig := &tls.Config{ RootCAs: caPool, } transport := &http.Transport{ TLSClientConfig: tlsConfig, } return &Client{ rt: &clientRoundTripper{ DefaultRequestDoer: registry.DefaultRequestDoer{ Client: &http.Client{ Timeout: clientTimeout, Transport: transport, }, Host: host, }, }, }, nil }
go
func NewClient(host, caFile string) (*Client, error) { if !strings.HasSuffix(host, "/") { host += "/" } caPool, err := x509.SystemCertPool() if err != nil { log.Printf("Could not load system certificate pool: %s. Creating custom pool", err) caPool = x509.NewCertPool() } if caFile != "" { caBytes, err := ioutil.ReadFile(caFile) if err != nil { return nil, fmt.Errorf("unable to read ca file: %s", err) } ok := caPool.AppendCertsFromPEM(caBytes) if !ok { return nil, fmt.Errorf("unable to parse and append ca file: %s", err) } } tlsConfig := &tls.Config{ RootCAs: caPool, } transport := &http.Transport{ TLSClientConfig: tlsConfig, } return &Client{ rt: &clientRoundTripper{ DefaultRequestDoer: registry.DefaultRequestDoer{ Client: &http.Client{ Timeout: clientTimeout, Transport: transport, }, Host: host, }, }, }, nil }
[ "func", "NewClient", "(", "host", ",", "caFile", "string", ")", "(", "*", "Client", ",", "error", ")", "{", "if", "!", "strings", ".", "HasSuffix", "(", "host", ",", "\"", "\"", ")", "{", "host", "+=", "\"", "\"", "\n", "}", "\n\n", "caPool", ","...
// NewClient returns a new client to a Gatekeeper host that can bootstrap this machine
[ "NewClient", "returns", "a", "new", "client", "to", "a", "Gatekeeper", "host", "that", "can", "bootstrap", "this", "machine" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/gatekeeper/client/client.go#L36-L77
1,676
manifoldco/torus-cli
gatekeeper/client/client.go
Bootstrap
func (c *Client) Bootstrap(provider string, bootreq interface{}) (*apitypes.BootstrapResponse, error) { path := fmt.Sprintf("%s/%s/%s", gatekeeperAPIVersion, "machine", provider) req, err := c.rt.NewRequest("POST", path, nil, bootreq) if err != nil { return nil, err } var bootresp apitypes.BootstrapResponse resp, err := c.rt.Do(context.Background(), req, &bootresp) if err != nil { return nil, err } defer resp.Body.Close() return &bootresp, nil }
go
func (c *Client) Bootstrap(provider string, bootreq interface{}) (*apitypes.BootstrapResponse, error) { path := fmt.Sprintf("%s/%s/%s", gatekeeperAPIVersion, "machine", provider) req, err := c.rt.NewRequest("POST", path, nil, bootreq) if err != nil { return nil, err } var bootresp apitypes.BootstrapResponse resp, err := c.rt.Do(context.Background(), req, &bootresp) if err != nil { return nil, err } defer resp.Body.Close() return &bootresp, nil }
[ "func", "(", "c", "*", "Client", ")", "Bootstrap", "(", "provider", "string", ",", "bootreq", "interface", "{", "}", ")", "(", "*", "apitypes", ".", "BootstrapResponse", ",", "error", ")", "{", "path", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",...
// Bootstrap bootstraps the machine with Gatekeeper
[ "Bootstrap", "bootstraps", "the", "machine", "with", "Gatekeeper" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/gatekeeper/client/client.go#L80-L95
1,677
manifoldco/torus-cli
cmd/version.go
VersionLookup
func VersionLookup(ctx *cli.Context) error { return chain( ensureDaemon, listVersionsCmd, checkUpdates, )(ctx) }
go
func VersionLookup(ctx *cli.Context) error { return chain( ensureDaemon, listVersionsCmd, checkUpdates, )(ctx) }
[ "func", "VersionLookup", "(", "ctx", "*", "cli", ".", "Context", ")", "error", "{", "return", "chain", "(", "ensureDaemon", ",", "listVersionsCmd", ",", "checkUpdates", ",", ")", "(", "ctx", ")", "\n", "}" ]
// VersionLookup ensures the environment is ready and then executes version cmd
[ "VersionLookup", "ensures", "the", "environment", "is", "ready", "and", "then", "executes", "version", "cmd" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/version.go#L28-L32
1,678
manifoldco/torus-cli
apitypes/worklog.go
DecodeWorklogIDFromString
func DecodeWorklogIDFromString(raw string) (WorklogID, error) { id := WorklogID{} buf, err := base32.DecodeString(raw) if err != nil { return id, err } if len(buf) != worklogIDLen { return id, ErrIncorrectWorklogIDLen } copy(id[:], buf) return id, nil }
go
func DecodeWorklogIDFromString(raw string) (WorklogID, error) { id := WorklogID{} buf, err := base32.DecodeString(raw) if err != nil { return id, err } if len(buf) != worklogIDLen { return id, ErrIncorrectWorklogIDLen } copy(id[:], buf) return id, nil }
[ "func", "DecodeWorklogIDFromString", "(", "raw", "string", ")", "(", "WorklogID", ",", "error", ")", "{", "id", ":=", "WorklogID", "{", "}", "\n\n", "buf", ",", "err", ":=", "base32", ".", "DecodeString", "(", "raw", ")", "\n", "if", "err", "!=", "nil"...
// DecodeWorklogIDFromString decodes a WorklogID from the given base32 encoded // representation.
[ "DecodeWorklogIDFromString", "decodes", "a", "WorklogID", "from", "the", "given", "base32", "encoded", "representation", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/worklog.go#L40-L55
1,679
manifoldco/torus-cli
apitypes/worklog.go
String
func (t WorklogType) String() string { switch t { case SecretRotateWorklogType: return "secret" case MissingKeypairsWorklogType: return "keypairs" case InviteApproveWorklogType: return "invite" case UserKeyringMembersWorklogType: fallthrough case MachineKeyringMembersWorklogType: return "secret" default: return "n/a" } }
go
func (t WorklogType) String() string { switch t { case SecretRotateWorklogType: return "secret" case MissingKeypairsWorklogType: return "keypairs" case InviteApproveWorklogType: return "invite" case UserKeyringMembersWorklogType: fallthrough case MachineKeyringMembersWorklogType: return "secret" default: return "n/a" } }
[ "func", "(", "t", "WorklogType", ")", "String", "(", ")", "string", "{", "switch", "t", "{", "case", "SecretRotateWorklogType", ":", "return", "\"", "\"", "\n", "case", "MissingKeypairsWorklogType", ":", "return", "\"", "\"", "\n", "case", "InviteApproveWorklo...
// String returns a human reable string for this worklog item type.
[ "String", "returns", "a", "human", "reable", "string", "for", "this", "worklog", "item", "type", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/worklog.go#L189-L204
1,680
manifoldco/torus-cli
apitypes/worklog.go
CreateID
func (w *WorklogItem) CreateID(worklogType WorklogType) { h, err := blake2b.New(&blake2b.Config{Size: worklogIDLen - 1}) if err != nil { // this only happens with a bad config panic(err) } h.Write([]byte{byte(worklogType)}) h.Write([]byte(w.Details.Subject())) id := WorklogID{byte(worklogType)} copy(id[1:], h.Sum(nil)) w.ID = &id }
go
func (w *WorklogItem) CreateID(worklogType WorklogType) { h, err := blake2b.New(&blake2b.Config{Size: worklogIDLen - 1}) if err != nil { // this only happens with a bad config panic(err) } h.Write([]byte{byte(worklogType)}) h.Write([]byte(w.Details.Subject())) id := WorklogID{byte(worklogType)} copy(id[1:], h.Sum(nil)) w.ID = &id }
[ "func", "(", "w", "*", "WorklogItem", ")", "CreateID", "(", "worklogType", "WorklogType", ")", "{", "h", ",", "err", ":=", "blake2b", ".", "New", "(", "&", "blake2b", ".", "Config", "{", "Size", ":", "worklogIDLen", "-", "1", "}", ")", "\n", "if", ...
// CreateID creates and populates a WorklogID for the WorklogItem based on the // given type and its subject.
[ "CreateID", "creates", "and", "populates", "a", "WorklogID", "for", "the", "WorklogItem", "based", "on", "the", "given", "type", "and", "its", "subject", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/apitypes/worklog.go#L208-L220
1,681
manifoldco/torus-cli
daemon/logic/utils.go
createCredentialGraph
func createCredentialGraph(ctx context.Context, credBody *PlaintextCredential, parent registry.CredentialGraph, sigID *identity.ID, encID *identity.ID, kp *crypto.KeyPairs, ct *registry.ClaimTree, client *registry.Client, engine *crypto.Engine, g *secure.Guard) (*registry.CredentialGraphV2, error) { pathExp, err := credBody.PathExp.WithInstance("*") if err != nil { return nil, err } keyringBody := primitive.NewKeyring(credBody.OrgID, credBody.ProjectID, pathExp) if parent != nil { keyringBody.Previous = parent.GetKeyring().GetID() keyringBody.KeyringVersion = parent.KeyringVersion() + 1 } keyring, err := engine.SignedKeyring(ctx, keyringBody, sigID, &kp.Signature) if err != nil { return nil, err } mek, err := g.Random(64) defer mek.Destroy() if err != nil { return nil, err } subjects, err := getKeyringMembers(ctx, client, credBody.OrgID) if err != nil { return nil, err } // use their public key to encrypt the mek with a random nonce. members := []registry.KeyringMember{} for _, subject := range subjects { for _, id := range subject.KeyOwnerIDs() { // For this user/mtoken, find their public encryption key enc, err := ct.FindActive(&id, primitive.EncryptionKeyType) if err == registry.ErrMissingKeyForOwner { // If we didn't find an active key, don't encode this // user/token in the keyring, but keep going. continue } if err != nil { return nil, err } encPubKey := enc.PublicKey encmek, nonce, err := engine.Box(ctx, mek, &kp.Encryption, []byte(*encPubKey.Body.Key.Value)) if err != nil { return nil, err } key := &primitive.KeyringMemberKey{ Algorithm: crypto.EasyBox, Nonce: base64.New(nonce), Value: base64.New(encmek), } member, err := newV2KeyringMember(ctx, engine, credBody.OrgID, keyring.ID, encPubKey.Body.OwnerID, encPubKey.ID, encID, sigID, key, kp) if err != nil { return nil, err } members = append(members, *member) } } graph := registry.CredentialGraphV2{ KeyringSectionV2: registry.KeyringSectionV2{ Keyring: keyring, Claims: []envelope.KeyringMemberClaim{}, Members: members, }, } return &graph, nil }
go
func createCredentialGraph(ctx context.Context, credBody *PlaintextCredential, parent registry.CredentialGraph, sigID *identity.ID, encID *identity.ID, kp *crypto.KeyPairs, ct *registry.ClaimTree, client *registry.Client, engine *crypto.Engine, g *secure.Guard) (*registry.CredentialGraphV2, error) { pathExp, err := credBody.PathExp.WithInstance("*") if err != nil { return nil, err } keyringBody := primitive.NewKeyring(credBody.OrgID, credBody.ProjectID, pathExp) if parent != nil { keyringBody.Previous = parent.GetKeyring().GetID() keyringBody.KeyringVersion = parent.KeyringVersion() + 1 } keyring, err := engine.SignedKeyring(ctx, keyringBody, sigID, &kp.Signature) if err != nil { return nil, err } mek, err := g.Random(64) defer mek.Destroy() if err != nil { return nil, err } subjects, err := getKeyringMembers(ctx, client, credBody.OrgID) if err != nil { return nil, err } // use their public key to encrypt the mek with a random nonce. members := []registry.KeyringMember{} for _, subject := range subjects { for _, id := range subject.KeyOwnerIDs() { // For this user/mtoken, find their public encryption key enc, err := ct.FindActive(&id, primitive.EncryptionKeyType) if err == registry.ErrMissingKeyForOwner { // If we didn't find an active key, don't encode this // user/token in the keyring, but keep going. continue } if err != nil { return nil, err } encPubKey := enc.PublicKey encmek, nonce, err := engine.Box(ctx, mek, &kp.Encryption, []byte(*encPubKey.Body.Key.Value)) if err != nil { return nil, err } key := &primitive.KeyringMemberKey{ Algorithm: crypto.EasyBox, Nonce: base64.New(nonce), Value: base64.New(encmek), } member, err := newV2KeyringMember(ctx, engine, credBody.OrgID, keyring.ID, encPubKey.Body.OwnerID, encPubKey.ID, encID, sigID, key, kp) if err != nil { return nil, err } members = append(members, *member) } } graph := registry.CredentialGraphV2{ KeyringSectionV2: registry.KeyringSectionV2{ Keyring: keyring, Claims: []envelope.KeyringMemberClaim{}, Members: members, }, } return &graph, nil }
[ "func", "createCredentialGraph", "(", "ctx", "context", ".", "Context", ",", "credBody", "*", "PlaintextCredential", ",", "parent", "registry", ".", "CredentialGraph", ",", "sigID", "*", "identity", ".", "ID", ",", "encID", "*", "identity", ".", "ID", ",", "...
// createCredentialGraph generates, signs, and posts a new CredentialGraph // to the registry.
[ "createCredentialGraph", "generates", "signs", "and", "posts", "a", "new", "CredentialGraph", "to", "the", "registry", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/utils.go#L89-L167
1,682
manifoldco/torus-cli
daemon/logic/utils.go
fetchKeyPairs
func fetchKeyPairs(k *registry.Keypairs, orgID *identity.ID) ( *identity.ID, *identity.ID, *crypto.KeyPairs, error) { enc, err := k.Select(orgID, primitive.EncryptionKeyType) if err != nil { return nil, nil, nil, err } sig, err := k.Select(orgID, primitive.SigningKeyType) if err != nil { return nil, nil, nil, err } kp := bundleKeypairs(sig, enc) return sig.PublicKey.ID, enc.PublicKey.ID, kp, nil }
go
func fetchKeyPairs(k *registry.Keypairs, orgID *identity.ID) ( *identity.ID, *identity.ID, *crypto.KeyPairs, error) { enc, err := k.Select(orgID, primitive.EncryptionKeyType) if err != nil { return nil, nil, nil, err } sig, err := k.Select(orgID, primitive.SigningKeyType) if err != nil { return nil, nil, nil, err } kp := bundleKeypairs(sig, enc) return sig.PublicKey.ID, enc.PublicKey.ID, kp, nil }
[ "func", "fetchKeyPairs", "(", "k", "*", "registry", ".", "Keypairs", ",", "orgID", "*", "identity", ".", "ID", ")", "(", "*", "identity", ".", "ID", ",", "*", "identity", ".", "ID", ",", "*", "crypto", ".", "KeyPairs", ",", "error", ")", "{", "enc"...
// fetchKeyPairs fetches and bundles the user's signing and encryption keypairs // from the given keypairs struct
[ "fetchKeyPairs", "fetches", "and", "bundles", "the", "user", "s", "signing", "and", "encryption", "keypairs", "from", "the", "given", "keypairs", "struct" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/utils.go#L350-L365
1,683
manifoldco/torus-cli
daemon/logic/utils.go
findSystemTeams
func findSystemTeams(teams []envelope.Team) (*envelope.Team, *envelope.Team, error) { var members, machines *envelope.Team for _, t := range teams { var team = t if t.Body.TeamType == primitive.SystemTeamType { switch t.Body.Name { case "member": members = &team case "machine": machines = &team } } if members != nil && machines != nil { break } } var errs []string if members == nil { errs = append(errs, "Member team not found.") } if machines == nil { errs = append(errs, "Machine team not found.") } if len(errs) > 0 { return nil, nil, &apitypes.Error{ Err: errs, Type: apitypes.NotFoundError, } } return members, machines, nil }
go
func findSystemTeams(teams []envelope.Team) (*envelope.Team, *envelope.Team, error) { var members, machines *envelope.Team for _, t := range teams { var team = t if t.Body.TeamType == primitive.SystemTeamType { switch t.Body.Name { case "member": members = &team case "machine": machines = &team } } if members != nil && machines != nil { break } } var errs []string if members == nil { errs = append(errs, "Member team not found.") } if machines == nil { errs = append(errs, "Machine team not found.") } if len(errs) > 0 { return nil, nil, &apitypes.Error{ Err: errs, Type: apitypes.NotFoundError, } } return members, machines, nil }
[ "func", "findSystemTeams", "(", "teams", "[", "]", "envelope", ".", "Team", ")", "(", "*", "envelope", ".", "Team", ",", "*", "envelope", ".", "Team", ",", "error", ")", "{", "var", "members", ",", "machines", "*", "envelope", ".", "Team", "\n", "for...
// findSystemTeams takes in a list of team objects and returns the members and machines // teams.
[ "findSystemTeams", "takes", "in", "a", "list", "of", "team", "objects", "and", "returns", "the", "members", "and", "machines", "teams", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/daemon/logic/utils.go#L396-L430
1,684
manifoldco/torus-cli
cmd/profile.go
profileView
func profileView(ctx *cli.Context) error { cfg, err := config.LoadConfig() if err != nil { return err } client := api.NewClient(cfg) c := context.Background() session, err := client.Session.Who(c) if err != nil { return errs.NewErrorExitError("Error fetching user details", err) } printProfile(session) return nil }
go
func profileView(ctx *cli.Context) error { cfg, err := config.LoadConfig() if err != nil { return err } client := api.NewClient(cfg) c := context.Background() session, err := client.Session.Who(c) if err != nil { return errs.NewErrorExitError("Error fetching user details", err) } printProfile(session) return nil }
[ "func", "profileView", "(", "ctx", "*", "cli", ".", "Context", ")", "error", "{", "cfg", ",", "err", ":=", "config", ".", "LoadConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "client", ":=", "api", ".", ...
// profileView is used to view your account profile
[ "profileView", "is", "used", "to", "view", "your", "account", "profile" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/cmd/profile.go#L45-L61
1,685
manifoldco/torus-cli
validate/validate.go
Confirmer
func Confirmer(defaultYes bool) Func { return func(input string) error { if defaultYes { if input == "" || input == "y" || input == "N" { return nil } return NewValidationError("You must specify either 'y' for yes or 'N' for no.") } if input == "" || input == "Y" || input == "n" { return nil } return NewValidationError("You must specify either 'Y' for yes or 'n' for no.") } }
go
func Confirmer(defaultYes bool) Func { return func(input string) error { if defaultYes { if input == "" || input == "y" || input == "N" { return nil } return NewValidationError("You must specify either 'y' for yes or 'N' for no.") } if input == "" || input == "Y" || input == "n" { return nil } return NewValidationError("You must specify either 'Y' for yes or 'n' for no.") } }
[ "func", "Confirmer", "(", "defaultYes", "bool", ")", "Func", "{", "return", "func", "(", "input", "string", ")", "error", "{", "if", "defaultYes", "{", "if", "input", "==", "\"", "\"", "||", "input", "==", "\"", "\"", "||", "input", "==", "\"", "\"",...
// Confirmer returns a confirmation validation function which validates the // input depending on whether or not this prompt is default Yes or No.
[ "Confirmer", "returns", "a", "confirmation", "validation", "function", "which", "validates", "the", "input", "depending", "on", "whether", "or", "not", "this", "prompt", "is", "default", "Yes", "or", "No", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L66-L82
1,686
manifoldco/torus-cli
validate/validate.go
OneOf
func OneOf(choices []string) Func { return func(input string) error { for _, v := range choices { if input == v { return nil } } return NewValidationError(fmt.Sprintf("%s is not a valid option.", input)) } }
go
func OneOf(choices []string) Func { return func(input string) error { for _, v := range choices { if input == v { return nil } } return NewValidationError(fmt.Sprintf("%s is not a valid option.", input)) } }
[ "func", "OneOf", "(", "choices", "[", "]", "string", ")", "Func", "{", "return", "func", "(", "input", "string", ")", "error", "{", "for", "_", ",", "v", ":=", "range", "choices", "{", "if", "input", "==", "v", "{", "return", "nil", "\n", "}", "\...
// OneOf returns a validation function which validates whether or not the input // matches one of the given options.
[ "OneOf", "returns", "a", "validation", "function", "which", "validates", "whether", "or", "not", "the", "input", "matches", "one", "of", "the", "given", "options", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L86-L96
1,687
manifoldco/torus-cli
validate/validate.go
SlugValidator
func SlugValidator(fieldName string) Func { return func(input string) error { if govalidator.StringMatches(input, slugPattern) { return nil } return NewValidationError(fmt.Sprintf(slugErrorPattern, fieldName)) } }
go
func SlugValidator(fieldName string) Func { return func(input string) error { if govalidator.StringMatches(input, slugPattern) { return nil } return NewValidationError(fmt.Sprintf(slugErrorPattern, fieldName)) } }
[ "func", "SlugValidator", "(", "fieldName", "string", ")", "Func", "{", "return", "func", "(", "input", "string", ")", "error", "{", "if", "govalidator", ".", "StringMatches", "(", "input", ",", "slugPattern", ")", "{", "return", "nil", "\n", "}", "\n\n", ...
// SlugValidator returns a validation function
[ "SlugValidator", "returns", "a", "validation", "function" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L99-L107
1,688
manifoldco/torus-cli
validate/validate.go
InviteCode
func InviteCode(input string) error { if govalidator.StringMatches(input, inviteCodePattern) { return nil } return NewValidationError("Please enter a valid invite code. Make sure to copy the entire code from the email!") }
go
func InviteCode(input string) error { if govalidator.StringMatches(input, inviteCodePattern) { return nil } return NewValidationError("Please enter a valid invite code. Make sure to copy the entire code from the email!") }
[ "func", "InviteCode", "(", "input", "string", ")", "error", "{", "if", "govalidator", ".", "StringMatches", "(", "input", ",", "inviteCodePattern", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "NewValidationError", "(", "\"", "\"", ")", "\n", "}...
// InviteCode validates whether the input meets the invite code requirements
[ "InviteCode", "validates", "whether", "the", "input", "meets", "the", "invite", "code", "requirements" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L110-L116
1,689
manifoldco/torus-cli
validate/validate.go
VerificationCode
func VerificationCode(input string) error { if govalidator.StringMatches(input, verifyCodePattern) { return nil } return NewValidationError("Please enter a valid verification code. Make sure to copy the entire code from the email!") }
go
func VerificationCode(input string) error { if govalidator.StringMatches(input, verifyCodePattern) { return nil } return NewValidationError("Please enter a valid verification code. Make sure to copy the entire code from the email!") }
[ "func", "VerificationCode", "(", "input", "string", ")", "error", "{", "if", "govalidator", ".", "StringMatches", "(", "input", ",", "verifyCodePattern", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "NewValidationError", "(", "\"", "\"", ")", "\n"...
// VerificationCode validates whether the input meets the verification code requirements
[ "VerificationCode", "validates", "whether", "the", "input", "meets", "the", "verification", "code", "requirements" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L119-L125
1,690
manifoldco/torus-cli
validate/validate.go
Description
func Description(input, fieldName string) error { if len(input) <= 500 { return nil } return NewValidationError(fieldName + " descriptions must be less than 500 characters") }
go
func Description(input, fieldName string) error { if len(input) <= 500 { return nil } return NewValidationError(fieldName + " descriptions must be less than 500 characters") }
[ "func", "Description", "(", "input", ",", "fieldName", "string", ")", "error", "{", "if", "len", "(", "input", ")", "<=", "500", "{", "return", "nil", "\n", "}", "\n\n", "return", "NewValidationError", "(", "fieldName", "+", "\"", "\"", ")", "\n", "}" ...
// Description validates whether the input meets the descriptin requirements
[ "Description", "validates", "whether", "the", "input", "meets", "the", "descriptin", "requirements" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L128-L134
1,691
manifoldco/torus-cli
validate/validate.go
Name
func Name(input string) error { if govalidator.StringMatches(input, namePattern) { return nil } return NewValidationError(fmt.Sprintf(nameErrorPattern, "Names")) }
go
func Name(input string) error { if govalidator.StringMatches(input, namePattern) { return nil } return NewValidationError(fmt.Sprintf(nameErrorPattern, "Names")) }
[ "func", "Name", "(", "input", "string", ")", "error", "{", "if", "govalidator", ".", "StringMatches", "(", "input", ",", "namePattern", ")", "{", "return", "nil", "\n", "}", "\n\n", "return", "NewValidationError", "(", "fmt", ".", "Sprintf", "(", "nameErro...
// Name validates whether the input meets first name last name requirements
[ "Name", "validates", "whether", "the", "input", "meets", "first", "name", "last", "name", "requirements" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L146-L152
1,692
manifoldco/torus-cli
validate/validate.go
Password
func Password(input string) error { length := len(input) if length >= 8 { return nil } if length > 0 { return NewValidationError("Passwords must be at least 8 characters") } return NewValidationError("Please enter a password") }
go
func Password(input string) error { length := len(input) if length >= 8 { return nil } if length > 0 { return NewValidationError("Passwords must be at least 8 characters") } return NewValidationError("Please enter a password") }
[ "func", "Password", "(", "input", "string", ")", "error", "{", "length", ":=", "len", "(", "input", ")", "\n", "if", "length", ">=", "8", "{", "return", "nil", "\n", "}", "\n", "if", "length", ">", "0", "{", "return", "NewValidationError", "(", "\"",...
// Password ensures the input meets password requirements
[ "Password", "ensures", "the", "input", "meets", "password", "requirements" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L155-L165
1,693
manifoldco/torus-cli
validate/validate.go
ConfirmPassword
func ConfirmPassword(previous string) Func { return func(input string) error { err := Password(input) if err != nil { return err } if input != previous { return NewValidationError("The password you provided does not match the previous password you provided!") } return nil } }
go
func ConfirmPassword(previous string) Func { return func(input string) error { err := Password(input) if err != nil { return err } if input != previous { return NewValidationError("The password you provided does not match the previous password you provided!") } return nil } }
[ "func", "ConfirmPassword", "(", "previous", "string", ")", "Func", "{", "return", "func", "(", "input", "string", ")", "error", "{", "err", ":=", "Password", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", ...
// ConfirmPassword ensures the input meets the password requirements and // matches the previously provided password
[ "ConfirmPassword", "ensures", "the", "input", "meets", "the", "password", "requirements", "and", "matches", "the", "previously", "provided", "password" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/validate/validate.go#L169-L182
1,694
manifoldco/torus-cli
pathexp/pathexp.go
GlobContains
func GlobContains(value, subject string) bool { gl := glob(value) return gl.Contains(subject) }
go
func GlobContains(value, subject string) bool { gl := glob(value) return gl.Contains(subject) }
[ "func", "GlobContains", "(", "value", ",", "subject", "string", ")", "bool", "{", "gl", ":=", "glob", "(", "value", ")", "\n", "return", "gl", ".", "Contains", "(", "subject", ")", "\n", "}" ]
// GlobContains returns whether a glob, built from the value, contains the subject
[ "GlobContains", "returns", "whether", "a", "glob", "built", "from", "the", "value", "contains", "the", "subject" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L92-L95
1,695
manifoldco/torus-cli
pathexp/pathexp.go
compareSegmentType
func compareSegmentType(a, b segment) int { segs := []segment{a, b} ranks := make([]int, 2) for i, seg := range segs { switch seg.(type) { case literal: ranks[i] = 3 case glob: ranks[i] = 2 case alternation: ranks[i] = 1 case fullglob: ranks[i] = 0 default: panic("Bad type for segment!") } } switch { case ranks[0] < ranks[1]: return -1 case ranks[0] > ranks[1]: return 1 default: return 0 } }
go
func compareSegmentType(a, b segment) int { segs := []segment{a, b} ranks := make([]int, 2) for i, seg := range segs { switch seg.(type) { case literal: ranks[i] = 3 case glob: ranks[i] = 2 case alternation: ranks[i] = 1 case fullglob: ranks[i] = 0 default: panic("Bad type for segment!") } } switch { case ranks[0] < ranks[1]: return -1 case ranks[0] > ranks[1]: return 1 default: return 0 } }
[ "func", "compareSegmentType", "(", "a", ",", "b", "segment", ")", "int", "{", "segs", ":=", "[", "]", "segment", "{", "a", ",", "b", "}", "\n", "ranks", ":=", "make", "(", "[", "]", "int", ",", "2", ")", "\n", "for", "i", ",", "seg", ":=", "r...
// compareSegmentType ranks the segments by their type specificity
[ "compareSegmentType", "ranks", "the", "segments", "by", "their", "type", "specificity" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L136-L162
1,696
manifoldco/torus-cli
pathexp/pathexp.go
New
func New(org, project string, envs, services, identities, instances []string) (*PathExp, error) { return newPathexp(org, project, envs, services, identities, instances, true) }
go
func New(org, project string, envs, services, identities, instances []string) (*PathExp, error) { return newPathexp(org, project, envs, services, identities, instances, true) }
[ "func", "New", "(", "org", ",", "project", "string", ",", "envs", ",", "services", ",", "identities", ",", "instances", "[", "]", "string", ")", "(", "*", "PathExp", ",", "error", ")", "{", "return", "newPathexp", "(", "org", ",", "project", ",", "en...
// New creates a new path expression from the given path segments // It returns an error if any of the values fail to validate // and it must contain all relevant parts
[ "New", "creates", "a", "new", "path", "expression", "from", "the", "given", "path", "segments", "It", "returns", "an", "error", "if", "any", "of", "the", "values", "fail", "to", "validate", "and", "it", "must", "contain", "all", "relevant", "parts" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L207-L209
1,697
manifoldco/torus-cli
pathexp/pathexp.go
NewPartial
func NewPartial(org, project string, envs, services, identities, instances []string) (*PathExp, error) { return newPathexp(org, project, envs, services, identities, instances, false) }
go
func NewPartial(org, project string, envs, services, identities, instances []string) (*PathExp, error) { return newPathexp(org, project, envs, services, identities, instances, false) }
[ "func", "NewPartial", "(", "org", ",", "project", "string", ",", "envs", ",", "services", ",", "identities", ",", "instances", "[", "]", "string", ")", "(", "*", "PathExp", ",", "error", ")", "{", "return", "newPathexp", "(", "org", ",", "project", ","...
// NewPartial creates a new path expression from the given path segments // It returns an error if any of the values fail to validate // but does not require any segments
[ "NewPartial", "creates", "a", "new", "path", "expression", "from", "the", "given", "path", "segments", "It", "returns", "an", "error", "if", "any", "of", "the", "values", "fail", "to", "validate", "but", "does", "not", "require", "any", "segments" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L214-L216
1,698
manifoldco/torus-cli
pathexp/pathexp.go
Split
func Split(name, segment string) ([]string, error) { parts := []string{segment} if len(segment) == 0 { return parts, nil // let elsewhere handle the empty single segment } if segment[0] == '[' && segment[len(segment)-1] == ']' { parts = strings.Split(segment[1:len(segment)-1], "|") // zero length is checked in parseMultiple if len(parts) == 1 { return nil, errors.New("Single item in segment alternation for " + name + ".") } } return parts, nil }
go
func Split(name, segment string) ([]string, error) { parts := []string{segment} if len(segment) == 0 { return parts, nil // let elsewhere handle the empty single segment } if segment[0] == '[' && segment[len(segment)-1] == ']' { parts = strings.Split(segment[1:len(segment)-1], "|") // zero length is checked in parseMultiple if len(parts) == 1 { return nil, errors.New("Single item in segment alternation for " + name + ".") } } return parts, nil }
[ "func", "Split", "(", "name", ",", "segment", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "parts", ":=", "[", "]", "string", "{", "segment", "}", "\n\n", "if", "len", "(", "segment", ")", "==", "0", "{", "return", "parts", ","...
// Split separates alternation
[ "Split", "separates", "alternation" ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L435-L451
1,699
manifoldco/torus-cli
pathexp/pathexp.go
Equal
func (pe *PathExp) Equal(other *PathExp) bool { switch { case pe.Org != other.Org: return false case pe.Project != other.Project: return false case !segmentsEqual(pe.Envs, other.Envs): return false case !segmentsEqual(pe.Services, other.Services): return false case !segmentsEqual(pe.Identities, other.Identities): return false case !segmentsEqual(pe.Instances, other.Instances): return false default: return true } }
go
func (pe *PathExp) Equal(other *PathExp) bool { switch { case pe.Org != other.Org: return false case pe.Project != other.Project: return false case !segmentsEqual(pe.Envs, other.Envs): return false case !segmentsEqual(pe.Services, other.Services): return false case !segmentsEqual(pe.Identities, other.Identities): return false case !segmentsEqual(pe.Instances, other.Instances): return false default: return true } }
[ "func", "(", "pe", "*", "PathExp", ")", "Equal", "(", "other", "*", "PathExp", ")", "bool", "{", "switch", "{", "case", "pe", ".", "Org", "!=", "other", ".", "Org", ":", "return", "false", "\n", "case", "pe", ".", "Project", "!=", "other", ".", "...
// Equal returns a bool indicating if the two PathExps are equivalent.
[ "Equal", "returns", "a", "bool", "indicating", "if", "the", "two", "PathExps", "are", "equivalent", "." ]
137599f985e6f676c081ffb4230aaad52fb7d26c
https://github.com/manifoldco/torus-cli/blob/137599f985e6f676c081ffb4230aaad52fb7d26c/pathexp/pathexp.go#L497-L515