Coverage for nova/policies/limits.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

1# Copyright 2016 Cloudbase Solutions Srl 

2# All Rights Reserved. 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); you may 

5# not use this file except in compliance with the License. You may obtain 

6# a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

13# License for the specific language governing permissions and limitations 

14# under the License. 

15 

16from oslo_policy import policy 

17 

18from nova.policies import base 

19 

20 

21BASE_POLICY_NAME = 'os_compute_api:limits' 

22OTHER_PROJECT_LIMIT_POLICY_NAME = 'os_compute_api:limits:other_project' 

23 

24DEPRECATED_REASON = """ 

25Nova API policies are introducing new default roles with scope_type 

26capabilities. Old policies are deprecated and silently going to be ignored 

27in nova 23.0.0 release. 

28""" 

29 

30DEPRECATED_POLICY = policy.DeprecatedRule( 

31 'os_compute_api:os-used-limits', 

32 base.RULE_ADMIN_API, 

33 deprecated_reason=DEPRECATED_REASON, 

34 deprecated_since='21.0.0' 

35) 

36 

37limits_policies = [ 

38 policy.DocumentedRuleDefault( 

39 name=BASE_POLICY_NAME, 

40 check_str=base.RULE_ANY, 

41 description="Show rate and absolute limits for the current user " 

42 "project", 

43 operations=[ 

44 { 

45 'method': 'GET', 

46 'path': '/limits' 

47 } 

48 ], 

49 scope_types=['project']), 

50 policy.DocumentedRuleDefault( 

51 name=OTHER_PROJECT_LIMIT_POLICY_NAME, 

52 check_str=base.ADMIN, 

53 description="""Show rate and absolute limits of other project. 

54 

55This policy only checks if the user has access to the requested 

56project limits. And this check is performed only after the check 

57os_compute_api:limits passes""", 

58 operations=[ 

59 { 

60 'method': 'GET', 

61 'path': '/limits' 

62 } 

63 ], 

64 scope_types=['project'], 

65 deprecated_rule=DEPRECATED_POLICY), 

66] 

67 

68 

69def list_rules(): 

70 return limits_policies