public void GetDaprApiTokenHeader_ApiTokenSet_SetsApiTokenHeader()
        {
            var token = "test_token";
            var entry = DaprClient.GetDaprApiTokenHeader(token);

            Assert.Equal("test_token", entry.Value);
        }
Example #2
0
        /// <summary>
        /// Builds a <see cref="DaprClient" /> instance from the properties of the builder.
        /// </summary>
        /// <returns>The <see cref="DaprClient" />.</returns>
        public DaprClient Build()
        {
            var grpcEndpoint = new Uri(this.GrpcEndpoint);

            if (grpcEndpoint.Scheme != "http" && grpcEndpoint.Scheme != "https")
            {
                throw new InvalidOperationException("The gRPC endpoint must use http or https.");
            }

            if (grpcEndpoint.Scheme.Equals(Uri.UriSchemeHttp))
            {
                // Set correct switch to maksecure gRPC service calls. This switch must be set before creating the GrpcChannel.
                AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            }

            var httpEndpoint = new Uri(this.HttpEndpoint);

            if (httpEndpoint.Scheme != "http" && httpEndpoint.Scheme != "https")
            {
                throw new InvalidOperationException("The HTTP endpoint must use http or https.");
            }

            var channel = GrpcChannel.ForAddress(this.GrpcEndpoint, this.GrpcChannelOptions);
            var client  = new Autogenerated.Dapr.DaprClient(channel);

            var apiTokenHeader = DaprClient.GetDaprApiTokenHeader(this.DaprApiToken);
            var httpClient     = HttpClientFactory is object?HttpClientFactory() : new HttpClient();

            return(new DaprClientGrpc(channel, client, httpClient, httpEndpoint, this.JsonSerializerOptions, apiTokenHeader));
        }
Example #3
0
        public void GetDaprApiTokenHeader_ApiTokenNotSet_NullApiTokenHeader()
        {
            var entry = DaprClient.GetDaprApiTokenHeader(null);

            Assert.Equal(default, entry);