1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

client: Add server-side filtering for profiles

Signed-off-by: Abdulrahman Alshahrani <abdulrahmanalshahrani@utexas.edu>
This commit is contained in:
Abdulrahman Alshahrani
2025-04-23 13:06:57 -05:00
committed by Stéphane Graber
parent 61c622e9f1
commit b1be552ba0
2 changed files with 40 additions and 0 deletions

View File

@@ -36,6 +36,22 @@ func (r *ProtocolIncus) GetProfiles() ([]api.Profile, error) {
return profiles, nil
}
// GetProfilesWithFilter returns a filtered list of available Profile structs.
func (r *ProtocolIncus) GetProfilesWithFilter(filters []string) ([]api.Profile, error) {
profiles := []api.Profile{}
v := url.Values{}
v.Set("recursion", "1")
v.Set("filter", parseFilters(filters))
_, err := r.queryStruct("GET", fmt.Sprintf("/profiles?%s", v.Encode()), nil, "", &profiles)
if err != nil {
return nil, err
}
return profiles, nil
}
// GetProfilesAllProjects returns a list of profiles across all projects as Profile structs.
func (r *ProtocolIncus) GetProfilesAllProjects() ([]api.Profile, error) {
err := r.CheckExtension("profiles_all_projects")
@@ -52,6 +68,28 @@ func (r *ProtocolIncus) GetProfilesAllProjects() ([]api.Profile, error) {
return profiles, nil
}
// GetProfilesAllProjectsWithFilter returns a filtered list of profiles across all projects as Profile structs.
func (r *ProtocolIncus) GetProfilesAllProjectsWithFilter(filters []string) ([]api.Profile, error) {
err := r.CheckExtension("profiles_all_projects")
if err != nil {
return nil, fmt.Errorf(`The server is missing the required "profiles_all_projects" API extension`)
}
profiles := []api.Profile{}
v := url.Values{}
v.Set("recursion", "1")
v.Set("all-projects", "true")
v.Set("filter", parseFilters(filters))
_, err = r.queryStruct("GET", fmt.Sprintf("/profiles?%s", v.Encode()), nil, "", &profiles)
if err != nil {
return nil, err
}
return profiles, nil
}
// GetProfile returns a Profile entry for the provided name.
func (r *ProtocolIncus) GetProfile(name string) (*api.Profile, string, error) {
profile := api.Profile{}

View File

@@ -290,8 +290,10 @@ type InstanceServer interface {
// Profile functions
GetProfilesAllProjects() (profiles []api.Profile, err error)
GetProfilesAllProjectsWithFilter(filters []string) ([]api.Profile, error)
GetProfileNames() (names []string, err error)
GetProfiles() (profiles []api.Profile, err error)
GetProfilesWithFilter(filters []string) ([]api.Profile, error)
GetProfile(name string) (profile *api.Profile, ETag string, err error)
CreateProfile(profile api.ProfilesPost) (err error)
UpdateProfile(name string, profile api.ProfilePut, ETag string) (err error)