{"action":"created","issue":{"url":"https://api.github.com/repos/camptocamp/puppet-openldap/issues/107","labels_url":"https://api.github.com/repos/camptocamp/puppet-openldap/issues/107/labels{/name}","comments_url":"https://api.github.com/repos/camptocamp/puppet-openldap/issues/107/comments","events_url":"https://api.github.com/repos/camptocamp/puppet-openldap/issues/107/events","html_url":"https://github.com/camptocamp/puppet-openldap/pull/107","id":116560926,"number":107,"title":"fixed bug for spaces in the \"by\" section of the rule","user":{"login":"crayfishx","id":837815,"avatar_url":"https://avatars.githubusercontent.com/u/837815?v=3","gravatar_id":"","url":"https://api.github.com/users/crayfishx","html_url":"https://github.com/crayfishx","followers_url":"https://api.github.com/users/crayfishx/followers","following_url":"https://api.github.com/users/crayfishx/following{/other_user}","gists_url":"https://api.github.com/users/crayfishx/gists{/gist_id}","starred_url":"https://api.github.com/users/crayfishx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crayfishx/subscriptions","organizations_url":"https://api.github.com/users/crayfishx/orgs","repos_url":"https://api.github.com/users/crayfishx/repos","events_url":"https://api.github.com/users/crayfishx/events{/privacy}","received_events_url":"https://api.github.com/users/crayfishx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-12T14:40:37Z","updated_at":"2015-11-12T14:58:25Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/camptocamp/puppet-openldap/pulls/107","html_url":"https://github.com/camptocamp/puppet-openldap/pull/107","diff_url":"https://github.com/camptocamp/puppet-openldap/pull/107.diff","patch_url":"https://github.com/camptocamp/puppet-openldap/pull/107.patch"},"body":"# Problem\r\n\r\nWhen creating openldap_access rules, it's possible to have a space in the \"by\" section of the rule.  This currently breaks the instances method in the provider which matches soley on space delimited lines.\r\n\r\n# Example\r\n\r\nI declare this code in Puppet\r\n\r\n    openldap_access { 'to dn.subtree=\"dc=example,dc=com\" by group/groupOfNames/member.exact=\"cn=slapd replicas,ou=groups,dc=example,dc=com\" on dc=example,dc=com':\r\n      ensure => 'present',\r\n      access => 'read',\r\n    }\r\n\r\nThe opendap module configures this correctly in LDAP, a look at the cn=config LDIF gives us\r\n\r\n    olcAccess: {6}to dn.subtree=\"dc=example,dc=com\" by group/groupOfNames/member.exa\r\n    ct=\"cn=slapd replicas,ou=groups,dc=example,dc=com\" read\r\n\r\nIf we try and run Puppet again now, it will try and re-create this rule and LDAP bombs out with an error because it already exists.  The reason for this is the prefetch,  if we use puppet resource to look at this entry we can see it's broken....\r\n\r\n    # puppet resource openldap_access\r\n\r\n    openldap_access { 'to dn.subtree=\"dc=example,dc=com\" by group/groupOfNames/member.exact=\"cn=slapd on dc=example,dc=com':\r\n      ensure  => 'present',\r\n      access  => 'replicas,ou=groups,dc=example,dc=com\"',\r\n      control => ' read',\r\n    }\r\n\r\n# Cause/Fix\r\n\r\nThe problem is in the regex in the prefix that deals with the by, access, control line\r\n\r\n```ruby\r\nby, access, control = b.strip.match(/^(\\S+)\\s+(\\S+)(\\s+\\S+)?$/).captures\r\n```\r\n\r\nThis regex will break if there is a space in the by section.  Since we can assume that if there is a space then it will be quoted, the regex in this PR should support all possible combinations, so \r\n\r\n    foo=a,b,c x y\r\n    foo=a,b,c x\r\n    foo=\"a b c\" x y\r\n    foo=\"a b c\" x\r\n    foo=\"a c\" x\r\n    foo x\r\n    foo x y\r\n\r\nIn all of these examples, x should be the second match and y (if it exists) the third match.  I've tested this PR against a variety of scenarios and it seems to work.\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/camptocamp/puppet-openldap/issues/comments/156129238","html_url":"https://github.com/camptocamp/puppet-openldap/pull/107#issuecomment-156129238","issue_url":"https://api.github.com/repos/camptocamp/puppet-openldap/issues/107","id":156129238,"user":{"login":"mcanevet","id":2950673,"avatar_url":"https://avatars.githubusercontent.com/u/2950673?v=3","gravatar_id":"","url":"https://api.github.com/users/mcanevet","html_url":"https://github.com/mcanevet","followers_url":"https://api.github.com/users/mcanevet/followers","following_url":"https://api.github.com/users/mcanevet/following{/other_user}","gists_url":"https://api.github.com/users/mcanevet/gists{/gist_id}","starred_url":"https://api.github.com/users/mcanevet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcanevet/subscriptions","organizations_url":"https://api.github.com/users/mcanevet/orgs","repos_url":"https://api.github.com/users/mcanevet/repos","events_url":"https://api.github.com/users/mcanevet/events{/privacy}","received_events_url":"https://api.github.com/users/mcanevet/received_events","type":"User","site_admin":false},"created_at":"2015-11-12T14:58:25Z","updated_at":"2015-11-12T14:58:25Z","body":"LGTM, @raphink what do you think of that?"}}