Skip to content

Add consul acl state - #49261

Merged
rallytime merged 16 commits into
saltstack:developfrom
remijouannet:add-consul-acl-state
Sep 4, 2018
Merged

rallytime merged 16 commits into
saltstack:developfrom
remijouannet:add-consul-acl-state

Conversation

@remijouannet

@remijouannet remijouannet commented Aug 22, 2018 •

Copy link
Copy Markdown
Contributor

What does this PR do?

add a consul module state with the following function

  • consul.acl_present
  • consul.acl_absent

this PR depend from this one #49232
because it need consul.acl_info

acl_present:
  consul.acl_present:
    - id: 38AC8470-4A83-4140-8DFD-F924CD32917F
    - name: acl_name
    - rules: node "" {policy = "write"} service "" {policy = "read"} key "_rexec" {policy = "write"}
    - type: client
    - consul_url: http://localhost:8500

acl_delete:
   consul.acl_absent:
     - id: 38AC8470-4A83-4140-8DFD-F924CD32917F

Tests written?

No

I'm already using this in production, the idea is the acl are fully manage by salt
all i have is this state consul/acl.sls

{% for acl, args in pillar['consul']['acl'].iteritems()|sort %}
add_consul_{{ acl }}:
  consul.acl_present:
    - name: {{ args['name'] }}
    - id: {{ args['id'] }}
    - type: {{ args['type'] }}
    - rules: {{ args['rules'] }}
{% endfor %}

and all the acl are define in pillar

consul:
  acl:
    consul-agent:
      name: Agent Token
      id: D537FB10-7C95-4EFF-BFE5-4CDBEFDCC418
      type: client
      rules: node "" {policy = "write"} service "" {policy = "read"} key "_rexec" {policy = "write"}
    admin:
      name: admin
      id: BF2D7FE2-65D6-43FE-ADA6-92A6522F90BD
      type: client
      rules: key "" { policy = "write" } service "admin" { policy = "write" } service "" { policy = "read" }

so when i have to update or create an acl, i just have to edit the pillar and use the state my consul.acl

@cachedout cachedout left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@remijouannet

Copy link
Copy Markdown
Contributor Author

hello @cachedout done ;)

@remijouannet

Copy link
Copy Markdown
Contributor Author

#49232 has been merged :)

@rallytime rallytime left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some small change requests here.

Comment thread salt/states/consul.py Outdated
# -*- coding: utf-8 -*-
'''
Consul Managemnt
===========================

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header (====) needs to match the number of characters in the Consul Management title, otherwise the doc build will output a warning.

There's also a typo in the heading. Management.

Comment thread salt/states/consul.py Outdated
'''
return True if the acl need to be update, False if it doesn't need to be update
'''
r = __salt__['consul.acl_info'](id=id, token=token, consul_url=consul_url)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is picky, but can you change these variable references to be at least 3 letters? It's a stylistic standard we like to have at Salt. ret is fine.

This needs to be changed in some of the other functions below as well.

Comment thread salt/states/consul.py Outdated

def _acl_exists(name=None, id=None, token=None, consul_url=None):
'''
return True if acl exist, if False it not

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If acl exists, return True. Otherwise, return False. might be a little more clear here.

Comment thread salt/states/consul.py Outdated
elif name:
r = __salt__['consul.acl_list'](token=token, consul_url=consul_url)

if len(r['data']):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can if r.get('data') work here instead of len? That might be a little more clear here.

Comment thread salt/states/consul.py Outdated
if not exists['result']:
if __opts__['test']:
ret['result'] = None
ret['comment'] = "the acl doesn't exist, it will be create"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create --> created

Comment thread salt/states/consul.py Outdated
if changes:
if __opts__['test']:
ret['result'] = None
ret['comment'] = "the acl exist, but it need to be update"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the acl exists and will be updated

Comment thread salt/states/consul.py Outdated
if exists['result']:
if __opts__['test']:
ret['result'] = None
ret['comment'] = "the acl exists, it will be delete"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete --> deleted

@remijouannet

Copy link
Copy Markdown
Contributor Author

@rallytime thx for the review, i will take a look at it as soon as i can

@rallytime
rallytime requested a review from cachedout August 31, 2018 18:30
Comment thread salt/states/consul.py Outdated

def _acl_exists(name=None, id=None, token=None, consul_url=None):
'''
If acl exists, return True. Otherwise, return False.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a little misleading. This function seems to return a dictionary and this makes it seem like the return itself is actually a boolean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tell me if the description is more clear now

Comment thread salt/states/consul.py Outdated

def _acl_exists(name=None, id=None, token=None, consul_url=None):
'''
If acl exists, return True. Otherwise, return False.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems misleading. This makes it seem like the function returns a boolean when it actually returns a dictionary.

Comment thread salt/states/consul.py Resolved
@rallytime
rallytime requested a review from cachedout September 4, 2018 13:37
@rallytime
rallytime merged commit 4516c9e into saltstack:develop Sep 4, 2018
@remijouannet

Copy link
Copy Markdown
Contributor Author

@cachedout @rallytime thx, is this possible to backport this PR in 2017.7 ?

@remijouannet
remijouannet deleted the add-consul-acl-state branch September 5, 2018 12:29
@rallytime

Copy link
Copy Markdown
Contributor

Hi @remijouannet - We only accept/back-port bug fixes in the dot branches so this won't be backported.

You can use dynamic module distribution to use this earlier on your own, however.

@remijouannet

Copy link
Copy Markdown
Contributor Author

ho, ok no problem
in which release this module will be include ?

@rallytime

Copy link
Copy Markdown
Contributor

@remijouannet It will be in the release codenamed Neon.

@remijouannet

Copy link
Copy Markdown
Contributor Author

ok thx for the answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants