Skip to content
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

(MODULES-552) Add capability to specify column_privileges #570

Merged
merged 1 commit into from
Oct 7, 2014

Conversation

fnerdwq
Copy link
Contributor

@fnerdwq fnerdwq commented Sep 16, 2014

Fixes Jira Issue MODULES-552.

@igalic
Copy link
Contributor

igalic commented Sep 16, 2014

could you please squash those two commits?

@fnerdwq
Copy link
Contributor Author

fnerdwq commented Sep 16, 2014

O.k..
Might be a stupid question, what is the best way to do it (I'm new to github 'collaboration')? Ammending the commit and forcing the push - or a new branch with new pull request?
Thanks...

@igalic
Copy link
Contributor

igalic commented Sep 16, 2014

sorry! i usually include a link to the documentation for rebase and squash, just in case someone is new.
but you already have a separate branch for each of your pull requests, following the basic github flow, so i assumed you're a total pro :)

@fnerdwq fnerdwq force-pushed the mysql_grant_column_privs branch from 859b55d to a4b84a9 Compare September 16, 2014 12:03
@fnerdwq
Copy link
Contributor Author

fnerdwq commented Sep 16, 2014

Thanks, "so far so clear" ;-)
I just wasn't sure if it's a good idea to forcibly push rebased branches.

So that's what I did now... Hope this if fine...

@igalic
Copy link
Contributor

igalic commented Sep 16, 2014

it's different from project to project. we're fine with it.

stripped_privileges = privileges.strip.split(/\s*,\s*(?![^(]*\))/).map{ |priv|
# split and sort the column_privileges in the parentheses and rejoin
if priv.include?('(')
type, col=priv.match(/\s*(\S*)\s*\(\s*(.*)\s*\)/).captures
Copy link
Contributor

Choose a reason for hiding this comment

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

why isn't this simply a strip.split('\s+', 2) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I think you are right. I was so focused on regexes yesterday (it made my head some to get the one in line 35 done ;-)
I'll change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I got it... Since it's not quaranteed, that there is a space between the keyword and the bracked (at least not in the type) it should be: strip.split(/\s+|\b/,2). Thanks for that simplification.

But then the next line gets more complicated
type.upcase + " (" + col.slice(1...-1).strip.split(/\s*,\s*/).sort.join(', ') + ")"
due to the parentheses.

@fnerdwq fnerdwq force-pushed the mysql_grant_column_privs branch from a4b84a9 to 0407a99 Compare September 18, 2014 15:52
@fnerdwq
Copy link
Contributor Author

fnerdwq commented Sep 18, 2014

Updated for your request to avoid the regex.

# split on ',' if it is not a non-'('-containing string followed by a
# closing parenthesis ')'-char - e.g. only split comma separated elements not in
# parentheses
stripped_privileges = privileges.strip.split(/\s*,\s*(?![^(]*\))/).map{ |priv|

Choose a reason for hiding this comment

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

Multi-line blocks should use do/end over {/}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, corrected.
Is this also 'best-practice' if there are more method call chained on the block, like do ... end.sort?

@fnerdwq fnerdwq force-pushed the mysql_grant_column_privs branch from 0407a99 to cdd8b7b Compare September 22, 2014 18:43
@igalic
Copy link
Contributor

igalic commented Sep 29, 2014

@cmurphy halp plz. my eyes hurt

it 'ordered including column privileges' do
@user = Puppet::Type.type(:mysql_grant).new(
:name => 'foo@localhost/*.*', :table => ['*.*','@'], :user => 'foo@localhost',
:privileges => ['SELECT(Host,Address)', 'Proxy'] )
Copy link
Contributor

Choose a reason for hiding this comment

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

The PROXY privilege must be named by itself, so while this test passes, applying it in a manifest doesn't work:

Error: Execution of '/usr/bin/mysql -e GRANT PROXY, SELECT (a, b) ON *.* TO 'nss-user'@'%' WITH GRANT OPTION' returned 1: ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PROXY, SELECT (a, b) ON *.* TO 'nss-user'@'%' WITH GRANT OPTION' at line 1

Could you change the test to have privileges ['SELECT(Host,Address)', 'INSERT'] or something similar just so it's not misleading?

@cmurphy
Copy link
Contributor

cmurphy commented Oct 2, 2014

Looks good to me except for the spec issue.

@fnerdwq fnerdwq force-pushed the mysql_grant_column_privs branch from cdd8b7b to 80a0e10 Compare October 3, 2014 09:43
@fnerdwq
Copy link
Contributor Author

fnerdwq commented Oct 3, 2014

I changed the spec file as you proposed...

@igalic
Copy link
Contributor

igalic commented Oct 3, 2014

super! thanks!
aaand, i just realized we don't have docs for this: can you please add an example to the README so we know how to use it?

@fnerdwq fnerdwq force-pushed the mysql_grant_column_privs branch from 80a0e10 to d5e319a Compare October 6, 2014 06:09
@fnerdwq fnerdwq force-pushed the mysql_grant_column_privs branch from d5e319a to f88719b Compare October 6, 2014 06:11
@fnerdwq
Copy link
Contributor Author

fnerdwq commented Oct 6, 2014

I added an extra example under mysql_grant. Hope that's enough?

igalic added a commit that referenced this pull request Oct 7, 2014
(MODULES-552) Add capability to specify column_privileges
@igalic igalic merged commit 400d3b2 into puppetlabs:master Oct 7, 2014
@igalic
Copy link
Contributor

igalic commented Oct 7, 2014

absolutely, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants