2727
2828
2929class 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
6264class 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
8385class 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
112116class 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
157161class 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