Skip to content

Commit

Permalink
Adding api to retrieve environment variables (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
karshinlin authored Apr 14, 2021
1 parent 740a26a commit d4bb543
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Kudu.Contracts/Diagnostics/ProcessEnvironmentInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using Kudu.Contracts.Infrastructure;
using Newtonsoft.Json;

namespace Kudu.Contracts.Diagnostics
{
public class ProcessEnvironmentInfo : Dictionary<string, string>, INamedObject
{
private readonly string _name;

public ProcessEnvironmentInfo()
{
}

public ProcessEnvironmentInfo(string name, Dictionary<string, string> values)
: base(values)
{
_name = name;
}

[JsonProperty(PropertyName = "name")]
string INamedObject.Name { get { return _name; } }
}
}
3 changes: 3 additions & 0 deletions Kudu.Services.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ public void Configure(IApplicationBuilder app,
routes.MapHttpProcessesRoute("one-process-module", "/{id}/modules/{baseAddress}",
new {controller = processControllerName, action = "GetModule"},
new {verb = new HttpMethodRouteConstraint("GET")});
routes.MapHttpProcessesRoute("all-envs", "/{id}/environments/{filter}",
new { controller = processControllerName, action = "GetEnvironments" },
new { verb = new HttpMethodRouteConstraint("GET") });

// Runtime
routes.MapHttpRouteDual("runtime", "diagnostics/runtime",
Expand Down
16 changes: 16 additions & 0 deletions Kudu.Services/Diagnostics/LinuxProcessController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using Kudu.Contracts.Diagnostics;
using Kudu.Services.Arm;
using Microsoft.AspNetCore.Mvc;

namespace Kudu.Services.Performance
Expand Down Expand Up @@ -91,5 +96,16 @@ public IActionResult StopProfileAsync(int id)
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return new JsonResult(ERRORMSG);
}

[HttpGet]
public IActionResult GetEnvironments(int id, string filter)
{
var envs = System.Environment.GetEnvironmentVariables()
.Cast<DictionaryEntry>().ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString())
.Where(p => string.Equals("all", filter, StringComparison.OrdinalIgnoreCase) || p.Key.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)
.ToDictionary(p => p.Key, p => p.Value);

return Ok(ArmUtils.AddEnvelopeOnArmRequest(new ProcessEnvironmentInfo(filter, envs), Request));
}
}
}

0 comments on commit d4bb543

Please sign in to comment.