CreateNamespaceInternal creates a new namespace. Only superadmin is authorized to do so. Authorization is handled by middlewares.
(ctx context.Context, passwd string)
| 83 | // CreateNamespaceInternal creates a new namespace. Only superadmin is authorized to do so. |
| 84 | // Authorization is handled by middlewares. |
| 85 | func (s *Server) CreateNamespaceInternal(ctx context.Context, passwd string) (uint64, error) { |
| 86 | glog.V(2).Info("Got create namespace request.") |
| 87 | |
| 88 | num := &pb.Num{Val: 1, Type: pb.Num_NS_ID} |
| 89 | ids, err := worker.AssignNsIdsOverNetwork(ctx, num) |
| 90 | if err != nil { |
| 91 | return 0, errors.Wrapf(err, "Creating namespace, got error:") |
| 92 | } |
| 93 | |
| 94 | ns := ids.StartId |
| 95 | glog.V(2).Infof("Got a lease for NsID: %d", ns) |
| 96 | |
| 97 | // Attach the newly leased NsID in the context in order to create guardians/groot for it. |
| 98 | ctx = x.AttachNamespace(ctx, ns) |
| 99 | m := &pb.Mutations{StartTs: worker.State.GetTimestamp(false)} |
| 100 | m.Schema = schema.InitialSchema(ns) |
| 101 | m.Types = schema.InitialTypes(ns) |
| 102 | _, err = query.ApplyMutations(ctx, m) |
| 103 | if err != nil { |
| 104 | return 0, err |
| 105 | } |
| 106 | |
| 107 | err = x.RetryUntilSuccess(10, 100*time.Millisecond, func() error { |
| 108 | return createGuardianAndGroot(ctx, passwd) |
| 109 | }) |
| 110 | if err != nil { |
| 111 | return 0, errors.Wrapf(err, "Failed to create guardian and groot: ") |
| 112 | } |
| 113 | |
| 114 | glog.V(2).Infof("Created namespace: %d", ns) |
| 115 | return ns, nil |
| 116 | } |
| 117 | |
| 118 | // This function is used while creating new namespace. New namespace creation is only allowed |
| 119 | // by the guardians of the galaxy group. |
no test coverage detected