File tree Expand file tree Collapse file tree 4 files changed +18
-9
lines changed
examples/src/main/java/io/kubernetes/client/examples
kubernetes/src/main/java/io/kubernetes/client
util/src/main/java/io/kubernetes/client/util Expand file tree Collapse file tree 4 files changed +18
-9
lines changed Original file line number Diff line number Diff line change 2828 * Requires kubectl proxy running
2929 *
3030 * Easiest way to run this:
31- * mvn exec:java -Dex .mainClass="io.kubernetes.client.examples.Example"
31+ * mvn exec:java -Dexec .mainClass="io.kubernetes.client.examples.Example"
3232 *
3333 * From inside $REPO_DIR/kubernetes
3434 */
3535public class Example {
3636 public static void main (String [] args ) throws IOException , ApiException {
37- ApiClient client ;
38- if (args .length == 0 ) {
39- client = new ApiClient ();
40- client .setBasePath ("http://localhost:8001" );
41- } else {
42- client = Config .fromConfig (args [0 ]);
43- }
37+ ApiClient client = Config .defaultClient ();
4438 Configuration .setDefaultApiClient (client );
4539
4640 CoreV1Api api = new CoreV1Api ();
Original file line number Diff line number Diff line change @@ -162,6 +162,8 @@ public ApiClient() {
162162 // Setup authentications (key: authentication name, value: authentication).
163163 authentications = new HashMap <String , Authentication >();
164164 authentications .put ("BearerToken" , new ApiKeyAuth ("header" , "authorization" ));
165+ authentications .put ("BasicAuth" , new HttpBasicAuth ());
166+
165167 // Prevent the authentications from being modified.
166168 authentications = Collections .unmodifiableMap (authentications );
167169 }
Original file line number Diff line number Diff line change @@ -128,7 +128,9 @@ public static ApiClient fromConfig(Reader input) {
128128
129129 String token = config .getAccessToken ();
130130 if (token != null ) {
131- client .setAccessToken (token );
131+ // This is kind of a hack, except not, because I don't think we actually
132+ // want to use oauth here.
133+ client .setApiKey ("Bearer " + token );
132134 }
133135
134136 String username = config .getUsername ();
Original file line number Diff line number Diff line change 1717import java .io .FileReader ;
1818import java .io .Reader ;
1919import java .util .ArrayList ;
20+ import java .util .Date ;
2021import java .util .Map ;
2122
2223import org .yaml .snakeyaml .Yaml ;
@@ -154,9 +155,19 @@ public String getAccessToken() {
154155 Map <String , Object > authProviderMap = (Map <String , Object >) authProvider ;
155156 Map <String , Object > authConfig = (Map <String , Object >) authProviderMap .get ("config" );
156157 if (authConfig != null ) {
158+ Date expiry = (Date ) authConfig .get ("expiry" );
159+ if (expiry != null ) {
160+ if (expiry .compareTo (new Date ()) <= 0 ) {
161+ // TODO: Generate new token here...
162+ throw new IllegalStateException ("Token is expired!" );
163+ }
164+ }
157165 return (String ) authConfig .get ("access-token" );
158166 }
159167 }
168+ if (currentUser .containsKey ("token" )) {
169+ return (String ) currentUser .get ("token" );
170+ }
160171 return null ;
161172 }
162173
You can’t perform that action at this time.
0 commit comments