github.com/Lephar/snapd@v0.0.0-20210825215435-c7fba9cef4d2/overlord/servicestate/quotas.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2021 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package servicestate
    21  
    22  import (
    23  	"errors"
    24  
    25  	"github.com/snapcore/snapd/overlord/servicestate/internal"
    26  	"github.com/snapcore/snapd/overlord/state"
    27  	"github.com/snapcore/snapd/snap/quota"
    28  )
    29  
    30  var ErrQuotaNotFound = errors.New("quota not found")
    31  
    32  // AllQuotas returns all currently tracked quota groups in the state. They are
    33  // validated for consistency using ResolveCrossReferences before being returned.
    34  func AllQuotas(st *state.State) (map[string]*quota.Group, error) {
    35  	return internal.AllQuotas(st)
    36  }
    37  
    38  // GetQuota returns an individual quota group by name.
    39  func GetQuota(st *state.State, name string) (*quota.Group, error) {
    40  	allGrps, err := internal.AllQuotas(st)
    41  	if err != nil {
    42  		return nil, err
    43  	}
    44  
    45  	group, ok := allGrps[name]
    46  	if !ok {
    47  		return nil, ErrQuotaNotFound
    48  	}
    49  
    50  	return group, nil
    51  }