Пример #1
0
        /// <summary>
        /// Creates a function that when invoked returns a valid authentication header
        /// </summary>
        /// <param name="sentryVersion">The sentry version.</param>
        /// <param name="clientVersion">The client version.</param>
        /// <param name="publicKey">The public key.</param>
        /// <param name="secretKey">The secret key.</param>
        /// <param name="clock">The clock.</param>
        /// <returns></returns>
        public static Action <HttpRequestHeaders> AddSentryAuth(
            int sentryVersion,
            string clientVersion,
            string publicKey,
            string secretKey,
            ISystemClock clock = null)
        {
            clock = clock ?? SystemClock.Clock;

            var baseAuthHeader = $"Sentry sentry_version={sentryVersion}," +
                                 $"sentry_client={clientVersion}," +
                                 $"sentry_key={publicKey}," +
                                 (secretKey != null ? $"sentry_secret={secretKey}," : null) +
                                 "sentry_timestamp=";

            return((headers) => headers.Add(
                       SentryAuthHeader,
                       baseAuthHeader + clock.GetUtcNow().ToUnixTimeSeconds()));
        }
Пример #2
0
        internal HttpRequestMessage CreateRequest(Envelope envelope)
        {
            if (string.IsNullOrWhiteSpace(_options.Dsn))
            {
                throw new InvalidOperationException("The DSN is expected to be set at this point.");
            }

            var dsn = Dsn.Parse(_options.Dsn);

            var authHeader =
                $"Sentry sentry_version={_options.SentryVersion}," +
                $"sentry_client={_options.ClientVersion}," +
                $"sentry_key={dsn.PublicKey}," +
                (dsn.SecretKey is { } secretKey ? $"sentry_secret={secretKey}," : null) +
                $"sentry_timestamp={_clock.GetUtcNow().ToUnixTimeSeconds()}";

            return(new HttpRequestMessage
            {
                RequestUri = dsn.GetEnvelopeEndpointUri(),
                Method = HttpMethod.Post,
                Headers = { { "X-Sentry-Auth", authHeader } },
                Content = new EnvelopeHttpContent(envelope)
            });
        }