io.fabric8.kubernetes.client.utils.Utils.getSystemPropertyOrEnvVar()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中io.fabric8.kubernetes.client.utils.Utils.getSystemPropertyOrEnvVar()方法的一些代码示例,展示了Utils.getSystemPropertyOrEnvVar()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.getSystemPropertyOrEnvVar()方法的具体详情如下:
包路径:io.fabric8.kubernetes.client.utils.Utils
类名称:Utils
方法名:getSystemPropertyOrEnvVar

Utils.getSystemPropertyOrEnvVar介绍

暂无

代码示例

代码示例来源:origin: fabric8io/kubernetes-client

public static String getSystemPropertyOrEnvVar(String systemPropertyName) {
 return getSystemPropertyOrEnvVar(systemPropertyName, (String) null);
}

代码示例来源:origin: fabric8io/kubernetes-client

public static Boolean getSystemPropertyOrEnvVar(String systemPropertyName, Boolean defaultValue) {
 String result = getSystemPropertyOrEnvVar(systemPropertyName, defaultValue.toString());
 return Boolean.parseBoolean(result);
}

代码示例来源:origin: fabric8io/kubernetes-client

public static int getSystemPropertyOrEnvVar(String systemPropertyName, int defaultValue) {
 String result = getSystemPropertyOrEnvVar(systemPropertyName, new Integer(defaultValue).toString());
 return Integer.parseInt(result);
}

代码示例来源:origin: fabric8io/kubernetes-client

public static String getProperty(Map<String, Object> properties, String propertyName, String defaultValue) {
 String answer = (String) properties.get(propertyName);
 if (!isNullOrEmpty(answer)) {
  return answer;
 }
 return getSystemPropertyOrEnvVar(propertyName, defaultValue);
}

代码示例来源:origin: fabric8io/kubernetes-client

private static String getDefaultOapiVersion(Config config) {
 return Utils.getSystemPropertyOrEnvVar(KUBERNETES_OAPI_VERSION_SYSTEM_PROPERTY, config.getApiVersion());
}

代码示例来源:origin: fabric8io/kubernetes-client

public static String getSystemPropertyOrEnvVar(String systemPropertyName, String defaultValue) {
 return getSystemPropertyOrEnvVar(systemPropertyName, convertSystemPropertyNameToEnvVar(systemPropertyName), defaultValue);
}

代码示例来源:origin: fabric8io/kubernetes-client

private static boolean tryNamespaceFromPath(Config config) {
 LOGGER.debug("Trying to configure client namespace from Kubernetes service account namespace path...");
 if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRYNAMESPACE_PATH_SYSTEM_PROPERTY, true)) {
  String serviceAccountNamespace = Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_FILE, KUBERNETES_NAMESPACE_PATH);
  boolean serviceAccountNamespaceExists = Files.isRegularFile(new File(serviceAccountNamespace).toPath());
  if (serviceAccountNamespaceExists) {
   LOGGER.debug("Found service account namespace at: [" + serviceAccountNamespace + "].");
   try {
    String namespace = new String(Files.readAllBytes(new File(serviceAccountNamespace).toPath()));
    config.setNamespace(namespace.replace(System.lineSeparator(), ""));
    return true;
   } catch (IOException e) {
    LOGGER.error("Error reading service account namespace from: [" + serviceAccountNamespace + "].", e);
   }
  } else {
   LOGGER.debug("Did not find service account namespace at: [" + serviceAccountNamespace + "]. Ignoring.");
  }
 }
 return false;
}

代码示例来源:origin: fabric8io/kubernetes-client

private static boolean tryKubeConfig(Config config, String context) {
 LOGGER.debug("Trying to configure client from Kubernetes config...");
 if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY, true)) {
  String fileName = Utils.getSystemPropertyOrEnvVar(KUBERNETES_KUBECONFIG_FILE, new File(getHomeDir(), ".kube" + File.separator + "config").toString());
  // if system property/env var contains multiple files take the first one based on the environment
  // we are running in (eg. : for Linux, ; for Windows)
  String[] fileNames = fileName.split(File.pathSeparator);
  if (fileNames.length > 1) {
   LOGGER.debug("Found multiple Kubernetes config files [{}], using the first one: [{}].", fileNames, fileNames[0]);
   fileName = fileNames[0];
  }
  File kubeConfigFile = new File(fileName);
  boolean kubeConfigFileExists = Files.isRegularFile(kubeConfigFile.toPath());
  if (kubeConfigFileExists) {
   LOGGER.debug("Found for Kubernetes config at: ["+kubeConfigFile.getPath()+"].");
   String kubeconfigContents;
   try {
    kubeconfigContents = new String(Files.readAllBytes(kubeConfigFile.toPath()), StandardCharsets.UTF_8);
   } catch(IOException e) {
    LOGGER.error("Could not load Kubernetes config file from {}", kubeConfigFile.getPath(), e);
    return false;
   }
   Config.loadFromKubeconfig(config, context, kubeconfigContents, kubeConfigFile.getPath());
   return true;
  } else {
   LOGGER.debug("Did not find Kubernetes config at: ["+kubeConfigFile.getPath()+"]. Ignoring.");
  }
 }
 return false;
}

代码示例来源:origin: fabric8io/kubernetes-client

private static boolean tryServiceAccount(Config config) {
 LOGGER.debug("Trying to configure client from service account...");
 String masterHost = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SERVICE_HOST_PROPERTY, (String) null);
 String masterPort = Utils.getSystemPropertyOrEnvVar(KUBERNETES_SERVICE_PORT_PROPERTY, (String) null);
 if (masterHost != null && masterPort != null) {
  String hostPort = joinHostPort(masterHost, masterPort);
  config.setMasterUrl("https://" + hostPort);
 if (Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_TRYSERVICEACCOUNT_SYSTEM_PROPERTY, true)) {
  boolean serviceAccountCaCertExists = Files.isRegularFile(new File(KUBERNETES_SERVICE_ACCOUNT_CA_CRT_PATH).toPath());
  if (serviceAccountCaCertExists) {

代码示例来源:origin: fabric8io/kubernetes-client

@Test
public void existingSysPropShouldReturnValue() {
 System.setProperty("something", "value");
 assertEquals("value", Utils.getSystemPropertyOrEnvVar("something"));
 System.getProperties().remove("something");
}

代码示例来源:origin: fabric8io/kubernetes-client

public static void configFromSysPropsOrEnvVars(Config config) {
 config.setTrustCerts(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, config.isTrustCerts()));
 config.setDisableHostnameVerification(Utils.getSystemPropertyOrEnvVar(KUBERNETES_DISABLE_HOSTNAME_VERIFICATION_SYSTEM_PROPERTY, config.isDisableHostnameVerification()));
 config.setMasterUrl(Utils.getSystemPropertyOrEnvVar(KUBERNETES_MASTER_SYSTEM_PROPERTY, config.getMasterUrl()));
 config.setApiVersion(Utils.getSystemPropertyOrEnvVar(KUBERNETES_API_VERSION_SYSTEM_PROPERTY, config.getApiVersion()));
 config.setNamespace(Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, config.getNamespace()));
 config.setCaCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getCaCertFile()));
 config.setCaCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getCaCertData()));
 config.setClientCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getClientCertFile()));
 config.setClientCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getClientCertData()));
 config.setClientKeyFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY, config.getClientKeyFile()));
 config.setClientKeyData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY, config.getClientKeyData()));
 config.setClientKeyAlgo(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY, config.getClientKeyAlgo()));
 config.setClientKeyPassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY, new String(config.getClientKeyPassphrase())));
 config.setUserAgent(Utils.getSystemPropertyOrEnvVar(KUBERNETES_USER_AGENT, config.getUserAgent()));
 config.setTrustStorePassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY, config.getTrustStorePassphrase()));
 config.setTrustStoreFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_FILE_PROPERTY, config.getTrustStoreFile()));
 config.setKeyStorePassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY, config.getKeyStorePassphrase()));
 config.setKeyStoreFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_FILE_PROPERTY, config.getKeyStoreFile()));
 config.setOauthToken(Utils.getSystemPropertyOrEnvVar(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY, config.getOauthToken()));
 config.setUsername(Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY, config.getUsername()));
 config.setPassword(Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY, config.getPassword()));
 config.setImpersonateUsername(Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_USERNAME, config.getImpersonateUsername()));
 String configuredImpersonateGroups = Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_GROUP, config.getImpersonateGroup());
 if (configuredImpersonateGroups != null) {
  config.setImpersonateGroups(configuredImpersonateGroups.split(","));

代码示例来源:origin: fabric8io/kubernetes-client

@Test
public void existingEnvVarShouldReturnBooleanValueFromConvertedSysPropName() {
 assertEquals(true, Utils.getSystemPropertyOrEnvVar("env.var.exists.boolean", false));
}

代码示例来源:origin: fabric8io/kubernetes-client

@Test
public void missingSysPropAndEnvVarShouldReturnNull() {
 assertNull(Utils.getSystemPropertyOrEnvVar("doesn't exist"));
}

代码示例来源:origin: fabric8io/kubernetes-client

@Test
public void existingEnvVarShouldReturnValue() {
 assertEquals("value", Utils.getSystemPropertyOrEnvVar("ENV_VAR_EXISTS"));
}

代码示例来源:origin: fabric8io/kubernetes-client

@Test
public void existingEnvVarShouldReturnValueFromConvertedSysPropName() {
 assertEquals("value", Utils.getSystemPropertyOrEnvVar("env.var.exists"));
}

代码示例来源:origin: fabric8io/kubernetes-client

@Test
public void missingEnvVarShouldReturnDefaultValue() {
 assertEquals(true, Utils.getSystemPropertyOrEnvVar("DONT_EXIST", true));
}

代码示例来源:origin: fabric8io/kubernetes-client

private static String getDefaultOpenShiftUrl(Config config) {
 String openshiftUrl = Utils.getSystemPropertyOrEnvVar(OPENSHIFT_URL_SYTEM_PROPERTY);
 if (openshiftUrl != null) {
  // The OPENSHIFT_URL environment variable may be set to the root url (i.e. without the '/oapi/version' path) in some configurations
  if (isRootURL(openshiftUrl)) {
   openshiftUrl = URLUtils.join(openshiftUrl, "oapi", getDefaultOapiVersion(config));
  }
  return openshiftUrl;
 } else {
  return URLUtils.join(config.getMasterUrl(), "oapi", getDefaultOapiVersion(config));
 }
}

代码示例来源:origin: io.fabric8/fabric8-arquillian

private static Boolean getBooleanProperty(String name, Map<String, String> map, Boolean defaultValue) {
  if (map.containsKey(name)) {
    return Boolean.parseBoolean(map.get(name));
  } else {
    return Utils.getSystemPropertyOrEnvVar(name, defaultValue);
  }
}

代码示例来源:origin: io.fabric8/fabric8-arquillian

private static Long getLongProperty(String name, Map<String, String> map, Long defaultValue) {
  if (map.containsKey(name)) {
    return Long.parseLong(map.get(name));
  } else {
    return Long.parseLong(Utils.getSystemPropertyOrEnvVar(name, String.valueOf(defaultValue)));
  }
}

代码示例来源:origin: io.fabric8/fabric8-karaf-core

public SecretsResource() {
  this.useApi = Utils.getSystemPropertyOrEnvVar(FABRIC8_K8S_SECRET_API_ENABLED, false);
  this.paths = new ArrayList<>();
  String secretPaths = Utils.getSystemPropertyOrEnvVar(FABRIC8_K8S_SECRET_PATHS);
  if (Utils.isNotNullOrEmpty(secretPaths)) {
    for (String path : secretPaths.split(",")) {
      this.paths.add(Paths.get(path));
    }
  }
}

相关文章