func putUser(tx backend.BatchTx, user *authpb.User) { b, err := user.Marshal() if err != nil { plog.Panicf("failed to marshal user struct (name: %s): %s", user.Name, err) } tx.UnsafePut(authUsersBucketName, user.Name, b) }
func getRevision(tx backend.BatchTx) uint64 { _, vs := tx.UnsafeRange(authBucketName, []byte(revisionKey), nil, 0) if len(vs) != 1 { plog.Panicf("failed to get the key of auth store revision") } return binary.BigEndian.Uint64(vs[0]) }
func putRole(tx backend.BatchTx, role *authpb.Role) { b, err := role.Marshal() if err != nil { plog.Panicf("failed to marshal role struct (name: %s): %s", role.Name, err) } tx.UnsafePut(authRolesBucketName, []byte(role.Name), b) }
func getRole(tx backend.BatchTx, rolename string) *authpb.Role { _, vs := tx.UnsafeRange(authRolesBucketName, []byte(rolename), nil, 0) if len(vs) == 0 { return nil } role := &authpb.Role{} err := role.Unmarshal(vs[0]) if err != nil { plog.Panicf("failed to unmarshal role struct (name: %s): %s", rolename, err) } return role }
func getUser(tx backend.BatchTx, username string) *authpb.User { _, vs := tx.UnsafeRange(authUsersBucketName, []byte(username), nil, 0) if len(vs) == 0 { return nil } user := &authpb.User{} err := user.Unmarshal(vs[0]) if err != nil { plog.Panicf("failed to unmarshal user struct (name: %s): %s", username, err) } return user }
func getAllRoles(tx backend.BatchTx) []*authpb.Role { _, vs := tx.UnsafeRange(authRolesBucketName, []byte{0}, []byte{0xff}, -1) if len(vs) == 0 { return nil } var roles []*authpb.Role for _, v := range vs { role := &authpb.Role{} err := role.Unmarshal(v) if err != nil { plog.Panicf("failed to unmarshal role struct: %s", err) } roles = append(roles, role) } return roles }
func getAllUsers(tx backend.BatchTx) []*authpb.User { _, vs := tx.UnsafeRange(authUsersBucketName, []byte{0}, []byte{0xff}, -1) if len(vs) == 0 { return nil } var users []*authpb.User for _, v := range vs { user := &authpb.User{} err := user.Unmarshal(v) if err != nil { plog.Panicf("failed to unmarshal user struct: %s", err) } users = append(users, user) } return users }
func (as *authStore) commitRevision(tx backend.BatchTx) { as.revision++ revBytes := make([]byte, revBytesLen) binary.BigEndian.PutUint64(revBytes, as.revision) tx.UnsafePut(authBucketName, revisionKey, revBytes) }
func delRole(tx backend.BatchTx, rolename string) { tx.UnsafeDelete(authRolesBucketName, []byte(rolename)) }
func delUser(tx backend.BatchTx, username string) { tx.UnsafeDelete(authUsersBucketName, []byte(username)) }