コード例 #1
0
ファイル: EventTrigger.cs プロジェクト: narayanr7/TeamCloud
        internal static async Task <string> GetUrlAsync()
        {
            var masterKey = await FunctionsEnvironment
                            .GetAdminKeyAsync()
                            .ConfigureAwait(false);

            var hostUrl = await FunctionsEnvironment
                          .GetHostUrlAsync()
                          .ConfigureAwait(false);

            var json = await hostUrl
                       .AppendPathSegment("admin/host/systemkeys/eventgrid_extension")
                       .SetQueryParam("code", masterKey, isEncoded: true)
                       .GetJObjectAsync()
                       .ConfigureAwait(false);

            return(hostUrl
                   .AppendPathSegment("runtime/webhooks/eventgrid")
                   .SetQueryParam("functionName", nameof(EventTrigger))
                   .SetQueryParam("code", json.SelectToken("value")?.ToString())
                   .ToString());
        }
コード例 #2
0
        private static async Task <string> GetTokenAsync()
        {
            var masterKey = await FunctionsEnvironment
                            .GetAdminKeyAsync()
                            .ConfigureAwait(false);

            var hostUrl = await FunctionsEnvironment
                          .GetHostUrlAsync()
                          .ConfigureAwait(false);

            var json = await hostUrl
                       .AppendPathSegment("admin/functions")
                       .AppendPathSegment(nameof(CallbackTrigger))
                       .AppendPathSegment("keys")
                       .SetQueryParam("code", masterKey)
                       .GetJObjectAsync()
                       .ConfigureAwait(false);

            var tokens = json
                         .SelectTokens($"$.keys[?(@.name != 'default')].value")
                         .Select(token => token.ToString())
                         .ToArray();

            if (tokens.Length == 1)
            {
                return(tokens[0]);
            }
            else if (tokens.Length > 1)
            {
                return(tokens[new Random().Next(0, tokens.Length - 1)]);
            }

            return(json
                   .SelectToken($"$.keys[?(@.name == 'default')].value")?
                   .ToString());
        }