summaryrefslogtreecommitdiff
path: root/oslo_policy/shell.py
diff options
context:
space:
mode:
authorMoisés Guimarães de Medeiros <moguimar@redhat.com>2018-12-13 16:57:40 +0100
committerHervé Beraud <hberaud@redhat.com>2018-12-20 15:13:00 +0100
commitcc6960be6f8f598ba7e81283e69f6da0d1d9b5f3 (patch)
treec865e5b77488a7dbeabafec3029b1dee2666247e /oslo_policy/shell.py
parentb9fd10e2612f26c93d49c168a0408aba6d20e5bf (diff)
downloadoslo-policy-cc6960be6f8f598ba7e81283e69f6da0d1d9b5f3.tar.gz
Use oslo.config instead of argparse.
Changing arg consumption from argparse to oslo.config in order to also provide behavior control using config files. Change-Id: Iec4dab763b973b70c98077cb29708acd9cbbcec4 Signed-off-by: Moisés Guimarães de Medeiros <moguimar@redhat.com>
Diffstat (limited to 'oslo_policy/shell.py')
-rw-r--r--oslo_policy/shell.py64
1 files changed, 34 insertions, 30 deletions
diff --git a/oslo_policy/shell.py b/oslo_policy/shell.py
index 3fda8de..b030fdf 100644
--- a/oslo_policy/shell.py
+++ b/oslo_policy/shell.py
@@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import argparse
import collections
import sys
from oslo_serialization import jsonutils
+from oslo_config import cfg
from oslo_policy import policy
@@ -83,37 +83,41 @@ def tool(policy_file, access_file, apply_rule, is_admin=False,
def main():
- parser = argparse.ArgumentParser(sys.argv[0])
- parser.add_argument(
- '--policy',
+ conf = cfg.ConfigOpts()
+
+ conf.register_cli_opt(cfg.StrOpt(
+ 'policy',
required=True,
- type=argparse.FileType('rb', 0),
- help='path to a policy file')
- parser.add_argument(
- '--access',
+ help='path to a policy file'))
+
+ conf.register_cli_opt(cfg.StrOpt(
+ 'access',
required=True,
- type=argparse.FileType('rb', 0),
- help='path to a file containing OpenStack Identity API' +
- ' access info in JSON format')
- parser.add_argument(
- '--target',
- type=argparse.FileType('rb', 0),
- help='path to a file containing custom target info in' +
- ' JSON format. This will be used to evaluate the policy with.')
- parser.add_argument(
- '--rule',
- help='rule to test')
-
- parser.add_argument(
- '--is_admin',
- help='set is_admin=True on the credentials used for the evaluation')
-
- args = parser.parse_args()
- try:
- is_admin = args.is_admin.lower() == "true"
- except Exception:
- is_admin = False
- tool(args.policy, args.access, args.rule, is_admin, args.target)
+ help='path to a file containing OpenStack Identity API '
+ 'access info in JSON format'))
+
+ conf.register_cli_opt(cfg.StrOpt(
+ 'target',
+ help='path to a file containing custom target info in '
+ 'JSON format. This will be used to evaluate the policy with.'))
+
+ conf.register_cli_opt(cfg.StrOpt(
+ 'rule',
+ help='rule to test'))
+
+ conf.register_cli_opt(cfg.StrOpt(
+ 'is_admin',
+ help='set is_admin=True on the credentials used for the evaluation',
+ default=""))
+
+ conf()
+
+ policy = open(conf.policy, "rb", 0)
+ access = open(conf.access, "rb", 0)
+ target = open(conf.target, "rb", 0) if conf.target else None
+ is_admin = conf.is_admin.lower() == "true"
+
+ tool(policy, access, conf.rule, is_admin, target)
if __name__ == "__main__":