Merge "Use oslo.config instead of argparse."
This commit is contained in:
commit
c9ea8f7bfa
@ -13,12 +13,12 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import argparse
|
|
||||||
import collections
|
import collections
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
from oslo_policy import policy
|
from oslo_policy import policy
|
||||||
|
|
||||||
|
|
||||||
@ -83,37 +83,41 @@ def tool(policy_file, access_file, apply_rule, is_admin=False,
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(sys.argv[0])
|
conf = cfg.ConfigOpts()
|
||||||
parser.add_argument(
|
|
||||||
'--policy',
|
|
||||||
required=True,
|
|
||||||
type=argparse.FileType('rb', 0),
|
|
||||||
help='path to a policy file')
|
|
||||||
parser.add_argument(
|
|
||||||
'--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(
|
conf.register_cli_opt(cfg.StrOpt(
|
||||||
'--is_admin',
|
'policy',
|
||||||
help='set is_admin=True on the credentials used for the evaluation')
|
required=True,
|
||||||
|
help='path to a policy file'))
|
||||||
|
|
||||||
args = parser.parse_args()
|
conf.register_cli_opt(cfg.StrOpt(
|
||||||
try:
|
'access',
|
||||||
is_admin = args.is_admin.lower() == "true"
|
required=True,
|
||||||
except Exception:
|
help='path to a file containing OpenStack Identity API '
|
||||||
is_admin = False
|
'access info in JSON format'))
|
||||||
tool(args.policy, args.access, args.rule, is_admin, args.target)
|
|
||||||
|
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__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user