66import com .google .gson .Gson ;
77import com .google .gson .reflect .TypeToken ;
88import com .microsoft .tunnels .contracts .Tunnel ;
9- import com .microsoft .tunnels .contracts .TunnelAccessControl ;
109import com .microsoft .tunnels .contracts .TunnelAccessControlEntry ;
1110import com .microsoft .tunnels .contracts .TunnelAccessScopes ;
1211import com .microsoft .tunnels .contracts .TunnelConnectionMode ;
1312import com .microsoft .tunnels .contracts .TunnelContracts ;
1413import com .microsoft .tunnels .contracts .TunnelEndpoint ;
1514import com .microsoft .tunnels .contracts .TunnelPort ;
1615
17- import java .io .UnsupportedEncodingException ;
1816import java .lang .reflect .Type ;
1917import java .net .URI ;
2018import java .net .URISyntaxException ;
21- import java .net .URLEncoder ;
2219import java .net .http .HttpClient ;
2320import java .net .http .HttpRequest ;
2421import java .net .http .HttpRequest .BodyPublishers ;
@@ -242,7 +239,7 @@ private URI buildUri(String clusterId,
242239
243240 String queryString = "" ;
244241 if (options != null ) {
245- queryString = toQueryString (options );
242+ queryString = options . toQueryString ();
246243 }
247244 if (query != null ) {
248245 queryString += StringUtils .isBlank (queryString ) ? query : "&" + query ;
@@ -263,38 +260,10 @@ private URI buildUri(String clusterId,
263260 }
264261 }
265262
266- private String toQueryString (TunnelRequestOptions options ) {
267- final String encoding = "UTF-8" ;
268- var queryOptions = new ArrayList <String >();
269- if (options .includePorts ) {
270- queryOptions .add ("includePorts=true" );
271- }
272-
273- if (options .scopes != null ) {
274- TunnelAccessControl .validateScopes (options .scopes , null );
275- try {
276- queryOptions .add ("scopes=" + URLEncoder .encode (String .join ("," , options .scopes ), encoding ));
277- } catch (UnsupportedEncodingException e ) {
278- throw new IllegalArgumentException ("Bad encoding: " + encoding );
279- }
280- }
281-
282- if (options .tokenScopes != null ) {
283- TunnelAccessControl .validateScopes (options .tokenScopes , null );
284- try {
285- queryOptions .add (
286- "tokenScopes=" + URLEncoder .encode (String .join ("," , options .tokenScopes ), encoding ));
287- } catch (UnsupportedEncodingException e ) {
288- throw new IllegalArgumentException ("Bad encoding: " + encoding );
289- }
290- }
291- return String .join ("&" , queryOptions );
292- }
293-
294263 public CompletableFuture <Collection <Tunnel >> listTunnelsAsync (
295264 String clusterId ,
265+ String domain ,
296266 TunnelRequestOptions options ) {
297- // TODO - add domain parameter
298267 var query = StringUtils .isBlank (clusterId ) ? "global=true" : null ;
299268 var requestUri = this .buildUri (clusterId , tunnelsApiPath , options , query );
300269 final Type responseType = new TypeToken <Collection <Tunnel >>() {
@@ -309,17 +278,6 @@ public CompletableFuture<Collection<Tunnel>> listTunnelsAsync(
309278 responseType );
310279 }
311280
312- @ Override
313- public CompletableFuture <Collection <Tunnel >> searchTunnelsAsync (
314- String [] tags ,
315- boolean requireAllTags ,
316- String clusterId ,
317- String domain ,
318- TunnelRequestOptions options ) {
319- // TODO Auto-generated method stub
320- return null ;
321- }
322-
323281 @ Override
324282 public CompletableFuture <Tunnel > getTunnelAsync (Tunnel tunnel , TunnelRequestOptions options ) {
325283 var requestUri = buildUri (tunnel , options , null , null );
0 commit comments