code: def get_api_key(client, username, secret):
      
  
      # Try to use a client with username/api key
      if len(secret) == 64:
          try:
              client['Account'].getCurrentUser()
              return secret
          except SoftLayer.SoftLayerAPIError as ex:
              if 'invalid api token' not in ex.faultString.lower():
                  raise
      else:
          # Try to use a client with username/password
          client.authenticate_with_password(username, secret)
  
          user_record = client['Account'].getCurrentUser(mask='id, apiAuthenticationKeys')
          api_keys = user_record['apiAuthenticationKeys']
          if len(api_keys) == 0:
              return client['User_Customer'].addApiAuthenticationKey(id=user_record['id'])
          return api_keys[0]['authenticationKey']
docs: Attempts API-Key and password auth to get an API key.
  
      This will also generate an API key if one doesn't exist