@@ -57,18 +57,14 @@ public void setApiClient(ApiClient apiClient) {
5757 this .apiClient = apiClient ;
5858 }
5959
60- private String makePath (
61- String namespace , String name , String container , boolean stdin , boolean tty ) {
62- return "/api/v1/namespaces/"
63- + namespace
64- + "/pods/"
65- + name
66- + "/attach?"
67- + "stdin="
68- + stdin
69- + "&tty="
70- + tty
71- + (container != null ? "&container=" + container : "" );
60+ /**
61+ * Setup a Builder for the given namespace and name
62+ *
63+ * @param namespace The namespace of the Pod
64+ * @param name The name of the Pod
65+ */
66+ public ConnectionBuilder newConnectionBuilder (String namespace , String name ) {
67+ return new ConnectionBuilder (namespace , name );
7268 }
7369
7470 /**
@@ -136,13 +132,107 @@ public AttachResult attach(V1Pod pod, String container, boolean stdin, boolean t
136132 public AttachResult attach (
137133 String namespace , String name , String container , boolean stdin , boolean tty )
138134 throws ApiException , IOException {
139- String path = makePath (namespace , name , container , stdin , tty );
135+ return newConnectionBuilder (namespace , name )
136+ .setContainer (container )
137+ .setStdin (stdin )
138+ .setTty (tty )
139+ .connect ();
140+ }
141+
142+ public final class ConnectionBuilder {
143+ private final String namespace ;
144+ private final String name ;
145+
146+ private String container ;
147+
148+ private boolean stdin ;
149+ private boolean stdout ;
150+ private boolean stderr ;
151+ private boolean tty ;
152+
153+ private ConnectionBuilder (String namespace , String name ) {
154+ this .namespace = namespace ;
155+ this .name = name ;
156+ this .stdin = true ;
157+ }
158+
159+ public String getName () {
160+ return name ;
161+ }
162+
163+ public String getNamespace () {
164+ return namespace ;
165+ }
166+
167+ public String getContainer () {
168+ return container ;
169+ }
170+
171+ public ConnectionBuilder setContainer (String container ) {
172+ this .container = container ;
173+ return this ;
174+ }
140175
141- WebSocketStreamHandler handler = new WebSocketStreamHandler ();
142- AttachResult result = new AttachResult (handler );
143- WebSockets .stream (path , "GET" , apiClient , handler );
176+ public boolean getStdin () {
177+ return stdin ;
178+ }
179+
180+ public ConnectionBuilder setStdin (boolean stdin ) {
181+ this .stdin = stdin ;
182+ return this ;
183+ }
184+
185+ public boolean getStdout () {
186+ return stdout ;
187+ }
144188
145- return result ;
189+ public ConnectionBuilder setStdout (boolean stdout ) {
190+ this .stdout = stdout ;
191+ return this ;
192+ }
193+
194+ public boolean getStderr () {
195+ return stderr ;
196+ }
197+
198+ public ConnectionBuilder setStderr (boolean stderr ) {
199+ this .stderr = stderr ;
200+ return this ;
201+ }
202+
203+ public boolean getTty () {
204+ return tty ;
205+ }
206+
207+ public ConnectionBuilder setTty (boolean tty ) {
208+ this .tty = tty ;
209+ return this ;
210+ }
211+
212+ private String makePath () {
213+ return "/api/v1/namespaces/"
214+ + namespace
215+ + "/pods/"
216+ + name
217+ + "/attach?"
218+ + "stdin="
219+ + stdin
220+ + "&stdout="
221+ + stdout
222+ + "&stderr="
223+ + stderr
224+ + "&tty="
225+ + tty
226+ + (container != null ? "&container=" + container : "" );
227+ }
228+
229+ public AttachResult connect () throws ApiException , IOException {
230+ WebSocketStreamHandler handler = new WebSocketStreamHandler ();
231+ AttachResult result = new AttachResult (handler );
232+ WebSockets .stream (makePath (), "GET" , apiClient , handler );
233+
234+ return result ;
235+ }
146236 }
147237
148238 /**
0 commit comments