lxd/rbac/server.go
func (r *Server) SyncProjects() error {
	if r.ProjectsFunc == nil {
		return fmt.Errorf("ProjectsFunc isn't configured yet, cannot sync")
	}

	resources := []rbacResource{}
	resourcesMap := map[string]string{}

	// Get all projects
	projects, err := r.ProjectsFunc()
	if err != nil {
		return err
	}

	// Convert to RBAC format
	for id, name := range projects {
		resources = append(resources, rbacResource{
			Name:       name,
			Identifier: strconv.FormatInt(id, 10),
		})

		resourcesMap[name] = strconv.FormatInt(id, 10)
	}

	// Update RBAC
	err = r.postResources(resources, nil, true)
	if err != nil {
		return err
	}

	// Update project map
	r.resourcesLock.Lock()
	r.resources = resourcesMap
	r.resourcesLock.Unlock()

	return nil
}
func (r *Server) SyncProjects() error {
	if r.ProjectsFunc == nil {
		return fmt.Errorf("ProjectsFunc isn't configured yet, cannot sync")
	}

	resources := []rbacResource{}
	resourcesMap := map[string]string{}

	// Get all projects
	projects, err := r.ProjectsFunc()
	if err != nil {
		return err
	}

	// Convert to RBAC format
	for id, name := range projects {
		resources = append(resources, rbacResource{
			Name:       name,
			Identifier: strconv.FormatInt(id, 10),
		})

		resourcesMap[name] = strconv.FormatInt(id, 10)
	}

	// Update RBAC
	err = r.postResources(resources, nil, true)
	if err != nil {
		return err
	}

	// Update project map
	r.resourcesLock.Lock()
	r.resources = resourcesMap
	r.resourcesLock.Unlock()

	return nil
}
func ( r * Server ) SyncProjects ( ) error { if r . ProjectsFunc == nil { return fmt . Errorf ( " " ) } resources := [ ] rbacResource { } resourcesMap := map [ string ] string { } // Get all projects projects , err := r . ProjectsFunc ( ) if err != nil { return err } // Convert to RBAC format for id , name := range projects { resources = append ( resources , rbacResource { Name : name , Identifier : strconv . FormatInt ( id , 10 ) , } ) resourcesMap [ name ] = strconv . FormatInt ( id , 10 ) } // Update RBAC err = r . postResources ( resources , nil , true ) if err != nil { return err } // Update project map r . resourcesLock . Lock ( ) r . resources = resourcesMap r . resourcesLock . Unlock ( ) return nil }
// SyncProjects updates the list of projects in RBAC
SyncProjects updates the list of projects in RBAC