Skip to content

Commit 2fa97f1

Browse files
committed
Add In Some Actions
1 parent caafede commit 2fa97f1

File tree

3 files changed

+59
-39
lines changed

3 files changed

+59
-39
lines changed

.github/workflows/pull-request.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Unikorn Push
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- synchronize
7+
- reopened
8+
- ready_for_review
9+
jobs:
10+
Static:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
- name: Install Prerequisites
16+
run: pip3 install pylint build
17+
- name: Build
18+
run: python3 -m build
19+
- name: Install
20+
# TODO: make this dynamic somehow by reading out from the toml.
21+
run: pip3 install --upgrade dist/python_unikorn_openstack_policy-0.1.0-py3-none-any.whl
22+
- name: Pylint
23+
run: pylint unikorn_openstack_policy

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ Oslo policy generation and testing framework.
1515
1616
```bash
1717
python3 -m build
18-
pip3 install --upgrade dist/python_unikorn_openstack_policy-0.1.0-py3-none-any.whl
18+
pip3 install dist/python_unikorn_openstack_policy-0.1.0-py3-none-any.whl
1919
```
2020

2121
## Generating Policy Files
2222

2323
```bash
2424
oslopolicy-sample-generator --namespace unikorn_openstack_policy
2525
```
26+
27+
## Coding Standards
28+
29+
You require 10/10 when running:
30+
31+
```bash
32+
pylint unikorn_openstack_policy
33+
```

unikorn_openstack_policy/policy.py

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,10 @@
1818

1919
# pylint: disable=line-too-long
2020

21-
from neutron.conf.policies import base
21+
from neutron.conf.policies import base, network
2222
from oslo_policy import policy
2323

2424
rules = [
25-
# Base rule definitions must be exact copies of the base poilicy.
26-
policy.RuleDefault(
27-
name='base_create_network',
28-
check_str=base.ADMIN_OR_PROJECT_MEMBER,
29-
description='Create a network',
30-
),
31-
policy.RuleDefault(
32-
name='base_create_network:segments',
33-
check_str=base.ADMIN,
34-
description='Specify ``segments`` attribute when creating a network',
35-
),
36-
policy.RuleDefault(
37-
name='base_create_network:provider:network_type',
38-
check_str=base.ADMIN,
39-
description='Specify ``provider:network_type`` when creating a network',
40-
),
41-
policy.RuleDefault(
42-
name='base_create_network:provider:physical_network',
43-
check_str=base.ADMIN,
44-
description='Specify ``provider:physical_network`` when creating a network',
45-
),
46-
policy.RuleDefault(
47-
name='base_create_network:provider:segmentation_id',
48-
check_str=base.ADMIN,
49-
description='Specify ``provider:segmentation_id`` when creating a network',
50-
),
51-
policy.RuleDefault(
52-
name='base_delete_network',
53-
check_str=base.ADMIN_OR_PROJECT_MEMBER,
54-
description='Delete a network',
55-
),
56-
5725
# The domain manager has the role 'manager', as defined by
5826
# https://docs.scs.community/standards/scs-0302-v1-domain-manager-role/
5927
policy.RuleDefault(
@@ -63,6 +31,9 @@
6331
),
6432

6533
# The domain manager can create and delete networks in its domain.
34+
# If the domain manager is able to create a network, it can also create provider networks.
35+
# Don't be naive enough here to assume the ability to provision a network is enough to
36+
# allow provider networks, if the prior rule changes, then we can open up a security hole.
6637
policy.RuleDefault(
6738
name='create_network',
6839
check_str='(rule:is_domain_manager and domain_id:%(domain_id)s) or rule:base_create_network',
@@ -73,10 +44,6 @@
7344
check_str='(rule:is_domain_manager and domain_id:%(domain_id)s) or rule:base_delete_network',
7445
description='Delete a network',
7546
),
76-
77-
# If the domain manager is able to create a network, it can also create provider networks.
78-
# Don't be naive enough here to assume the ability to provision a network is enough to
79-
# allow provider networks, if the prior rule changes, then we can open up a security hole.
8047
policy.RuleDefault(
8148
name='create_network:segments',
8249
check_str='(rule:is_domain_manager and domain_id:%(domain_id)s) or rule:base_create_network:segments',
@@ -99,8 +66,30 @@
9966
),
10067
]
10168

69+
70+
def basify(rule):
71+
"""Do a copy of the existing rule with a base_ name prefix"""
72+
73+
return policy.RuleDefault(
74+
name='base_' + rule.name, check_str=rule.check_str, description=rule.description)
75+
76+
77+
def inherited(rule):
78+
"""Is the rule inherited by one that we have defined?"""
79+
80+
return any(rule.name == my_rule.name for my_rule in rules)
81+
82+
10283
def list_rules():
10384
"""Implements the "oslo.policy.policies" entry point"""
104-
return base.list_rules() + rules
85+
86+
# Okay now for the "hard" bit. We reference built in rules directly from neutron so
87+
# we can augment the exact rules for a specific version, thus we pick up any changes.
88+
# We prefix the existing rules with "base_" as already seen above but only if they
89+
# are redefined (and by implication referenced) from one of ours.
90+
network_rules = [basify(rule) for rule in network.list_rules() if inherited(rule)]
91+
92+
# Those rules will also rely on base rules, so include them too in the final output.
93+
return base.list_rules() + network_rules + rules
10594

10695
# vi: ts=4 et:

0 commit comments

Comments
 (0)