-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
review更改 #91
base: master
Are you sure you want to change the base?
review更改 #91
Conversation
short_description: ansible can manage aliyun access_key through this module | ||
version_added: "2.5" | ||
description: | ||
- "This module allows the user to manage access-keys. Includes those commands:'present', 'absent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 32行不需要用双引号引起来(况且只有一个双引号),另外,英文介绍最好可以稍微正式点儿
state: | ||
description: | ||
- Create,delete or update the access_key of the user. List all access_keys of a user. | ||
choices: [ 'present','list','absent'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state的description要跟它的module的功能相对应,这里应该去掉list的部分;choices也一样
每个参数的定义要准确,如果这个参数是必填的,要注明:required: true,如果有默认值,要注明default:“具体的默认值”
type: dict | ||
sample: { | ||
"access_key_id": "0wNEpMMlzy7szvai", | ||
"access_key_secret": "PupkTg8jdmau1cXxYacgE736PJj4cA", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
敏感信息不要暴露在开源代码中,用“abc12345“代替就好
''' | ||
|
||
RETURN = ''' | ||
changed: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量changed 不用暴露在RETURN中
choices=['present', 'absent'],required=True), | ||
user_name = dict(required=True), | ||
access_key_ids = dict(required=False), | ||
is_active = dict(required=False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument_spec 中的参数的定义要跟DOCUMENTATION中的保持一致,如果是required=True,要进行声明,否则不用;如果有choices,要声明,用于做参数合法性校验,如果有default,要声明,为其指定一个初始化的default value;所有的变量的类型要进行声明,具体可参考:https://github.com/ansible/ansible/pull/36898/files#diff-7e74fd025d257f404dbd79c735e2cdd3 这是一个已经提交到官方的并且被官方review过多次的PR
try: | ||
changed=ram.delete_access_key(user_name=module.params.get('user_name'),access_key_id=module.params.get('access_key_id')) | ||
except Exception as e: | ||
module.fail_json(msg="Failed to delete access_key {0}with error {1}".format(module.params.get('access_key_id'),e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量之间应该有一个空格进行分割,不然无法通过CI,所以145行应该是:module.fail_json(msg="Failed to delete access_key {0} with error {1}".format(module.params.get('access_key_id'), e))
ram = ram_connect(module) | ||
invocations[module.params.get('state')](module, ram) | ||
|
||
if __name__ == '__main__': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create和delete实现的逻辑没什么大的问题,由于这个module本身功能不是很大,逻辑不复杂,所以个人认为直接在main中实现create和delete就可以了,不用单独定义三个函数,可以避免重复多次的取值和判断的逻辑,同时整体代码看起来也很整洁。
{ | ||
"access_key_id": "0wNEpMMlzy7szvai", | ||
"status": "Active", | ||
"create_date": "2015-01-23T12:33:18Z" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参数上下要对齐
result = [] | ||
ids = [] | ||
|
||
if user_name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有了124行的required=True,135行的逻辑可以省略
ram = ram_connect(module) | ||
invocations[module.params.get('state')](module, ram) | ||
|
||
if __name__ == '__main__': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
两个函数之间有且只有两个空行
options: | ||
state: | ||
description: | ||
- Create,delete or update the access_key of the user. List all access_keys of a user. | ||
choices: [ 'present','list','absent'] | ||
- Create,delete or update the access_key of the user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create 和 delete之间应该要有一个空格
- Create,delete or update the access_key of the user. List all access_keys of a user. | ||
choices: [ 'present','list','absent'] | ||
- Create,delete or update the access_key of the user. | ||
choices: [ 'present', 'absent'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state 统一改为optional,然后default设置为present
access_key_ids = dict(required=False), | ||
is_active = dict(required=False), | ||
access_key_id = dict(required=False), | ||
is_active = dict(default=True, required=False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
argument_spec中申明的参数,要跟DOCUMENT中定义的一样,
- 如果是required=True,要显示申明,否则不用
- 如果有default值,要显示申明
- 如果有choices,要显示申明
除此之外,此处要对参数做类型的显示申明
@@ -142,7 +141,7 @@ def ali_access_key_del(module,ram): | |||
try: | |||
changed=ram.delete_access_key(user_name=module.params.get('user_name'),access_key_id=module.params.get('access_key_id')) | |||
except Exception as e: | |||
module.fail_json(msg="Failed to delete access_key {0}with error {1}".format(module.params.get('access_key_id'),e)) | |||
module.fail_json(msg="Failed to delete access_key {0} with error {1}".format(module.params.get('access_key_id'),e)) | |||
module.exit_json(changed=changed) | |||
|
|||
def validate_parameters(required_vars, valid_vars, module): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数与函数之间有且只有两个空行
@@ -18,6 +18,8 @@ | |||
# You should have received a copy of the GNU General Public License | |||
# along with Ansible. If not, see http://www.gnu.org/licenses/. | |||
|
|||
from __future__ import absolute_import, division, print_function | |||
metaclass = type | |||
|
|||
ANSIBLE_METADATA = {'metadata_version': '1.1', | |||
'status': ['preview'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在metadata中要加上“'supported_by': 'community'”
alicloud_region: '{{ alicloud_region }}' | ||
user_name:'{{ user_name }}' | ||
access_key_ids:'{{ access_key_ids }}' | ||
state: 'absent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量跟变量值之间应该有一个空格,所以90行应该是 user_name: '{{ user_name }}'; 91行应该是:access_key_ids: '{{ access_key_ids }}' 烦请检查其他的地方
def ali_access_key_create(module,ram): | ||
#user_name | ||
required_vars = ['user_name'] | ||
valid_vars = ['access_key_id','is_active'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
两个item之间,应该保留一个空格:valid_vars = ['access_key_id', 'is_active'],烦请检查其他的地方
changed = False | ||
try: | ||
if params['access_key_id']: | ||
changed=ram.update_access_key(user_name=module.params.get('user_name'), access_key_id=params['access_key_id'],is_active=params['is_active']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
125,129 格式问题
validate_parameters(required_vars, valid_vars, module) | ||
changed = False | ||
try: | ||
changed=ram.delete_access_key(user_name=module.params.get('user_name'),access_key_id=module.params.get('access_key_id')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
145格式问题
state = module.params.get('state') | ||
for v in required_vars: | ||
if not module.params.get(v): | ||
module.fail_json(msg="Parameter %s required for %s state" % (v, state)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
message和error的统一为:{}, line 154: 改为:module.fail_json(msg="Parameter {0} required for {1} state".format((v, state))
]), | ||
user_name = dict(type='str', required=True), | ||
access_key_id = dict(type='str', required=False), | ||
is_active = dict(type='bool', default=True, required=False), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
required=False 没必要申明,默认的
def main(): | ||
argument_spec = ecs_argument_spec() | ||
argument_spec.update(dict( | ||
state=dict(default='present', choices=[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请申明type='str'
type: list | ||
sample: [ | ||
{ | ||
"access_key_id": "0wNEpMMlzy7szvai", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
敏感信息记得脱敏
result.append(get_info(accesskey)) | ||
module.exit_json(changed=False, access_keys=result, total=len(result)) | ||
except ECSResponseError as e: | ||
module.fail_json(msg='Error in describe access_keys: %s' % str(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format格式
DOCUMENTATION = ''' | ||
--- | ||
module: alicloud_access_key_facts | ||
version_added: "2.5" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change it to 2.6
try: | ||
changed=ram.delete_access_key(user_name=module.params.get('user_name'), access_key_id=module.params.get('access_key_id')) | ||
except Exception as e: | ||
module.fail_json(msg="Failed to delete access_key {0} with error {1}".format(module.params.get('access_key_id'),e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式问题,最后e之前应该有一个空格
short_description: ansible can manage aliyun access_key through this module | ||
version_added: "2.6" | ||
description: | ||
- This module allows the user to manage access-keys. Includes those commands:'present', 'absent' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
格式问题,commands:后应该有一个空格
zhuweif seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
list 用facts去实现,create返回对象,其他操作返回操作状态