This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
stas
committed
May 3, 2022
1 parent
fd28ba3
commit 49ac48c
Showing
4 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/ApiService/ApiService/TestHooks/ExtensionsTestHooks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.OneFuzz.Service; | ||
|
||
|
||
#if DEBUG | ||
namespace ApiService.TestHooks { | ||
|
||
public class ExtensionsTestHooks { | ||
|
||
private readonly ILogTracer _log; | ||
private readonly IConfigOperations _configOps; | ||
private readonly IExtensions _extensions; | ||
|
||
public ExtensionsTestHooks(ILogTracer log, IConfigOperations configOps, IExtensions extensions) { | ||
_log = log.WithTag("TestHooks", nameof(ExtensionsTestHooks)); | ||
_configOps = configOps; | ||
_extensions = extensions; | ||
} | ||
|
||
[Function("GenericExtensionsHook")] | ||
public async Task<HttpResponseData> GenericExtensions([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "testhooks/extensions/genericExtensions")] HttpRequestData req) { | ||
_log.Info("Get Generic extensions"); | ||
|
||
var query = UriExtension.GetQueryComponents(req.Url); | ||
|
||
Os os; | ||
if (query["os"].ToLowerInvariant() == "windows") { | ||
os = Os.Windows; | ||
} else if (query["os"].ToLowerInvariant() == "linux") { | ||
os = Os.Linux; | ||
} else { | ||
var err = req.CreateResponse(HttpStatusCode.BadRequest); | ||
await err.WriteAsJsonAsync(new { error = $"unsupported os {query["os"]}" }); | ||
return err; | ||
} | ||
|
||
var ext = await (_extensions as Extensions)!.GenericExtensions(query["region"], os); | ||
var resp = req.CreateResponse(HttpStatusCode.OK); | ||
|
||
await resp.WriteAsJsonAsync(ext); | ||
|
||
return resp; | ||
} | ||
|
||
|
||
|
||
} | ||
} | ||
|
||
#endif |
95 changes: 95 additions & 0 deletions
95
src/ApiService/ApiService/TestHooks/IpOperationsTestHooks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.OneFuzz.Service; | ||
|
||
|
||
#if DEBUG | ||
namespace ApiService.TestHooks { | ||
public class IpOperationsTestHooks { | ||
private readonly ILogTracer _log; | ||
private readonly IConfigOperations _configOps; | ||
private readonly IIpOperations _ipOps; | ||
|
||
public IpOperationsTestHooks(ILogTracer log, IConfigOperations configOps, IIpOperations ipOps) { | ||
_log = log.WithTag("TestHooks", nameof(IpOperationsTestHooks)); | ||
_configOps = configOps; | ||
_ipOps = ipOps; | ||
} | ||
|
||
[Function("GetPublicNicTestHook")] | ||
public async Task<HttpResponseData> GetPublicNic([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "testhooks/ipOps/publicNic")] HttpRequestData req) { | ||
_log.Info("Get public nic"); | ||
|
||
var query = UriExtension.GetQueryComponents(req.Url); | ||
|
||
var rg = query["rg"]; | ||
var name = query["name"]; | ||
|
||
var nic = await _ipOps.GetPublicNic(rg, name); | ||
|
||
var resp = req.CreateResponse(HttpStatusCode.OK); | ||
await resp.WriteStringAsync(nic.Get().Value.Data.Name); | ||
return resp; | ||
} | ||
|
||
[Function("GetIpTestHook")] | ||
public async Task<HttpResponseData> GetIp([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "testhooks/ipOps/ip")] HttpRequestData req) { | ||
_log.Info("Get public nic"); | ||
|
||
var query = UriExtension.GetQueryComponents(req.Url); | ||
|
||
var rg = query["rg"]; | ||
var name = query["name"]; | ||
|
||
var ip = await _ipOps.GetIp(rg, name); | ||
|
||
var resp = req.CreateResponse(HttpStatusCode.OK); | ||
await resp.WriteStringAsync(ip.Get().Value.Data.Name); | ||
return resp; | ||
} | ||
|
||
|
||
[Function("DeletePublicNicTestHook")] | ||
public async Task<HttpResponseData> DeletePublicNic([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "testhooks/ipOps/publicNic")] HttpRequestData req) { | ||
_log.Info("Get public nic"); | ||
|
||
var query = UriExtension.GetQueryComponents(req.Url); | ||
|
||
var rg = query["rg"]; | ||
var name = query["name"]; | ||
var yes = UriExtension.GetBoolValue("force", query, false); | ||
|
||
if (yes) { | ||
await _ipOps.DeleteNic(rg, name); | ||
var resp = req.CreateResponse(HttpStatusCode.OK); | ||
return resp; | ||
} else { | ||
var resp = req.CreateResponse(HttpStatusCode.NotModified); | ||
return resp; | ||
} | ||
} | ||
|
||
[Function("DeleteIpTestHook")] | ||
public async Task<HttpResponseData> DeleteIp([HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "testhooks/ipOps/ip")] HttpRequestData req) { | ||
_log.Info("Get public nic"); | ||
|
||
var query = UriExtension.GetQueryComponents(req.Url); | ||
|
||
var rg = query["rg"]; | ||
var name = query["name"]; | ||
var yes = UriExtension.GetBoolValue("force", query, false); | ||
|
||
if (yes) { | ||
await _ipOps.DeleteIp(rg, name); | ||
var resp = req.CreateResponse(HttpStatusCode.OK); | ||
return resp; | ||
} else { | ||
var resp = req.CreateResponse(HttpStatusCode.NotModified); | ||
return resp; | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters