Skip to content

Commit

Permalink
feature/app-check/ReplacePlaceholders
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlo committed Jan 29, 2024
1 parent 28f60b9 commit ec540fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
10 changes: 5 additions & 5 deletions FirebaseAdmin/FirebaseAdmin/AppCheck/AppCheckApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ internal sealed class AppCheckApiClient : IDisposable

internal AppCheckApiClient(Args args)
{
string noProjectId = "Project ID is required to access app check service. Use a service account "
if (string.IsNullOrEmpty(args.ProjectId))
{
string noProjectId = "Project ID is required to access app check service. Use a service account "
+ "credential or set the project ID explicitly via AppOptions. Alternatively "
+ "you can set the project ID via the GOOGLE_CLOUD_PROJECT environment "
+ "variable.";
if (string.IsNullOrEmpty(args.ProjectId))
{
throw new FirebaseAppCheckException(
ErrorCode.InvalidArgument,
noProjectId,
Expand Down Expand Up @@ -216,7 +216,7 @@ private string GetUrl(string appId)
{ "appId", appId },
};

return HttpUtils.FormatString(AppCheckUrlFormat, urlParams);
return StringUtils.ReplacePlaceholders(AppCheckUrlFormat, urlParams);
}

private int StringToMilliseconds(string duration)
Expand Down Expand Up @@ -244,7 +244,7 @@ private string GetVerifyTokenUrl()
{ "projectId", this.projectId },
};

return HttpUtils.FormatString(OneTimeUseTokenVerificationUrlFormat, urlParams);
return StringUtils.ReplacePlaceholders(OneTimeUseTokenVerificationUrlFormat, urlParams);
}

internal sealed class Args
Expand Down
11 changes: 0 additions & 11 deletions FirebaseAdmin/FirebaseAdmin/Util/HttpUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ internal sealed class HttpUtils

private HttpUtils() { }

public static string FormatString(string str, Dictionary<string, string> urlParams)
{
string formatted = str;
foreach (var key in urlParams.Keys)
{
formatted = Regex.Replace(formatted, $"{{{key}}}", urlParams[key]);
}

return formatted;
}

internal static string EncodeQueryParams(IDictionary<string, object> queryParams)
{
var queryString = string.Empty;
Expand Down
21 changes: 21 additions & 0 deletions FirebaseAdmin/FirebaseAdmin/Util/StringUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace FirebaseAdmin.Util
{
internal class StringUtils
{
public static string ReplacePlaceholders(string str, Dictionary<string, string> urlParams)
{
string formatted = str;
foreach (var key in urlParams.Keys)
{
formatted = Regex.Replace(formatted, $"{{{key}}}", urlParams[key]);
}

return formatted;
}
}
}

0 comments on commit ec540fd

Please sign in to comment.