Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 43b815b

Browse files
committed
CA-345342: Made the query parameters of the http actions optional and nullable.
Note that some of them are not optional, however, the current definition does not allow for distinguishing them from the mandatory ones, and as a consequence it is easier to mark them all as optional than provide method overloads manually. Also: - Fixed issue where the parameters set to false were ignored. - Exposed manually in the SDK http actions removed from the API. Signed-off-by: Konstantina Chremmou <[email protected]>
1 parent e5c4ed6 commit 43b815b

File tree

7 files changed

+179
-31
lines changed

7 files changed

+179
-31
lines changed

csharp/autogen/src/HTTP.cs

+18-24
Original file line numberDiff line numberDiff line change
@@ -358,37 +358,31 @@ public static Uri BuildUri(string hostname, string path, params object[] args)
358358
flatargs.Add(arg);
359359
}
360360

361-
UriBuilder uri = new UriBuilder();
362-
uri.Scheme = "https";
363-
uri.Port = DEFAULT_HTTPS_PORT;
364-
uri.Host = hostname;
365-
uri.Path = path;
366-
367-
StringBuilder query = new StringBuilder();
361+
var query = new StringBuilder();
368362
for (int i = 0; i < flatargs.Count - 1; i += 2)
369363
{
370-
string kv;
371-
372-
// If the argument is null, don't include it in the URL
373-
if (flatargs[i + 1] == null)
364+
if (flatargs[i + 1] == null)//skip null arguments
374365
continue;
375366

376-
// bools are special because some xapi calls use presence/absence and some
377-
// use "b=true" (not "True") and "b=false". But all accept "b=true" or absent.
378-
if (flatargs[i + 1] is bool)
379-
{
380-
if (!((bool)flatargs[i + 1]))
381-
continue;
382-
kv = flatargs[i] + "=true";
383-
}
384-
else
385-
kv = flatargs[i] + "=" + Uri.EscapeDataString(flatargs[i + 1].ToString());
386-
387367
if (query.Length != 0)
388368
query.Append('&');
389-
query.Append(kv);
369+
370+
query.Append(flatargs[i]).Append("=");
371+
372+
if (flatargs[i + 1] is bool)
373+
query.Append((bool)flatargs[i + 1] ? "true" : "false");
374+
else
375+
query.Append(Uri.EscapeDataString(flatargs[i + 1].ToString()));
390376
}
391-
uri.Query = query.ToString();
377+
378+
UriBuilder uri = new UriBuilder
379+
{
380+
Scheme = "https",
381+
Port = DEFAULT_HTTPS_PORT,
382+
Host = hostname,
383+
Path = path,
384+
Query = query.ToString()
385+
};
392386

393387
return uri.Uri;
394388
}

csharp/gen_csharp_binding.ml

+4-4
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ and gen_http_actions() =
178178
(unique public name, (HTTP method, URI, whether to expose in SDK, [args to expose in SDK], [allowed_roles], [(sub-action,allowed_roles)]))
179179
*)
180180
let decl_of_sdkarg = function
181-
| String_query_arg s -> "string " ^ (escaped s)
182-
| Int64_query_arg s -> "long " ^ (escaped s)
183-
| Bool_query_arg s -> "bool " ^ (escaped s)
181+
| String_query_arg s -> sprintf "string %s = null" (escaped s)
182+
| Int64_query_arg s -> sprintf "long? %s = null" (escaped s)
183+
| Bool_query_arg s -> sprintf "bool? %s = null" (escaped s)
184184
| Varargs_query_arg -> "params string[] args /* alternate names and values */"
185185
in
186186
let use_of_sdkarg = function
187187
| String_query_arg s
188188
| Int64_query_arg s
189-
| Bool_query_arg s -> sprintf "\"%s\", %s" s (escaped s)
189+
| Bool_query_arg s -> sprintf {|"%s", %s|} s (escaped s)
190190
| Varargs_query_arg -> "args"
191191
in
192192
let delegate_type = function

csharp/templates/HTTP_actions.mustache

+14
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,19 @@ namespace XenAPI
2929
}
3030

3131
{{/http_actions}}
32+
33+
public static void get_pool_patch_download(HTTP.DataCopiedDelegate dataCopiedDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
34+
string hostname, IWebProxy proxy, string path, string task_id, string session_id, string uuid)
35+
{
36+
Get(dataCopiedDelegate, cancellingDelegate, timeout_ms, hostname, "/pool_patch_download", proxy, path,
37+
"task_id", task_id, "session_id", session_id, "uuid", uuid);
38+
}
39+
40+
public static void put_oem_patch_stream(HTTP.UpdateProgressDelegate progressDelegate, HTTP.FuncBool cancellingDelegate, int timeout_ms,
41+
string hostname, IWebProxy proxy, string path, string task_id, string session_id)
42+
{
43+
Put(progressDelegate, cancellingDelegate, timeout_ms, hostname, "/oem_patch_stream", proxy, path,
44+
"task_id", task_id, "session_id", session_id);
45+
}
3246
}
3347
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) Citrix Systems, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1) Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* 2) Redistributions in binary form must reproduce the above
13+
* copyright notice, this list of conditions and the following
14+
* disclaimer in the documentation and/or other materials
15+
* provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
32+
using System;
33+
using System.Collections;
34+
using System.Collections.Generic;
35+
using System.Management.Automation;
36+
using System.Text;
37+
38+
using XenAPI;
39+
40+
namespace Citrix.XenServer.Commands
41+
{
42+
[Cmdlet(VerbsCommunications.Receive, "XenPoolPatch", SupportsShouldProcess = false)]
43+
[OutputType(typeof(void))]
44+
public class ReceiveXenPoolPatchCommand : XenServerHttpCmdlet
45+
{
46+
#region Cmdlet Parameters
47+
48+
[Parameter]
49+
public HTTP.DataCopiedDelegate DataCopiedDelegate { get; set; }
50+
51+
[Parameter(ValueFromPipelineByPropertyName = true)]
52+
public string Uuid { get; set; }
53+
54+
#endregion
55+
56+
#region Cmdlet Methods
57+
58+
protected override void ProcessRecord()
59+
{
60+
GetSession();
61+
62+
RunApiCall(() => XenAPI.HTTP_actions.get_pool_patch_download(DataCopiedDelegate,
63+
CancellingDelegate, TimeoutMs, XenHost, Proxy, Path, TaskRef,
64+
session.opaque_ref, Uuid));
65+
}
66+
67+
#endregion
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) Citrix Systems, Inc.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1) Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* 2) Redistributions in binary form must reproduce the above
13+
* copyright notice, this list of conditions and the following
14+
* disclaimer in the documentation and/or other materials
15+
* provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
32+
using System;
33+
using System.Collections;
34+
using System.Collections.Generic;
35+
using System.Management.Automation;
36+
using System.Text;
37+
38+
using XenAPI;
39+
40+
namespace Citrix.XenServer.Commands
41+
{
42+
[Cmdlet(VerbsCommunications.Send, "XenOemPatchStream", SupportsShouldProcess = true)]
43+
[OutputType(typeof(void))]
44+
public class SendXenOemPatchStreamCommand : XenServerHttpCmdlet
45+
{
46+
#region Cmdlet Parameters
47+
48+
[Parameter]
49+
public HTTP.UpdateProgressDelegate ProgressDelegate { get; set; }
50+
51+
#endregion
52+
53+
#region Cmdlet Methods
54+
55+
protected override void ProcessRecord()
56+
{
57+
GetSession();
58+
59+
if (!ShouldProcess("/oem_patch_stream"))
60+
return;
61+
62+
RunApiCall(() => XenAPI.HTTP_actions.put_oem_patch_stream(ProgressDelegate,
63+
CancellingDelegate, TimeoutMs, XenHost, Proxy, Path, TaskRef,
64+
session.opaque_ref));
65+
}
66+
67+
#endregion
68+
}
69+
}

powershell/gen_powershell_binding.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ and gen_arg_param = function
191191
(pascal_case_ x)
192192
| Int64_query_arg x -> sprintf "
193193
[Parameter]
194-
public long %s { get; set; }\n" (pascal_case_ x)
194+
public long? %s { get; set; }\n" (pascal_case_ x)
195195
| Bool_query_arg x ->
196196
let y = if x = "host" then "is_host" else x in
197197
sprintf "
198198
[Parameter]
199-
public bool %s { get; set; }\n" (pascal_case_ y)
199+
public bool? %s { get; set; }\n" (pascal_case_ y)
200200
| Varargs_query_arg -> sprintf "
201201
///<summary>
202-
/// Alternate names & values
202+
/// Alternate names and values
203203
///</summary>
204204
[Parameter]
205205
public string[] Args { get; set; }\n"

powershell/templates/XenServerPowerShell.csproj.mustache

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
<Compile Include="ConvertTo-XenRef.cs" />
6464
<Compile Include="Disconnect-XenServer.cs" />
6565
<Compile Include="Get-XenSession.cs" />
66+
<Compile Include="Receive-XenPoolPatch.cs" />
67+
<Compile Include="Send-XenOemPatchStream.cs" />
6668
<Compile Include="Wait-XenTask.cs" />
6769
<Compile Include="XenServerCmdlet.cs" />
6870
<Compile Include="XenServerHttpCmdlet.cs" />

0 commit comments

Comments
 (0)