Skip to content

Commit 673e0d8

Browse files
author
Steve Martinelli
committed
Command doc: policy
Also tweaked a bunch of the code to not show 'blob', but 'rules' instead. Change-Id: I6db798d272ff416a77f169c0e912d2096fa02504
1 parent a7a1a57 commit 673e0d8

3 files changed

Lines changed: 130 additions & 30 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
======
2+
policy
3+
======
4+
5+
Identity v3
6+
7+
policy create
8+
-------------
9+
10+
Create new policy
11+
12+
.. program:: policy create
13+
.. code:: bash
14+
15+
os policy create
16+
[--type <type>]
17+
<filename>
18+
19+
.. option:: --type <type>
20+
21+
New MIME type of the policy rules file (defaults to application/json)
22+
23+
.. describe:: <filename>
24+
25+
New serialized policy rules file
26+
27+
policy delete
28+
-------------
29+
30+
Delete policy
31+
32+
.. program:: policy delete
33+
.. code:: bash
34+
35+
os policy delete
36+
<policy>
37+
38+
.. describe:: <policy>
39+
40+
Policy to delete
41+
42+
policy list
43+
-----------
44+
45+
List policies
46+
47+
.. program:: policy list
48+
.. code:: bash
49+
50+
os policy list
51+
[--long]
52+
53+
.. option:: --long
54+
55+
List additional fields in output
56+
57+
policy set
58+
----------
59+
60+
Set policy properties
61+
62+
.. program:: policy set
63+
.. code:: bash
64+
65+
os policy set
66+
[--type <type>]
67+
[--rules <filename>]
68+
<policy>
69+
70+
.. option:: --type <type>
71+
72+
New MIME type of the policy rules file
73+
74+
.. describe:: --rules <filename>
75+
76+
New serialized policy rules file
77+
78+
.. describe:: <policy>
79+
80+
Policy to modify
81+
82+
policy show
83+
-----------
84+
85+
Display policy details
86+
87+
.. program:: policy show
88+
.. code:: bash
89+
90+
os policy show
91+
<policy>
92+
93+
.. describe:: <policy>
94+
95+
Policy to display

‎doc/source/commands.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ referring to both Compute and Volume quotas.
9898
* ``module``: internal - installed Python modules in the OSC process
9999
* ``network``: Network - a virtual network for connecting servers and other resources
100100
* ``object``: (**Object Store**) a single file in the Object Store
101-
* ``policy``: Identity - determines authorization
101+
* ``policy``: (**Identity**) determines authorization
102102
* ``project``: (**Identity**) owns a group of resources
103103
* ``quota``: (**Compute**, **Volume**) resource usage restrictions
104104
* ``region``: (**Identity**) a subset of an OpenStack deployment

‎openstackclient/identity/v3/policy.py‎

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,49 +27,51 @@
2727

2828

2929
class CreatePolicy(show.ShowOne):
30-
"""Create policy command"""
30+
"""Create new policy"""
3131

3232
log = logging.getLogger(__name__ + '.CreatePolicy')
3333

3434
def get_parser(self, prog_name):
3535
parser = super(CreatePolicy, self).get_parser(prog_name)
3636
parser.add_argument(
3737
'--type',
38-
metavar='<policy-type>',
38+
metavar='<type>',
3939
default="application/json",
40-
help='New MIME type of the policy blob - i.e.: application/json',
40+
help='New MIME type of the policy rules file '
41+
'(defaults to application/json)',
4142
)
4243
parser.add_argument(
43-
'blob_file',
44-
metavar='<blob-file>',
45-
help='New policy rule set itself, as a serialized blob, in a file',
44+
'rules',
45+
metavar='<filename>',
46+
help='New serialized policy rules file',
4647
)
4748
return parser
4849

4950
def take_action(self, parsed_args):
5051
self.log.debug('take_action(%s)', parsed_args)
51-
blob = utils.read_blob_file_contents(parsed_args.blob_file)
52+
blob = utils.read_blob_file_contents(parsed_args.rules)
5253

5354
identity_client = self.app.client_manager.identity
5455
policy = identity_client.policies.create(
5556
blob=blob, type=parsed_args.type
5657
)
5758

5859
policy._info.pop('links')
60+
policy._info.update({'rules': policy._info.pop('blob')})
5961
return zip(*sorted(six.iteritems(policy._info)))
6062

6163

6264
class DeletePolicy(command.Command):
63-
"""Delete policy command"""
65+
"""Delete policy"""
6466

6567
log = logging.getLogger(__name__ + '.DeletePolicy')
6668

6769
def get_parser(self, prog_name):
6870
parser = super(DeletePolicy, self).get_parser(prog_name)
6971
parser.add_argument(
7072
'policy',
71-
metavar='<policy-id>',
72-
help='ID of policy to delete',
73+
metavar='<policy>',
74+
help='Policy to delete',
7375
)
7476
return parser
7577

@@ -81,55 +83,57 @@ def take_action(self, parsed_args):
8183

8284

8385
class ListPolicy(lister.Lister):
84-
"""List policy command"""
86+
"""List policies"""
8587

8688
log = logging.getLogger(__name__ + '.ListPolicy')
8789

8890
def get_parser(self, prog_name):
8991
parser = super(ListPolicy, self).get_parser(prog_name)
9092
parser.add_argument(
91-
'--include-blob',
93+
'--long',
9294
action='store_true',
9395
default=False,
94-
help='Additional fields are listed in output',
96+
help='List additional fields in output',
9597
)
9698
return parser
9799

98100
def take_action(self, parsed_args):
99101
self.log.debug('take_action(%s)', parsed_args)
100-
if parsed_args.include_blob:
102+
if parsed_args.long:
101103
columns = ('ID', 'Type', 'Blob')
104+
column_headers = ('ID', 'Type', 'Rules')
102105
else:
103106
columns = ('ID', 'Type')
107+
column_headers = columns
104108
data = self.app.client_manager.identity.policies.list()
105-
return (columns,
109+
return (column_headers,
106110
(utils.get_item_properties(
107111
s, columns,
108112
formatters={},
109113
) for s in data))
110114

111115

112116
class SetPolicy(command.Command):
113-
"""Set policy command"""
117+
"""Set policy properties"""
114118

115119
log = logging.getLogger(__name__ + '.SetPolicy')
116120

117121
def get_parser(self, prog_name):
118122
parser = super(SetPolicy, self).get_parser(prog_name)
119123
parser.add_argument(
120124
'policy',
121-
metavar='<policy-id>',
122-
help='ID of policy to change',
125+
metavar='<policy>',
126+
help='Policy to modify',
123127
)
124128
parser.add_argument(
125129
'--type',
126-
metavar='<policy-type>',
127-
help='New MIME Type of the policy blob - i.e.: application/json',
130+
metavar='<type>',
131+
help='New MIME type of the policy rules file',
128132
)
129133
parser.add_argument(
130-
'--blob-file',
131-
metavar='<blob_file>',
132-
help='New policy rule set itself, as a serialized blob, in a file',
134+
'--rules',
135+
metavar='<filename>',
136+
help='New serialized policy rules file',
133137
)
134138
return parser
135139

@@ -138,8 +142,8 @@ def take_action(self, parsed_args):
138142
identity_client = self.app.client_manager.identity
139143
blob = None
140144

141-
if parsed_args.blob_file:
142-
blob = utils.read_blob_file_contents(parsed_args.blob_file)
145+
if parsed_args.rules:
146+
blob = utils.read_blob_file_contents(parsed_args.rules)
143147

144148
kwargs = {}
145149
if blob:
@@ -148,23 +152,23 @@ def take_action(self, parsed_args):
148152
kwargs['type'] = parsed_args.type
149153

150154
if not kwargs:
151-
sys.stdout.write("Policy not updated, no arguments present \n")
155+
sys.stdout.write('Policy not updated, no arguments present \n')
152156
return
153157
identity_client.policies.update(parsed_args.policy, **kwargs)
154158
return
155159

156160

157161
class ShowPolicy(show.ShowOne):
158-
"""Show policy command"""
162+
"""Display policy details"""
159163

160164
log = logging.getLogger(__name__ + '.ShowPolicy')
161165

162166
def get_parser(self, prog_name):
163167
parser = super(ShowPolicy, self).get_parser(prog_name)
164168
parser.add_argument(
165169
'policy',
166-
metavar='<policy-id>',
167-
help='ID of policy to display',
170+
metavar='<policy>',
171+
help='Policy to display',
168172
)
169173
return parser
170174

@@ -175,4 +179,5 @@ def take_action(self, parsed_args):
175179
parsed_args.policy)
176180

177181
policy._info.pop('links')
182+
policy._info.update({'rules': policy._info.pop('blob')})
178183
return zip(*sorted(six.iteritems(policy._info)))

0 commit comments

Comments
 (0)