mirror of
https://github.com/curlconverter/curlconverter.git
synced 2022-05-22 02:35:29 +03:00
support --digest auth in Python output (#345)
This commit is contained in:
committed by
GitHub
parent
ca185a55c9
commit
a731d9a8b7
1
fixtures/curl_commands/get_digest_auth.sh
Normal file
1
fixtures/curl_commands/get_digest_auth.sh
Normal file
@@ -0,0 +1 @@
|
||||
curl "http://localhost:28139/" -u "some_username:some_password" --digest
|
||||
4
fixtures/python/get_digest_auth.py
generated
Normal file
4
fixtures/python/get_digest_auth.py
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
import requests
|
||||
from requests.auth import HTTPDigestAuth
|
||||
|
||||
response = requests.get('http://localhost:28139/', auth=HTTPDigestAuth('some_username', 'some_password'))
|
||||
@@ -21,9 +21,7 @@ export const _toDart = r => {
|
||||
'void main() async {\n'
|
||||
|
||||
if (r.auth) {
|
||||
const splitAuth = r.auth.split(':')
|
||||
const uname = splitAuth[0] || ''
|
||||
const pword = splitAuth[1] || ''
|
||||
const [uname, pword] = r.auth
|
||||
|
||||
s +=
|
||||
" var uname = '" + uname + "';\n" +
|
||||
|
||||
@@ -54,10 +54,7 @@ function getBasicAuth (request) {
|
||||
return ''
|
||||
}
|
||||
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
|
||||
const [user, password] = request.auth
|
||||
return `basic_auth: {${repr(user)}, ${repr(password)}}`
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,7 @@ export const _toGo = request => {
|
||||
}
|
||||
|
||||
if (request.auth) {
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
const [user, password] = request.auth
|
||||
goCode += '\treq.SetBasicAuth("' + user + '", "' + password + '")\n'
|
||||
}
|
||||
goCode += '\tresp, err := client.Do(req)\n'
|
||||
|
||||
@@ -46,7 +46,7 @@ export const _toJava = request => {
|
||||
}
|
||||
|
||||
if (request.auth) {
|
||||
javaCode += '\t\tbyte[] message = ("' + doubleQuotes(request.auth) + '").getBytes("UTF-8");\n'
|
||||
javaCode += '\t\tbyte[] message = ("' + doubleQuotes(request.auth.join(':')) + '").getBytes("UTF-8");\n'
|
||||
javaCode += '\t\tString basicAuth = DatatypeConverter.printBase64Binary(message);\n'
|
||||
javaCode += '\t\thttpConn.setRequestProperty("Authorization", "Basic " + basicAuth);\n'
|
||||
javaCode += '\n'
|
||||
|
||||
@@ -51,9 +51,7 @@ export const _toJavaScript = request => {
|
||||
i++
|
||||
}
|
||||
if (request.auth) {
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
const [user, password] = request.auth
|
||||
jsFetchCode += ' \'Authorization\': \'Basic \' + btoa(\'' + user + ':' + password + '\')'
|
||||
}
|
||||
if (request.cookies) {
|
||||
|
||||
@@ -47,9 +47,7 @@ export const _toNodeRequest = request => {
|
||||
|
||||
if (request.auth) {
|
||||
nodeRequestCode += ',\n'
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
const [user, password] = request.auth
|
||||
nodeRequestCode += ' auth: {\n'
|
||||
nodeRequestCode += " 'user': '" + user + "',\n"
|
||||
nodeRequestCode += " 'pass': '" + password + "'\n"
|
||||
|
||||
@@ -134,10 +134,7 @@ export const _toJsonString = request => {
|
||||
}
|
||||
|
||||
if (request.auth) {
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
|
||||
const [user, password] = request.auth
|
||||
requestJson.auth = {
|
||||
user: repr(user),
|
||||
password: repr(password)
|
||||
|
||||
@@ -72,7 +72,7 @@ const prepareAuth = (request) => {
|
||||
const options = []
|
||||
const optionsParams = []
|
||||
if (request.auth) {
|
||||
const [usr, pass] = request.auth.split(':')
|
||||
const [usr, pass] = request.auth
|
||||
const userfield = `'Username', ${repr(usr)}`
|
||||
const passfield = `'Password', ${repr(pass)}`
|
||||
const authparams = (usr ? `${userfield}, ` : '') + passfield
|
||||
|
||||
@@ -23,7 +23,7 @@ const parseWebOptions = (request) => {
|
||||
|
||||
const headers = {}
|
||||
if (request.auth) {
|
||||
const [username, password] = request.auth.split(':')
|
||||
const [username, password] = request.auth
|
||||
if (username !== '') {
|
||||
options.Username = username
|
||||
options.Password = password
|
||||
|
||||
@@ -29,9 +29,7 @@ export const _toPhpRequests = request => {
|
||||
|
||||
let optionsString = false
|
||||
if (request.auth) {
|
||||
const splitAuth = request.auth.split(':').map(quote)
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
const [user, password] = request.auth
|
||||
optionsString = "$options = array('auth' => array('" + user + "', '" + password + "'));"
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export const _toPhp = request => {
|
||||
|
||||
if (request.auth) {
|
||||
phpCode += 'curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);\n'
|
||||
phpCode += "curl_setopt($ch, CURLOPT_USERPWD, '" + quote(request.auth) + "');\n"
|
||||
phpCode += "curl_setopt($ch, CURLOPT_USERPWD, '" + quote(request.auth.join(':')) + "');\n"
|
||||
}
|
||||
|
||||
if (request.data || request.multipartUploads) {
|
||||
|
||||
@@ -319,10 +319,9 @@ export const _toPython = request => {
|
||||
}
|
||||
|
||||
if (request.auth) {
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
requestLineBody += ', auth=(' + repr(user) + ', ' + repr(password) + ')'
|
||||
const [user, password] = request.auth
|
||||
const authClass = request.digest ? 'HTTPDigestAuth' : ''
|
||||
requestLineBody += ', auth=' + authClass + '(' + repr(user) + ', ' + repr(password) + ')'
|
||||
}
|
||||
requestLineBody += ')'
|
||||
|
||||
@@ -335,7 +334,11 @@ export const _toPython = request => {
|
||||
pythonCode += 'import os\n'
|
||||
}
|
||||
|
||||
pythonCode += 'import requests\n\n'
|
||||
pythonCode += 'import requests\n'
|
||||
if (request.auth && request.digest) {
|
||||
pythonCode += 'from requests.auth import HTTPDigestAuth\n'
|
||||
}
|
||||
pythonCode += '\n'
|
||||
|
||||
if (osVariables.size > 0) {
|
||||
for (const osVar of osVariables) {
|
||||
|
||||
@@ -172,9 +172,7 @@ export const _toR = request => {
|
||||
requestLineBody += ', config = httr::config(ssl_verifypeer = FALSE)'
|
||||
}
|
||||
if (request.auth) {
|
||||
const splitAuth = request.auth.split(':')
|
||||
const user = splitAuth[0] || ''
|
||||
const password = splitAuth[1] || ''
|
||||
const [user, password] = request.auth
|
||||
requestLineBody += ', httr::authenticate(' + repr(user) + ', ' + repr(password) + ')'
|
||||
}
|
||||
requestLineBody += ')'
|
||||
|
||||
@@ -63,8 +63,8 @@ export const _toRust = request => {
|
||||
lines.push(indent(`.${request.method}("${quote(request.url)}")`, 2))
|
||||
|
||||
if (request.auth) {
|
||||
const [user, password] = request.auth.split(':', 2).map(quote)
|
||||
lines.push(indent(`.basic_auth("${user || ''}", Some("${password || ''}"))`, 2))
|
||||
const [user, password] = request.auth
|
||||
lines.push(indent(`.basic_auth("${quote(user)}", Some("${quote(password)}"))`, 2))
|
||||
}
|
||||
|
||||
if (hasHeaders) {
|
||||
|
||||
@@ -75,13 +75,13 @@ export const _toStrest = request => {
|
||||
}
|
||||
}
|
||||
if (request.auth) {
|
||||
response.requests.curl_converter.auth = {
|
||||
basic: {}
|
||||
const [username, password] = request.auth
|
||||
const basic = {}
|
||||
if (username) {
|
||||
basic.username = username
|
||||
}
|
||||
if (request.auth.split(':')[0]) {
|
||||
response.requests.curl_converter.auth.basic.username = request.auth.split(':')[0]
|
||||
}
|
||||
response.requests.curl_converter.auth.basic.password = request.auth.split(':')[1]
|
||||
basic.password = password
|
||||
response.requests.curl_converter.auth = { basic }
|
||||
}
|
||||
|
||||
let queryList
|
||||
|
||||
@@ -18,8 +18,8 @@ export const ansibleTemplate = `-
|
||||
{%- endif %}
|
||||
{%- endif %}
|
||||
{%- if request.auth %}
|
||||
{%- set url_username = request.auth.split(":")[0] %}
|
||||
{%- set url_password = request.auth.split(":")[1] %}
|
||||
{%- set url_username = request.auth[0] %}
|
||||
{%- set url_password = request.auth[1] %}
|
||||
{%- if url_username %}
|
||||
url_username: {{ url_username }}
|
||||
{%- endif %}
|
||||
|
||||
6
util.js
6
util.js
@@ -1086,7 +1086,11 @@ const buildRequest = parsedArguments => {
|
||||
}
|
||||
|
||||
if (parsedArguments.user) {
|
||||
request.auth = parsedArguments.user
|
||||
const [user, pass] = parsedArguments.user.split(/:(.*)/s, 2)
|
||||
request.auth = [user, pass || '']
|
||||
}
|
||||
if (parsedArguments.digest) {
|
||||
request.digest = parsedArguments.digest
|
||||
}
|
||||
if (has(request, 'data')) {
|
||||
if (request.data.length > 1) {
|
||||
|
||||
Reference in New Issue
Block a user