public SBuildFeatureDescriptor getAwsConnectionFeatureFromBuild()

in aws-core-server/src/main/java/jetbrains/buildServer/clouds/amazon/connector/featureDevelopment/AwsConnectionsManagerImpl.java [69:106]


  public SBuildFeatureDescriptor getAwsConnectionFeatureFromBuild(@NotNull SBuild build) throws AwsBuildFeatureException {
    SBuildType buildType = build.getBuildType();
    if (buildType == null) {
      throw new AwsBuildFeatureException("There is no BuildType for the Build with id: " + build.getBuildId());
    }

    Collection<SBuildFeatureDescriptor> awsConnectionsToExpose = AwsConnToAgentBuildFeature.getAwsConnectionsToExpose(build);
    if (awsConnectionsToExpose.isEmpty()) {
      return null;
    }

    final boolean subProjectsFeatureEnabled = ParamUtil.toBooleanOrTrue(buildType, AwsCloudConnectorConstants.ALLOWED_IN_SUBPROJECTS_FEATURE_FLAG);
    if (subProjectsFeatureEnabled) {
      final List<SBuildFeatureDescriptor> filteredList = new ArrayList<SBuildFeatureDescriptor>();
      for (SBuildFeatureDescriptor feature : awsConnectionsToExpose) {
        final String connProjectId = getLinkedAwsConnection(feature.getParameters()).getProjectId();
        if (connProjectId.equals(buildType.getProjectId()) || ParamUtil.isAllowedInSubProjects(feature.getParameters())) {
          filteredList.add(feature);
        }
      }
      awsConnectionsToExpose = filteredList;
    }

    final boolean buildStepsFeatureEnabled = ParamUtil.toBooleanOrTrue(buildType, AwsCloudConnectorConstants.ALLOWED_IN_BUILDS_FEATURE_FLAG);

    if (!buildStepsFeatureEnabled) {
      return awsConnectionsToExpose.iterator().next();
    }

    for (SBuildFeatureDescriptor nextDescriptor : awsConnectionsToExpose) {
      final String isAllowedInBuildSteps = nextDescriptor.getParameters().get(AwsCloudConnectorConstants.ALLOWED_IN_BUILDS_PARAM);
      if (isAllowedInBuildSteps == null || Boolean.parseBoolean(isAllowedInBuildSteps)) {
        return nextDescriptor;
      }
    }

    throw new AwsBuildFeatureException("There are no AWS Connections that can be exposed");
  }