Search code examples
ibm-cloud-infrastructure

softlayer api user password update


I am trying to use the SoftLayer API Rest method to update a user VPN password but having no luck. I must be structuring my call incorrectly and was hoping someone had a working example or input on why my call is failing. I've tried many ways but with no luck. The api user I am using has the needed priv level, my key is valid (works on other methods etc..) My method is:

def set_user_vpn_password(self):
    ''' method to set a user's vpn password '''

    myPass = { "password" : "P@s$w0rd!?" }

    r = requests.post('https://<priv api account>:<api key>@api.softlayer.com/rest/v3/SoftLayer_User_Customer/<softlayer uid>/updateVpnPassword', json=myPass)
    print(r.text)
    pp(r)
    pp(r.json())

The resulting error is:

{"error":"ERR_USER_CUSTOMER_PASSWORD_COMPLEXITY_FAILED","code":"SoftLayer_Exception"}
<Response [500]>
{u'code': u'SoftLayer_Exception',
 u'error': u'ERR_USER_CUSTOMER_PASSWORD_COMPLEXITY_FAILED'}

I don't believe I missed anything on my password policy with regard to complexity - I've tried different strings to no avail. As you can see I am using the Python requests module.


Solution

  • The password policy regarding the complexity is Ok. The problem is that SoftLayer uses this kind of body in the requests:

    {
      "parameters": [] 
    }
    

    Sometimes the request requires an object or an integer or a string such in this case, so the correct REST request would be:

    {
        "parameters": ["P@s$w0rd!?"]
    }
    

    Here a python example using SoftLayer python client:

    """
    Update VPN password.
    
    Important manual pages:
    http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/updateVpnPassword
    https://sldn.softlayer.com/article/Python
    
    License: http://sldn.softlayer.com/article/License
    Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
    """
    import SoftLayer
    import pprint
    
    """
    Your SoftLayer API username and key
    """
    USERNAME = 'set me'
    API_KEY = 'set me'
    
    # Create a SoftLayer API client object
    client = SoftLayer.Client(username=USERNAME,
                              api_key=API_KEY)
    userService = client['SoftLayer_User_Customer']
    
    user_id = 205571
    updated_password = 'P@s$w0rd!?'
    
    try:
        result = userService.updateVpnPassword(updated_password, id=user_id)
        pprint.pprint(result)
    except SoftLayer.SoftLayerAPIError as e:
        print(('Unable to update password faultCode=%s, faultString=%s'
        % (e.faultCode, e.faultString)))