Example #1
0
// If the namespace being created is a root namespace, only the admin account can create it
func (e *Executor) handleCreateRootNamespace(w *common.ResponseWriter, stmt *skl.CreateNamespaceStatement, store datamodel.NamespaceStore) {

	// Get namespace
	name := stmt.Namespace()

	// Verify namespace existance
	_, err := store.Get(name)

	// If err == nil, the namespace already exists
	if err == nil {
		w.Success(common.NamespaceAlreadyExists, name)
		return
	}

	// Get session user
	user := e.session.user
	if user.IsAdmin() {

		// Create new namespace
		_, err := store.Create(name)

		// If err !+ nil, namespace could not be created
		if err != nil {
			w.Fail(common.CreateNamespaceError, "could not create namespace '%s'", name)
			return
		}

		// No error == success
		w.Success(common.OK, "namespace created")
		return
	}

	// Otherwise fail creation
	w.Fail(common.Unauthorized, "root namespaces can only be created by the admin account")
	return
}
Example #2
0
// namespaceAlreadyExists determines if a namespace already exists...
func (e *Executor) namespaceAlreadyExists(namespace string, store datamodel.NamespaceStore) bool {
	_, err := store.Get(namespace)
	return err == nil
}