コード例 #1
0
 /**
  * schedule indexing for now
  *
  * @param artifactoryResponse - encapsulate data require for response
  */
 private void runIndexNow(RestResponse artifactoryResponse) {
   BasicStatusHolder status = new BasicStatusHolder();
   mavenIndexer.scheduleImmediateIndexing(status);
   if (status.isError()) {
     artifactoryResponse.error(status.getStatusMsg());
   } else {
     artifactoryResponse.info("Indexer was successfully scheduled to run in the background.");
   }
 }
コード例 #2
0
 /**
  * @param artifactoryResponse - encapsulate data related to response
  * @param name - build name
  * @param buildNumber - build number
  * @param buildStarted - build date
  */
 private void fetchBuildIssues(
     RestResponse artifactoryResponse, String name, String buildNumber, String buildStarted) {
   Build build = getBuild(name, buildNumber, buildStarted, artifactoryResponse);
   Issues issues = build.getIssues();
   if (issues == null) {
     artifactoryResponse.iModelList(new ArrayList<>());
     return;
   }
   Set<Issue> affectedIssues = issues.getAffectedIssues();
   List<IssueModel> issuesList = new ArrayList<>();
   affectedIssues.forEach(issue -> issuesList.add(new IssueModel(issue)));
   artifactoryResponse.iModelList(issuesList);
 }
コード例 #3
0
  /**
   * @param restResponse
   * @param servletContextUrl
   * @return
   */
  private String getGradleProperties(RestResponse restResponse, String servletContextUrl) {
    AddonsManager addonsManager = ContextHelper.get().beanForType(AddonsManager.class);
    FilteredResourcesAddon filteredResourcesWebAddon =
        addonsManager.addonByType(FilteredResourcesAddon.class);

    java.util.Properties credentialProperties = new java.util.Properties();
    credentialProperties.setProperty(
        "auth.username", filteredResourcesWebAddon.getGeneratedSettingsUsernameTemplate());

    credentialProperties.setProperty(
        "auth.password",
        filteredResourcesWebAddon.getGeneratedSettingsUserCredentialsTemplate(false));

    credentialProperties.setProperty("auth.contextUrl", servletContextUrl);

    String content =
        replaceValuesAndGetTemplateValue(
            "/gradle.properties.template", credentialProperties, restResponse);
    try {
      String filtered =
          filteredResourcesWebAddon.filterResource(
              null,
              (org.artifactory.md.Properties) InfoFactoryHolder.get().createProperties(),
              new StringReader(content));
      return filtered;
    } catch (Exception e) {
      log.error("Unable to filter gradle build properties file: " + e.getMessage());
      restResponse.error(e.getMessage());
    }
    return content;
  }
コード例 #4
0
 @Override
 public void execute(ArtifactoryRestRequest request, RestResponse response) {
   PropertiesArtifactInfo propertiesTab = (PropertiesArtifactInfo) request.getImodel();
   try {
     RepoPath repoPath = RequestUtils.getPathFromRequest(request);
     propsService.editProperty(
         repoPath,
         propertiesTab.getParent(),
         propertiesTab.getProperty(),
         propertiesTab.getSelectedValues());
     response.info(
         "Successfully updated property '" + propertiesTab.getProperty().getName() + "'");
   } catch (Exception e) {
     log.error("Failed to create property '" + propertiesTab.getProperty().getName() + "'");
     response.info("Failed to update property '" + propertiesTab.getProperty().getName() + "'");
   }
 }
コード例 #5
0
 /**
  * download gradle build props
  *
  * @param response - encapsulate data related to response
  * @param servletContextUrl - servlet context
  */
 private void downLoadGradleProps(RestResponse response, String servletContextUrl) {
   String gradleProperties = getGradleProperties(response, servletContextUrl);
   ScriptDownload scriptDownload = new ScriptDownload();
   scriptDownload.setFileContent(gradleProperties);
   ((StreamRestResponse) response).setDownload(true);
   ((StreamRestResponse) response).setDownloadFile("gradle.properties");
   response.iModel(scriptDownload);
 }
コード例 #6
0
 /**
  * download Gradle build File
  *
  * @param response - encapsulate data related to response
  * @param gradleSnippet - gradle snippet file
  */
 private void downloadGradleBuildFile(RestResponse response, String gradleSnippet) {
   // download build.gradle file
   ScriptDownload scriptDownload = new ScriptDownload();
   scriptDownload.setFileContent(gradleSnippet);
   ((StreamRestResponse) response).setDownload(true);
   ((StreamRestResponse) response).setDownloadFile("build.gradle");
   response.iModel(scriptDownload);
 }
コード例 #7
0
 /**
  * @param templateResourcePath
  * @param templateProperties
  * @return
  */
 private String replaceValuesAndGetTemplateValue(
     String templateResourcePath, Properties templateProperties, RestResponse response) {
   InputStream gradleInitTemplateStream = null;
   try {
     gradleInitTemplateStream = getClass().getResourceAsStream(templateResourcePath);
     String gradleTemplate = IOUtils.toString(gradleInitTemplateStream);
     PropertyPlaceholderHelper propertyPlaceholderHelper =
         new PropertyPlaceholderHelper("${", "}");
     return propertyPlaceholderHelper.replacePlaceholders(gradleTemplate, templateProperties);
   } catch (IOException e) {
     String errorMessage = "An error occurred while preparing the Gradle Init Script template: ";
     response.error(errorMessage + e.getMessage());
     log.error(errorMessage, e);
   } finally {
     IOUtils.closeQuietly(gradleInitTemplateStream);
   }
   return "";
 }
コード例 #8
0
  @Override
  public void execute(ArtifactoryRestRequest request, RestResponse response) {
    List<String> allUsers =
        userGroupService
            .getAllUsers(false)
            .stream()
            .map(UserInfo::getUsername)
            .collect(Collectors.toList());

    List<String> allGroups =
        userGroupService
            .getAllGroups()
            .stream()
            .map(GroupInfo::getGroupName)
            .collect(Collectors.toList());

    AllUsersAndGroupsModel allUsersAndGroups = new AllUsersAndGroupsModel();
    allUsersAndGroups.setAllUsers(allUsers);
    allUsersAndGroups.setAllGroups(allGroups);
    response.iModel(allUsersAndGroups);
  }
コード例 #9
0
 @Override
 public void execute(ArtifactoryRestRequest request, RestResponse response) {
   GradleSettingModel gradleSettingModel = (GradleSettingModel) request.getImodel();
   boolean downloadScript = Boolean.valueOf(request.getQueryParamByKey("downloadScript"));
   boolean downloadGradleProps = Boolean.valueOf(request.getQueryParamByKey("gradleProps"));
   String servletContextUrl = HttpUtils.getServletContextUrl(request.getServletRequest());
   // generate maven settings
   String gradleSnippet = generateSettings(servletContextUrl, gradleSettingModel, response);
   if (downloadGradleProps) {
     downLoadGradleProps(response, servletContextUrl);
     return;
   }
   if (downloadScript) {
     downloadGradleBuildFile(response, gradleSnippet);
     return;
   } else {
     // update maven setting model
     GradleSettingModel mavenSnippetModel = new GradleSettingModel(gradleSnippet);
     mavenSnippetModel.clearProps();
     response.iModel(mavenSnippetModel);
   }
 }
コード例 #10
0
 /**
  * update response with created status and feedback
  *
  * @param artifactoryResponse - encapsulate all data require for response
  * @param proxyDescriptor - proxy descriptor
  */
 private void updateResponse(RestResponse artifactoryResponse, ProxyDescriptor proxyDescriptor) {
   artifactoryResponse.info("Successfully created proxy '" + proxyDescriptor.getKey() + "'");
   artifactoryResponse.responseCode(HttpServletResponse.SC_CREATED);
 }
コード例 #11
0
 /**
  * update error feedback
  *
  * @param artifactoryResponse - encapsulate data require for response
  * @param statusHolder - status holder
  * @param e - exception
  */
 private void updateErrorFeedBack(
     RestResponse artifactoryResponse, BasicStatusHolder statusHolder, Exception e) {
   log.error("Could not run indexer.", e);
   statusHolder.error(e.getMessage(), log);
   artifactoryResponse.error("Indexer did not run: " + e.getMessage());
 }
コード例 #12
0
 /**
  * return not found error
  *
  * @param errorMessage
  * @param response
  */
 private void throwInternalError(String errorMessage, RestResponse response) {
   response.error(errorMessage);
   response.responseCode(HttpServletResponse.SC_NOT_FOUND);
 }
コード例 #13
0
 /**
  * Throws a 404 AbortWithHttpErrorCodeException with the given message
  *
  * @param errorMessage Message to display in the error
  */
 private void throwNotFoundError(RestResponse response, String errorMessage) {
   log.error(errorMessage);
   response.error(errorMessage);
 }