in src/RequestProcessor.cs [100:154]
internal StreamingMessage ProcessWorkerInitRequest(StreamingMessage request)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var workerInitRequest = request.WorkerInitRequest;
Environment.SetEnvironmentVariable("AZUREPS_HOST_ENVIRONMENT", $"AzureFunctions/{workerInitRequest.HostVersion}");
Environment.SetEnvironmentVariable("POWERSHELL_DISTRIBUTION_CHANNEL", $"Azure-Functions:{workerInitRequest.HostVersion}");
// Set the environment variable to force the Get-AzAccessToken to return a
// plaintext token and avoid the planned breaking change.
// TODO: Remove this for the next PowerShell version (7.6).
Environment.SetEnvironmentVariable("AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN", "true");
StreamingMessage response = NewStreamingMessageTemplate(
request.RequestId,
StreamingMessage.ContentOneofCase.WorkerInitResponse,
out StatusResult status);
response.WorkerInitResponse.Capabilities.Add("RpcHttpBodyOnly", "true");
response.WorkerInitResponse.Capabilities.Add("WorkerStatus", "true");
if (OpenTelemetryController.IsOpenTelemetryEnvironmentEnabled())
{
response.WorkerInitResponse.Capabilities.Add("WorkerOpenTelemetryEnabled", "true");
}
// If the environment variable is set, spin up the custom named pipe server.
// This is typically used for debugging. It will throw a friendly exception if the
// pipe name is not a valid pipename.
string pipeName = Environment.GetEnvironmentVariable("PSWorkerCustomPipeName");
if (!string.IsNullOrEmpty(pipeName))
{
RpcLogger.WriteSystemLog(LogLevel.Trace, string.Format(PowerShellWorkerStrings.SpecifiedCustomPipeName, pipeName));
RemoteSessionNamedPipeServer.CreateCustomNamedPipeServer(pipeName);
}
try
{
var rpcLogger = new RpcLogger(_msgStream);
rpcLogger.SetContext(request.RequestId, null);
response.WorkerInitResponse.WorkerMetadata = GetWorkerMetadata(_pwshVersion);
rpcLogger.Log(isUserOnlyLog: false, LogLevel.Trace, string.Format(PowerShellWorkerStrings.WorkerInitCompleted, stopwatch.ElapsedMilliseconds));
}
catch (Exception e)
{
status.Status = StatusResult.Types.Status.Failure;
status.Exception = e.ToRpcException();
return response;
}
return response;
}