// workspaces returns a filtered list of remote workspace names.
329835
func (b *Remote) workspaces() ([]string, error) {
	options := tfe.WorkspaceListOptions{}
	switch {
	case b.workspace != "":
		options.Search = tfe.String(b.workspace)
	case b.prefix != "":
		options.Search = tfe.String(b.prefix)
	}

	// Create a slice to contain all the names.
	var names []string

	for {
		wl, err := b.client.Workspaces.List(context.Background(), b.organization, options)
		if err != nil {
			return nil, err
		}

		for _, w := range wl.Items {
			if b.workspace != "" && w.Name == b.workspace {
				names = append(names, backend.DefaultStateName)
				continue
			}
			if b.prefix != "" && strings.HasPrefix(w.Name, b.prefix) {
				names = append(names, strings.TrimPrefix(w.Name, b.prefix))
			}
		}

		// Exit the loop when we've seen all pages.
		if wl.CurrentPage >= wl.TotalPages {
			break
		}

		// Update the page number to get the next page.
		options.PageNumber = wl.NextPage
	}

	// Sort the result so we have consistent output.
	sort.StringSlice(names).Sort()

	return names, nil
}
1274589
func (api *spacesAPI) CreateSpaces(args params.CreateSpacesParams) (results params.ErrorResults, err error) {
	isAdmin, err := api.authorizer.HasPermission(permission.AdminAccess, api.backing.ModelTag())
	if err != nil && !errors.IsNotFound(err) {
		return results, errors.Trace(err)
	}
	if !isAdmin {
		return results, common.ServerError(common.ErrPerm)
	}

	return networkingcommon.CreateSpaces(api.backing, api.context, args)
}
777696
func (ts *Server) GetKeyspaces(ctx context.Context) ([]string, error) {
	children, err := ts.globalCell.ListDir(ctx, KeyspacesPath, false /*full*/)
	switch {
	case err == nil:
		return DirEntriesToStringArray(children), nil
	case IsErrType(err, NoNode):
		return nil, nil
	default:
		return nil, err
	}
}
123535
func initWorkspaceForProjectPath(projectPath string, isAllowReset bool) error {
	log.Debug("[Init] Initializing Workspace & Config ...")

	gowsWorspacesRootDirAbsPath, err := config.GOWSWorspacesRootDirAbsPath()
	if err != nil {
		return fmt.Errorf("Failed to get absolute path for gows workspaces root dir, error: %s", err)
	}

	// Create the Workspace
	gowsConfig, err := config.LoadGOWSConfigFromFile()
	if err != nil {
		return fmt.Errorf("Failed to load gows config: %s", err)
	}

	projectWorkspaceAbsPath := ""
	wsConfig, isFound := gowsConfig.WorkspaceForProjectLocation(projectPath)
	if isFound {
		if wsConfig.WorkspaceRootPath == "" {
			return fmt.Errorf("A workspace is found for this project (path: %s), but the workspace root directory path is not defined", projectPath)
		}
		projectWorkspaceAbsPath = wsConfig.WorkspaceRootPath

		if isAllowReset {
			if err := os.RemoveAll(projectWorkspaceAbsPath); err != nil {
				return fmt.Errorf("Failed to delete previous workspace at path: %s", projectWorkspaceAbsPath)
			}
			// init a new one
			projectWorkspaceAbsPath = ""
		} else {
			log.Warning(colorstring.Yellow("A workspace already exists for this project") + " (" + projectWorkspaceAbsPath + "), will be reused.")
			log.Warning("If you want to delete the previous workspace of this project and generate a new one you should run: " + colorstring.Green("gows clear"))
		}
	}

	if projectWorkspaceAbsPath == "" {
		// generate one
		projectBaseWorkspaceDirName := fmt.Sprintf("%s-%d", filepath.Base(projectPath), time.Now().Unix())
		projectWorkspaceAbsPath = filepath.Join(gowsWorspacesRootDirAbsPath, projectBaseWorkspaceDirName)
	}

	log.Debugf("  projectWorkspaceAbsPath: %s", projectWorkspaceAbsPath)
	if err := initGoWorkspaceAtPath(projectWorkspaceAbsPath); err != nil {
		return fmt.Errorf("Failed to initialize workspace at path: %s", projectWorkspaceAbsPath)
	}
	log.Debugf("  Workspace successfully created")

	// Save the location into Workspace config
	{
		workspaceConf := config.WorkspaceConfigModel{
			WorkspaceRootPath: projectWorkspaceAbsPath,
		}
		gowsConfig.Workspaces[projectPath] = workspaceConf

		if err := config.SaveGOWSConfigToFile(gowsConfig); err != nil {
			return fmt.Errorf("Failed to save gows config: %s", err)
		}
	}
	log.Debug("[Init] Workspace Config saved")

	return nil
}
900749
func (api *API) ListSpaces() ([]params.Space, error) {
	var response params.ListSpacesResults
	err := api.facade.FacadeCall("ListSpaces", nil, &response)
	if params.IsCodeNotSupported(err) {
		return response.Results, errors.NewNotSupported(nil, err.Error())
	}
	return response.Results, err
}
532833
func (v *version) Namespaces() NamespaceInformer {
	return &namespaceInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
1038578
func newWorkflows(c *ArgoprojV1alpha1Client, namespace string) *workflows {
	return &workflows{
		client: c.RESTClient(),
		ns:     namespace,
	}
}
524012
func (s *leaseLister) Leases(namespace string) LeaseNamespaceLister {
	return leaseNamespaceLister{indexer: s.indexer, namespace: namespace}
}
559710
func ListNamespaces() ([]HostComputeNamespace, error) {
	hcnQuery := defaultQuery()
	namespaces, err := ListNamespacesQuery(hcnQuery)
	if err != nil {
		return nil, err
	}
	return namespaces, nil
}
919670
func (m *Machine) AllSpaces() (set.Strings, error) {
	// TODO(jam): 2016-12-18 This should evolve to look at the
	// LinkLayerDevices directly, instead of using the Addresses the devices
	// are in to link back to spaces.
	spaces := set.NewStrings()
	addresses, err := m.AllAddresses()
	if err != nil {
		return nil, errors.Trace(err)
	}
	for _, address := range addresses {
		subnet, err := address.Subnet()
		if err != nil {
			if errors.IsNotFound(err) {
				// We don't know what this subnet is, so it can't be a space. It
				// might just be the loopback device.
				continue
			}
			return nil, errors.Trace(err)
		}
		spaceName := subnet.SpaceName()
		if spaceName != "" {
			spaces.Add(spaceName)
		}
	}
	logger.Tracef("machine %q found AllSpaces() = %s",
		m.Id(), network.QuoteSpaceSet(spaces))
	return spaces, nil
}
719878
func (r *RoleV3) SetNamespaces(rct RoleConditionType, namespaces []string) {
	ncopy := utils.CopyStrings(namespaces)

	if rct == Allow {
		r.Spec.Allow.Namespaces = ncopy
	} else {
		r.Spec.Deny.Namespaces = ncopy
	}
}
989546
func (client *Client) GetSpaces(filters ...Filter) ([]Space, Warnings, error) {
	params := ConvertFilterParameters(filters)
	params.Add("order-by", "name")
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetSpacesRequest,
		Query:       params,
	})
	if err != nil {
		return nil, nil, err
	}

	var fullSpacesList []Space
	warnings, err := client.paginate(request, Space{}, func(item interface{}) error {
		if space, ok := item.(Space); ok {
			fullSpacesList = append(fullSpacesList, space)
		} else {
			return ccerror.UnknownObjectInListError{
				Expected:   Space{},
				Unexpected: item,
			}
		}
		return nil
	})

	return fullSpacesList, warnings, err
}
729191
func (c *Cluster) AllWorkloads(namespace string) (res []cluster.Workload, err error) {
	namespaces, err := c.getAllowedAndExistingNamespaces()
	if err != nil {
		return nil, errors.Wrap(err, "getting namespaces")
	}

	var allworkloads []cluster.Workload
	for _, ns := range namespaces {
		if namespace != "" && ns.Name != namespace {
			continue
		}

		for kind, resourceKind := range resourceKinds {
			workloads, err := resourceKind.getWorkloads(c, ns.Name)
			if err != nil {
				switch {
				case apierrors.IsNotFound(err):
					// Kind not supported by API server, skip
					continue
				case apierrors.IsForbidden(err):
					// K8s can return forbidden instead of not found for non super admins
					c.logger.Log("warning", "not allowed to list resources", "err", err)
					continue
				default:
					return nil, err
				}
			}

			for _, workload := range workloads {
				if !isAddon(workload) {
					id := flux.MakeResourceID(ns.Name, kind, workload.GetName())
					c.muSyncErrors.RLock()
					workload.syncError = c.syncErrors[id]
					c.muSyncErrors.RUnlock()
					allworkloads = append(allworkloads, workload.toClusterWorkload(id))
				}
			}
		}
	}

	return allworkloads, nil
}
161143
func (e *environ) Spaces(ctx context.ProviderCallContext) ([]network.SpaceInfo, error) {
	return nil, errors.NotSupportedf("Spaces")
}
278849
func (l *dynamicLister) Namespace(namespace string) NamespaceLister {
	return &dynamicNamespaceLister{indexer: l.indexer, namespace: namespace, gvr: l.gvr}
}
708588
func ConvertNamespaceList(namespaceList *corev1.NamespaceList) *projectapi.ProjectList {
	projects := &projectapi.ProjectList{}
	for _, n := range namespaceList.Items {
		projects.Items = append(projects.Items, *ConvertNamespaceFromExternal(&n))
	}
	return projects
}
27651
func (b *Remote) DeleteWorkspace(name string) error {
	if b.workspace == "" && name == backend.DefaultStateName {
		return backend.ErrDefaultWorkspaceNotSupported
	}
	if b.prefix == "" && name != backend.DefaultStateName {
		return backend.ErrWorkspacesNotSupported
	}

	// Configure the remote workspace name.
	switch {
	case name == backend.DefaultStateName:
		name = b.workspace
	case b.prefix != "" && !strings.HasPrefix(name, b.prefix):
		name = b.prefix + name
	}

	client := &remoteClient{
		client:       b.client,
		organization: b.organization,
		workspace: &tfe.Workspace{
			Name: name,
		},
	}

	return client.Delete()
}