Skip to content

Commit

Permalink
Add MPS Secrets as Env Variables in Game Servers (#182)
Browse files Browse the repository at this point in the history
Co-authored-by: Jose Valenciano <[email protected]>
  • Loading branch information
jotavalenciano and Jose Valenciano authored Apr 10, 2024
1 parent 194f41a commit fd5f361
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
24 changes: 24 additions & 0 deletions VmAgent.Core.UnitTests/VmConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ public void EnvironmentVariablesWithMultipleIpAddresses()
envVariables.Should().Contain("PF_PUBLIC_IP_ADDRESSES_ROUTING_TYPE_1", "Microsoft");
}

[TestMethod]
[TestCategory("BVT")]
public void EnvironmentVariablesWithMpsSecrets()
{
SessionHostsStartInfo sessionHostsStartInfo = CreateSessionHostStartInfo(new Dictionary<string, string>());
sessionHostsStartInfo.GameSecrets = new SecretDetail[]
{
new SecretDetail()
{
Name = "secret1",
Value = "value1"
},
new SecretDetail()
{
Name = "secret2",
Value = "value2"
}
};

IDictionary<string, string> envVariables = VmConfiguration.GetCommonEnvironmentVariables(sessionHostsStartInfo, VmConfiguration);
envVariables.Should().Contain("PF_MPS_SECRET_secret1", "value1");
envVariables.Should().Contain("PF_MPS_SECRET_secret2", "value2");
}


private SessionHostsStartInfo CreateSessionHostStartInfo(IDictionary<string, string> buildMetadata = null, SessionHostType sessionHostType = SessionHostType.Process)
{
Expand Down
11 changes: 11 additions & 0 deletions VmAgent.Core/VmConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class VmConfiguration
/// Prefix used for all the Public Ip Addresses environment variables (count, ip addresss, fqdn, routing type)
public const string PublicIpAddressesEnvVariablePrefix = "PF_PUBLIC_IP_ADDRESSES";

// Prefix for each secret configured in PlayFab MPS and saved as environment variable
public const string PlayfabMpsSecretEnvVariablePrefix = "PF_MPS_SECRET";

private static readonly byte[] PlayFabTitleIdPrefix = BitConverter.GetBytes(0xFFFFFFFFFFFFFFFF);

public int ListeningPort { get; }
Expand Down Expand Up @@ -117,6 +120,8 @@ public static IDictionary<string, string> GetCommonEnvironmentVariables(SessionH

environmentVariables.AddRange(GetPublicIpAddressesEnvironmentVariables(sessionHostsStartInfo));

environmentVariables.AddRange(GetEnvironmentVariablesWithPlayFabMpsSecrets(sessionHostsStartInfo));

return environmentVariables;
}

Expand Down Expand Up @@ -148,6 +153,12 @@ private static IDictionary<string, string> GetPublicIpAddressesEnvironmentVariab
return publicIPAddressesEnvironmentVariables;
}

private static IDictionary<string, string> GetEnvironmentVariablesWithPlayFabMpsSecrets(SessionHostsStartInfo sessionHostsStartInfo)
{
return sessionHostsStartInfo.GameSecrets?.ToDictionary(
secretDetail => $"{PlayfabMpsSecretEnvVariablePrefix}_{secretDetail.Name}", secretDetail => secretDetail.Value) ?? new Dictionary<string, string>();
}

private static string GetSharedContentFolderPath(SessionHostsStartInfo sessionHostsStartInfo, VmConfiguration vmConfiguration)
{
switch (sessionHostsStartInfo.SessionHostType)
Expand Down

0 comments on commit fd5f361

Please sign in to comment.