|
| 1 | +/* |
| 2 | + * Copyright 2023 The Dapr Authors |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
1 | 14 | package io.dapr.workflows.internal;
|
2 | 15 |
|
3 | 16 | import io.dapr.client.Headers;
|
|
10 | 23 | import io.grpc.Metadata;
|
11 | 24 | import io.grpc.MethodDescriptor;
|
12 | 25 |
|
13 |
| -public class APITokenClientInterceptor implements ClientInterceptor { |
14 |
| - @Override |
15 |
| - public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( |
16 |
| - MethodDescriptor<ReqT, RespT> methodDescriptor, |
17 |
| - CallOptions options, |
18 |
| - Channel channel) { |
19 |
| - // TBD: do we need timeout in workflow client? |
20 |
| - ClientCall<ReqT, RespT> clientCall = channel.newCall(methodDescriptor, options); |
21 |
| - return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(clientCall) { |
| 26 | +public class ApiTokenClientInterceptor implements ClientInterceptor { |
| 27 | + @Override |
| 28 | + public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( |
| 29 | + MethodDescriptor<ReqT, RespT> methodDescriptor, |
| 30 | + CallOptions options, |
| 31 | + Channel channel) { |
| 32 | + // TBD: do we need timeout in workflow client? |
| 33 | + ClientCall<ReqT, RespT> clientCall = channel.newCall(methodDescriptor, options); |
| 34 | + return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(clientCall) { |
22 | 35 | @Override
|
23 | 36 | public void start(final Listener<RespT> responseListener, final Metadata metadata) {
|
24 |
| - String daprApiToken = Properties.API_TOKEN.get(); |
25 |
| - if (daprApiToken != null) { |
26 |
| - metadata.put(Metadata.Key.of(Headers.DAPR_API_TOKEN, Metadata.ASCII_STRING_MARSHALLER), daprApiToken); |
27 |
| - } |
28 |
| - super.start(responseListener, metadata); |
| 37 | + String daprApiToken = Properties.API_TOKEN.get(); |
| 38 | + if (daprApiToken != null) { |
| 39 | + metadata.put(Metadata.Key.of(Headers.DAPR_API_TOKEN, Metadata.ASCII_STRING_MARSHALLER), daprApiToken); |
| 40 | + } |
| 41 | + super.start(responseListener, metadata); |
29 | 42 | }
|
30 |
| - }; |
31 |
| - } |
| 43 | + }; |
| 44 | + } |
32 | 45 | }
|
0 commit comments