Java Code Examples for io.fabric8.kubernetes.client.ConfigBuilder#withOauthToken()
The following examples show how to use
io.fabric8.kubernetes.client.ConfigBuilder#withOauthToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IstioExecutor.java From istio-apim with Apache License 2.0 | 6 votes |
/** * Build the config for the client */ private Config buildConfig() throws APIManagementException { System.setProperty(TRY_KUBE_CONFIG, "false"); System.setProperty(TRY_SERVICE_ACCOUNT, "true"); ConfigBuilder configBuilder; configBuilder = new ConfigBuilder().withMasterUrl(kubernetesAPIServerUrl); if (!StringUtils.isEmpty(saTokenFileName)) { String token; String tokenFile = saTokenFilePath + "/" + saTokenFileName; try { token = FileUtil.readFileToString(tokenFile); } catch (IOException e) { throw new APIManagementException("Error while reading the SA Token FIle " + tokenFile); } configBuilder.withOauthToken(token); } return configBuilder.build(); }
Example 2
Source File: K8sNodeUtil.java From onos with Apache License 2.0 | 6 votes |
/** * Obtains workable kubernetes client. * * @param config kubernetes API config * @return kubernetes client */ public static KubernetesClient k8sClient(K8sApiConfig config) { if (config == null) { log.warn("Kubernetes API server config is empty."); return null; } String endpoint = endpoint(config); ConfigBuilder configBuilder = new ConfigBuilder().withMasterUrl(endpoint); if (config.scheme() == K8sApiConfig.Scheme.HTTPS) { configBuilder.withTrustCerts(true) .withCaCertData(config.caCertData()) .withClientCertData(config.clientCertData()) .withClientKeyData(config.clientKeyData()); if (StringUtils.isNotEmpty(config.token())) { configBuilder.withOauthToken(config.token()); } } return new DefaultKubernetesClient(configBuilder.build()); }
Example 3
Source File: TokenAuthStrategy.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public ConfigBuilder apply(@NotNull ConfigBuilder clientConfig, @NotNull KubeApiConnection connection) { String token = connection.getCustomParameter(SECURE_PREFIX + AUTH_TOKEN); if(StringUtil.isEmpty(token)) { throw new KubeCloudException("Auth token is empty for connection to " + connection.getApiServerUrl()); } return clientConfig.withOauthToken(token); }
Example 4
Source File: DefaultServiceAccountAuthStrategy.java From teamcity-kubernetes-plugin with Apache License 2.0 | 5 votes |
@NotNull @Override public ConfigBuilder apply(@NotNull ConfigBuilder clientConfig, @NotNull KubeApiConnection connection) { String defaultServiceAccountAuthToken = getDefaultServiceAccountAuthToken(); if(StringUtil.isEmpty(defaultServiceAccountAuthToken)) throw new KubeCloudException("Can't locate default Kubernetes service account token."); return clientConfig.withOauthToken(defaultServiceAccountAuthToken); }
Example 5
Source File: ClientFactory.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static KnativeClient newClient(String[] args) { ConfigBuilder config = new ConfigBuilder(); for (int i = 0; i < args.length - 1; i++) { String key = args[i]; String value = args[i + 1]; if (key.equals("--api-server")) { config = config.withMasterUrl(value); } if (key.equals("--token")) { config = config.withOauthToken(value); } if (key.equals("--username")) { config = config.withUsername(value); } if (key.equals("--password")) { config = config.withPassword(value); } if (key.equals("--namespace")) { config = config.withNamespace(value); } } return new DefaultKnativeClient(config.build()); }
Example 6
Source File: ClientFactory.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static TektonClient newClient(String[] args) { ConfigBuilder config = new ConfigBuilder(); for (int i = 0; i < args.length - 1; i++) { String key = args[i]; String value = args[i + 1]; if (key.equals("--api-server")) { config = config.withMasterUrl(value); } if (key.equals("--token")) { config = config.withOauthToken(value); } if (key.equals("--username")) { config = config.withUsername(value); } if (key.equals("--password")) { config = config.withPassword(value); } if (key.equals("--namespace")) { config = config.withNamespace(value); } } return new DefaultTektonClient(config.build()); }
Example 7
Source File: ClientFactory.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static ServiceCatalogClient newClient(String[] args) { ConfigBuilder config = new ConfigBuilder(); for (int i = 0; i < args.length - 1; i++) { String key = args[i]; String value = args[i + 1]; if (key.equals("--api-server")) { config = config.withMasterUrl(value); } if (key.equals("--token")) { config = config.withOauthToken(value); } if (key.equals("--username")) { config = config.withUsername(value); } if (key.equals("--password")) { config = config.withPassword(value); } if (key.equals("--namespace")) { config = config.withNamespace(value); } } return new DefaultServiceCatalogClient(config.build()); }
Example 8
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Activate public void activate(Map<String, Object> properties) { final ConfigBuilder builder = new ConfigBuilder(); if (properties.containsKey(KUBERNETES_MASTER_SYSTEM_PROPERTY)) { builder.withMasterUrl((String) properties.get(KUBERNETES_MASTER_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_API_VERSION_SYSTEM_PROPERTY)) { builder.withApiVersion((String) properties.get(KUBERNETES_API_VERSION_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY)) { builder.withNamespace((String) properties.get(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY)) { builder.withCaCertFile((String) properties.get(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY)) { builder.withCaCertData((String) properties.get(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY)) { builder.withClientCertFile((String) properties.get(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY)) { builder.withClientCertData((String) properties.get(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY)) { builder.withClientKeyFile((String) properties.get(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY)) { builder.withClientKeyData((String) properties.get(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY)) { builder.withClientKeyAlgo((String) properties.get(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY)) { builder.withClientKeyPassphrase((String) properties.get(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY)) { builder.withUsername((String) properties.get(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY)) { builder.withPassword((String) properties.get(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY)) { builder.withOauthToken((String) properties.get(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY)); } if (properties.containsKey(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY)) { builder.withWatchReconnectInterval(Integer.parseInt((String) properties.get(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY)) { builder.withWatchReconnectLimit(Integer.parseInt((String) properties.get(KUBERNETES_WATCH_RECONNECT_LIMIT_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY)) { builder.withRequestTimeout(Integer.parseInt((String) properties.get(KUBERNETES_REQUEST_TIMEOUT_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_HTTP_PROXY)) { builder.withHttpProxy((String) properties.get(KUBERNETES_HTTP_PROXY)); } if (properties.containsKey(KUBERNETES_HTTPS_PROXY)) { builder.withHttpsProxy((String) properties.get(KUBERNETES_HTTPS_PROXY)); } if (properties.containsKey(KUBERNETES_NO_PROXY)) { String noProxyProperty = (String) properties.get(KUBERNETES_NO_PROXY); builder.withNoProxy(noProxyProperty.split(",")); } if (properties.containsKey(KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY)) { builder.withWebsocketTimeout(Long.parseLong((String) properties.get(KUBERNETES_WEBSOCKET_TIMEOUT_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY)) { builder.withWebsocketPingInterval(Long.parseLong((String) properties.get(KUBERNETES_WEBSOCKET_PING_INTERVAL_SYSTEM_PROPERTY))); } if (properties.containsKey(KUBERNETES_TRUSTSTORE_FILE_PROPERTY)) { builder.withTrustStoreFile((String) properties.get(KUBERNETES_TRUSTSTORE_FILE_PROPERTY)); } if (properties.containsKey(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY)) { builder.withTrustStorePassphrase((String) properties.get(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY)); } if (properties.containsKey(KUBERNETES_KEYSTORE_FILE_PROPERTY)) { builder.withKeyStoreFile((String) properties.get(KUBERNETES_KEYSTORE_FILE_PROPERTY)); } if (properties.containsKey(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY)) { builder.withKeyStorePassphrase((String) properties.get(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY)); } if (provider != null ) { builder.withOauthTokenProvider(provider); } delegate = new DefaultKubernetesClient(builder.build()); }