Skip to content

Playfab allocator - #2

Merged
tristan-unity merged 10 commits into
developfrom
playfab-allocator
Dec 15, 2025
Merged

tristan-unity merged 10 commits into
developfrom
playfab-allocator

Conversation

@tristan-unity

Copy link
Copy Markdown
Contributor

No description provided.

@arthur-joly
arthur-joly changed the base branch from main to develop December 12, 2025 21:48
Comment on lines +50 to +63

[CloudCodeFunction(nameof(Allocate))]
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request)
{
try
{
PlayFabSettings.staticSettings.DeveloperSecretKey = (await _gameApiClient.SecretManager.GetSecret(context, DeveloperSecretKey)).Value;
}
catch (Exception e)
{
const string error = $"An error occured when retrieving secrets for key '{DeveloperSecretKey}'.";
LogError(error, e);
return new AllocateResponse(AllocateStatus.Error) { Message = AllocationUserFriendlyError };
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can copy/paste the try/catch for all GetSecret calls or we could also introduce a TryGetSecret like so:

Suggested change
[CloudCodeFunction(nameof(Allocate))]
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request)
{
try
{
PlayFabSettings.staticSettings.DeveloperSecretKey = (await _gameApiClient.SecretManager.GetSecret(context, DeveloperSecretKey)).Value;
}
catch (Exception e)
{
const string error = $"An error occured when retrieving secrets for key '{DeveloperSecretKey}'.";
LogError(error, e);
return new AllocateResponse(AllocateStatus.Error) { Message = AllocationUserFriendlyError };
}
bool TryGetSecret(IExecutionContext context, string secretKey, out string secretValue)
{
try
{
secretValue = _gameApiClient.SecretManager.GetSecret(context, secretKey).Result.Value;
return true;
}
catch (Exception e)
{
var error = $"An error occured when retrieving secrets for key '{secretKey}'.";
LogError(error, e);
}
secretValue = string.Empty;
return false;
}
[CloudCodeFunction(nameof(Allocate))]
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request)
{
if (!TryGetSecret(context, DeveloperSecretKey, out var developerSecret))
{
return new AllocateResponse(AllocateStatus.Error) { Message = AllocationUserFriendlyError };
}
PlayFabSettings.staticSettings.DeveloperSecretKey = developerSecret;

With the caveat that it's a blocking call, not an async call anymore.

What do you think ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldnt be introducing blocking calls. Task.Result is a dangerous code smell.

const string DeveloperSecretKey = "DEVELOPER_SECRET_KEY";

/// <summary>
/// You will need to set up a secret in the <a

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a local const rather than a secret?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was but then I checked how GameLift allocator was doing it and it is using the secret store.
So I changed it to be consistent with GameLift allocator.

/// href="https://cloud.unity.com">Unity Dashboard</a> with
/// the <c>TITLE_ID</c> key containing your PlayFab Title Id.
/// </summary>
const string PlayfabTitleId = "TITLE_ID";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a local const rather than a secret?

Comment on lines +50 to +63

[CloudCodeFunction(nameof(Allocate))]
public async Task<AllocateResponse> Allocate(IExecutionContext context, AllocateRequest request)
{
try
{
PlayFabSettings.staticSettings.DeveloperSecretKey = (await _gameApiClient.SecretManager.GetSecret(context, DeveloperSecretKey)).Value;
}
catch (Exception e)
{
const string error = $"An error occured when retrieving secrets for key '{DeveloperSecretKey}'.";
LogError(error, e);
return new AllocateResponse(AllocateStatus.Error) { Message = AllocationUserFriendlyError };
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldnt be introducing blocking calls. Task.Result is a dangerous code smell.

{
AllocationData = new Dictionary<string, object>
{
{ "sessionId", allocationResult.Result.SessionId },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only "sessionId" is used in Poll. Why set the other values?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true.
Same reason as above, I aligned on what GameLift allocator was doing to be consistent.

@tristan-unity
tristan-unity merged commit ae95e2f into develop Dec 15, 2025
4 of 5 checks passed
@tristan-unity
tristan-unity deleted the playfab-allocator branch December 15, 2025 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants