Commit 69b6b4f9 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3292363 by Xiaohua Guan, yas: Manage Cloud Orchestrator deployment...

Issue #3292363 by Xiaohua Guan, yas: Manage Cloud Orchestrator deployment (Hide value of password field)
parent 33f2aec5
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -212,7 +212,10 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C
    $template_definitions = Yaml::decode(file_get_contents($template_definitions_path));
    $template_definition = $template_definitions[$deployment_template];
    $template_location = $template_definition['location'];
    if ($deployment_type === 'k8s') {

    // If the location is a relative path, the definition folder path
    // should be added.
    if (!file_exists($template_location)) {
      $template_location = dirname($template_definitions_path) . '/' . $template_location;
    }

@@ -243,6 +246,14 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C
      $cloud_launch_template->validate();
      $cloud_launch_template->save();

      $parameter_definitions = $this->loadParameterDefinitions(realpath(
        sprintf(
          '%s/templates/%s/parameters.yml',
          $this->extensionPathResolver->getPath('module', 'cloud_cluster'),
          $deployment_type
        )
      ));

      // Create cloud cluster site object.
      $timestamp = time();
      $entity = CloudClusterSite::create([
@@ -253,7 +264,7 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C
        'cloud_launch_template' => $cloud_launch_template->id(),
        'parameters' => array_map(fn($key, $value) => [
          'item_key' => $key,
          'item_value' => $value,
          'item_value' => $parameter_definitions[$key]['type'] === 'password' ? '******' : $value,
        ], array_keys($parameters ?: []), array_values($parameters ?: [])),
        'created' => $timestamp,
        'changed' => $timestamp,
@@ -359,4 +370,25 @@ class CloudClusterCloudLaunchTemplatePlugin extends CloudPluginBase implements C
    return $field;
  }

  /**
   * Load parameter definitions.
   *
   * @param string $parameter_definitions_path
   *   The path of parameter definition file.
   *
   * @return array
   *   Parameter definitions.
   */
  private function loadParameterDefinitions($parameter_definitions_path): array {
    $definitions = [];
    $yml = Yaml::decode(file_get_contents($parameter_definitions_path));
    foreach ($yml['groups'] ?: [] as $group) {
      foreach ($group['parameters'] ?: [] as $parameter) {
        $definitions[$parameter['name']] = $parameter;
      }
    }

    return $definitions;
  }

}