Converting result to snake_case before returning

pull/18777/head
Corwin Brown 9 years ago committed by Matt Clay
parent ac620b79dd
commit 62e8f46390

@ -1,7 +1,7 @@
#!powershell #!powershell
# This file is part of Ansible # This file is part of Ansible
# #
# Copyright 2015, Corwin Brown <corwin.brown@maxpoint.com> # Copyright 2015, Corwin Brown <corwin@corwinbrown.com>
# #
# Ansible is free software: you can redistribute it and/or modify # Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -25,6 +25,15 @@ $result = New-Object psobject @{
win_uri = New-Object psobject win_uri = New-Object psobject
} }
# Functions ###############################################
Function ConvertTo-SnakeCase($input_string) {
$snake_case = $input_string -csplit "(?<!^)(?=[A-Z])" -join "_"
$snake_case = $snake_case.ToLower()
return $snake_case
}
# Build Arguments # Build Arguments
$webrequest_opts = @{} $webrequest_opts = @{}
@ -64,7 +73,9 @@ try {
} }
ForEach ($prop in $response.psobject.properties) { ForEach ($prop in $response.psobject.properties) {
Set-Attr $result $prop.Name $prop.Value $result_key = ConvertTo-SnakeCase $prop.Name
$result_value = $prop.Value
Set-Attr $result $result_key $result_value
} }
Exit-Json $result Exit-Json $result

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2015, Corwin Brown <corwin.brown@maxpoint.com> # (c) 2015, Corwin Brown <corwin@corwinbrown.com>
# #
# This file is part of Ansible # This file is part of Ansible
# #
@ -27,7 +27,7 @@ module: win_uri
version_added: "2.1" version_added: "2.1"
short_description: Interacts with webservices. short_description: Interacts with webservices.
description: description:
- Interacts with HTTP and HTTPS services. - Interacts with HTTP and HTTPS web services and supports Digest, Basic and WSSE HTTP authentication mechanisms.
options: options:
url: url:
description: description:
@ -55,7 +55,7 @@ options:
- The body of the HTTP request/response to the web service. - The body of the HTTP request/response to the web service.
headers: headers:
description: description:
- Key Value pairs for headers. Example "Host: www.somesite.com" - 'Key Value pairs for headers. Example "Host: www.somesite.com"'
use_basic_parsing: use_basic_parsing:
description: description:
- This module relies upon 'Invoke-WebRequest', which by default uses the Internet Explorer Engine to parse a webpage. There's an edge-case where if a user hasn't run IE before, this will fail. The only advantage to using the Internet Explorer praser is that you can traverse the DOM in a powershell script. That isn't useful for Ansible, so by default we toggle 'UseBasicParsing'. However, you can toggle that off here. - This module relies upon 'Invoke-WebRequest', which by default uses the Internet Explorer Engine to parse a webpage. There's an edge-case where if a user hasn't run IE before, this will fail. The only advantage to using the Internet Explorer praser is that you can traverse the DOM in a powershell script. That isn't useful for Ansible, so by default we toggle 'UseBasicParsing'. However, you can toggle that off here.
@ -81,7 +81,7 @@ EXAMPLES = """
url: http://my.internal.server.com url: http://my.internal.server.com
method: GET method: GET
headers: headers:
host: "www.somesite.com host: "www.somesite.com"
# Do a HEAD request on an endpoint # Do a HEAD request on an endpoint
--- ---
@ -120,27 +120,27 @@ use_basic_parsing:
returned: always returned: always
type: bool type: bool
sample: True sample: True
StatusCode: status_code:
description: The HTTP Status Code of the response. description: The HTTP Status Code of the response.
returned: success returned: success
type: int type: int
sample: 200 sample: 200
StatusDescription: status_description:
description: A summery of the status. description: A summery of the status.
returned: success returned: success
type: string type: string
stample: "OK" stample: "OK"
RawContent: raw_content:
description: The raw content of the HTTP response. description: The raw content of the HTTP response.
returned: success returned: success
type: string type: string
sample: 'HTTP/1.1 200 OK\nX-XSS-Protection: 1; mode=block\nX-Frame-Options: SAMEORIGIN\nAlternate-Protocol: 443:quic,p=1\nAlt-Svc: quic="www.google.com:443"; ma=2592000; v="30,29,28,27,26,25",quic=":443"; ma=2...' sample: 'HTTP/1.1 200 OK\nX-XSS-Protection: 1; mode=block\nX-Frame-Options: SAMEORIGIN\nAlternate-Protocol: 443:quic,p=1\nAlt-Svc: quic="www.google.com:443"; ma=2592000; v="30,29,28,27,26,25",quic=":443"; ma=2...'
Headers: headers:
description: The Headers of the response. description: The Headers of the response.
returned: success returned: success
type: dict type: dict
sample: {"Content-Type": "application/json"} sample: {"Content-Type": "application/json"}
RawContentLength: raw_content_length:
description: The byte size of the response. description: The byte size of the response.
returned: success returned: success
type: int type: int

Loading…
Cancel
Save