-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.cs
46 lines (39 loc) · 1.53 KB
/
module.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
namespace frpsug
{
using Runtime;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
/// <summary>A class that contains the module-common code and data.</summary>
/// <notes>
/// This is a modified version from https://github.com/Azure/autorest/blob/master/docs/powershell/samples/timeswire/generated/custom/Module.cs
/// </notes>
public partial class Module
{
partial void CustomInit()
{
// we need to add a step at the end of the pipeline
// to attach the API key
// once for the regular pipeline
this._pipeline.Append(AddApiKey);
// once for the pipeline that supports a proxy
this._pipelineWithProxy.Append(AddApiKey);
}
protected async Task<HttpResponseMessage> AddApiKey(HttpRequestMessage request, IEventListener callback, ISendAsync next)
{
// does the request already have a query?
var sepChar = string.IsNullOrEmpty(request.RequestUri.Query) ? "?" : "&";
// add on the apikey
request.RequestUri = new System.Uri(
request.RequestUri.AbsoluteUri +
sepChar +
"api_key=" +
// we'll cheat and pull it from the environment :D
System.Environment.GetEnvironmentVariable("nasaapikey")
);
// let it go on.
return await next.SendAsync(request, callback);
}
}
}