The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SOLVED Creating databases and users with uapi

Discussion in 'cPanel Developers' started by Miguel G, Dec 1, 2016.

Tags:
  1. Miguel G

    Miguel G Active Member

    Joined:
    Jun 4, 2015
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hi,

    I am using uapi in a bash script to create for a given Cpanel user a database and a user for that database.


    Code:
    /usr/bin/uapi --user=$CPUSER --output=json Mysql create_database name=$DATABASE/usr/bin/uapi --user=$CPUSER --output=json Mysql create_user name=$USERNAME password=$PASSWORD/usr/bin/uapi --user=$CPUSER Mysql set_privileges_on_database user=$USERNAME database=$DATABASE privileges=ALL PRIVILEGES
    

    The first two commands work fine but the last one always give two kinds of errors:


    Code:
    func: set_privileges_on_database
    module: Mysql
    result:
      data: ~
      errors:
        - (XID 9p7vx9) Provide the âuserâargument.
      messages: ~
      metadata: {}
    
      status: 0
    
    or instead of user argument, sometimes it says database argument instead of the user argument. Funny thing is that after running that very same command separately in the command line, randomly it works, randomly it shows any of the two aforementioned errors.
     
  2. Miguel G

    Miguel G Active Member

    Joined:
    Jun 4, 2015
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    Twitter:
    Sorry, the editor put wrong the lines in my script

    Code:
    /usr/bin/uapi --user=$CPUSER --output=json Mysql create_database name=$DATABASE
    
    /usr/bin/uapi --user=$CPUSER --output=json Mysql create_user name=$USERNAME password=$PASSWORD
    
    /usr/bin/uapi --user=$CPUSER Mysql set_privileges_on_database user=$USERNAME database=$DATABASE privileges=ALL PRIVILEGES
    BTW, I have WHM 60 build 25
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,285
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    I was able to reproduce this behavior, and it appears related to the URI encoded value for "ALL PRIVILEGES". When reproducing the error message using the example you provided, I notice through strace that it's sometimes attempting to run the command with the wrong syntax:

    Code:
    703657 execve("/usr/bin/uapi", ["/usr/bin/uapi", "--user=user01", "Mysql", "set_privileges_on_database", "user=dbuser123", "database=1234", "privileges=ALL", "PRIVILEGES"], [/* 24 vars */]) = 0
    I updated the command to include "%20" instead of the space:

    Code:
    /usr/bin/uapi --user=$CPUSER Mysql set_privileges_on_database user=$USERNAME database=$DATABASE privileges=ALL%20PRIVILEGES
    I could no longer reproduce the issue after making this change. Could you verify if that addresses the issue? If so, I'll open an internal case to ensure this is updated on our documentation.

    Thanks!
     
  4. Miguel G

    Miguel G Active Member

    Joined:
    Jun 4, 2015
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    Twitter:
    Yes, it works! Many thanks for looking into this!
     
  5. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,064
    Likes Received:
    1,285
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    I'm happy to see that helped. I opened a case with our Documentation Team to ensure the document is updated to further clarify the URI-encoded requirement.

    Thank you.
     
Loading...

Share This Page