public PipelineTemplateConfig templateByName(CaseInsensitiveString foo) { for (PipelineTemplateConfig templateConfig : this) { if (templateConfig.name().equals(foo)) { return templateConfig; } } return null; }
@Override public PipelineTemplateConfig findTemplate(CaseInsensitiveString templateName) { for (PipelineTemplateConfig config : templatesConfig) { if (templateName.equals(config.name())) { return config; } } return null; }
@Override public boolean isValid(CruiseConfig preprocessedConfig) { List<CaseInsensitiveString> pipelinesAssociatedWithTemplate = preprocessedConfig.pipelinesAssociatedWithTemplate(templateConfig.name()); if (!pipelinesAssociatedWithTemplate.isEmpty()) { result.unprocessableEntity(cannotDeleteResourceBecauseOfDependentPipelines("template", templateConfig.name(), CaseInsensitiveString.toStringList(pipelinesAssociatedWithTemplate))); throw new GoConfigInvalidException(preprocessedConfig, String.format("The template '%s' is being referenced by pipeline(s): %s", templateConfig.name(), pipelinesAssociatedWithTemplate)); } return true; }
public void validateNameUniquness(Map<String, PipelineTemplateConfig> templateMap) { String currentName = name.toLower(); PipelineTemplateConfig templateWithSameName = templateMap.get(currentName); if (templateWithSameName == null) { templateMap.put(currentName, this); } else { templateWithSameName.addError(NAME, String.format("Template name '%s' is not unique", templateWithSameName.name())); this.addError(NAME, String.format("Template name '%s' is not unique", name)); } }
public void encryptSecureProperties(CruiseConfig preprocessedCruiseConfig, PipelineTemplateConfig pipelineTemplateConfig) { if (isNotBlank(artifactId)) { PluggableArtifactConfig externalArtifact = getSpecifiedExternalArtifact(preprocessedCruiseConfig, pipelineTemplateConfig, this, false, pipelineTemplateConfig.name()); encryptSecurePluginConfiguration(preprocessedCruiseConfig, externalArtifact); } }
public void validateFetchExternalArtifactTask(FetchPluggableArtifactTask preprocessedFetchPluggableArtifactTask, PipelineTemplateConfig pipelineTemplateConfig, CruiseConfig preprocessedConfig) { PluggableArtifactConfig specifiedExternalArtifact = preprocessedFetchPluggableArtifactTask.getSpecifiedExternalArtifact(preprocessedConfig, pipelineTemplateConfig, preprocessedFetchPluggableArtifactTask, false, pipelineTemplateConfig.name()); validateFetchTasks(preprocessedFetchPluggableArtifactTask, preprocessedConfig, specifiedExternalArtifact); }
private void haltIfEntityBySameNameInRequestExists(PipelineTemplateConfig templateConfig, HttpLocalizedOperationResult result) { if (templateConfigService.loadForView(templateConfig.name().toString(), result) == null) { return; } templateConfig.addError("name", LocalizedMessage.resourceAlreadyExists("template", templateConfig.name().toString())); throw haltBecauseEntityAlreadyExists(jsonWriter(templateConfig), "template", templateConfig.name()); } }
private void moveStage(StageConfig moveMeStage, int moveBy) { int current = this.indexOf(moveMeStage); if (current == -1) { throw new RuntimeException(String.format("Cannot find the stage '%s' in pipeline '%s'", moveMeStage.name(), name())); } this.remove(moveMeStage); this.add(current + moveBy, moveMeStage); }
public void call(PipelineTemplateConfig pipelineTemplateConfig) { List<CaseInsensitiveString> pipelines = goConfigService.currentCruiseConfig().pipelinesAssociatedWithTemplate(pipelineTemplateConfig.name()); for (CaseInsensitiveString pipeline : pipelines) { cacheUpdateService.updateCacheForPipeline(pipeline); } } }
private boolean isRequestFresh(CruiseConfig cruiseConfig) { PipelineTemplateConfig pipelineTemplateConfig = findAddedTemplate(cruiseConfig); boolean freshRequest = entityHashingService.md5ForEntity(pipelineTemplateConfig).equals(md5); if (!freshRequest) { result.stale(staleResourceConfig("Template", templateConfig.name())); } return freshRequest; } }
@Override public void update(CruiseConfig modifiedConfig) { preprocessedTemplateConfig = findAddedTemplate(modifiedConfig); TemplatesConfig templatesConfig = modifiedConfig.getTemplates(); templatesConfig.removeTemplateNamed(preprocessedTemplateConfig.name()); modifiedConfig.setTemplates(templatesConfig); }
private boolean isUserAuthorized() { if (!securityService.isAuthorizedToEditTemplate(templateConfig.name(), currentUser)) { result.forbidden(forbiddenToEdit(), forbidden()); return false; } return true; }
private boolean isUserAuthorized() { if (!securityService.isAuthorizedToEditTemplate(templateConfig.name(), currentUser)) { result.forbidden(forbiddenToEdit(), forbidden()); return false; } return true; }
public void validateTask(ValidationContext validationContext) { if (validationContext.isWithinPipelines()) { validateWorkingDirectory(validationContext, "pipeline", validationContext.getPipeline().name()); } else { validateWorkingDirectory(validationContext, "template", validationContext.getTemplate().name()); } }
public void deleteTemplateConfig(final Username currentUser, final PipelineTemplateConfig templateConfig, final LocalizedOperationResult result) { DeleteTemplateConfigCommand command = new DeleteTemplateConfigCommand(templateConfig, result, securityService, currentUser, externalArtifactsService); update(currentUser, result, command, templateConfig); if (result.isSuccessful()) { result.setMessage(LocalizedMessage.resourceDeleteSuccessful("template", templateConfig.name().toString())); } }
@Override public void update(CruiseConfig modifiedConfig) { PipelineTemplateConfig existingTemplateConfig = findAddedTemplate(modifiedConfig); templateConfig.setAuthorization(existingTemplateConfig.getAuthorization()); TemplatesConfig templatesConfig = modifiedConfig.getTemplates(); templatesConfig.removeTemplateNamed(existingTemplateConfig.name()); templatesConfig.add(templateConfig); modifiedConfig.setTemplates(templatesConfig); }
private void validateFilePath(ValidationContext validationContext, String path, String propertyName) { if (path == null) { return; } if (!FilenameUtil.isNormalizedPathOutsideWorkingDir(path)) { String parentType = validationContext.isWithinPipelines() ? "pipeline" : "template"; CaseInsensitiveString parentName = validationContext.isWithinPipelines() ? validationContext.getPipeline().name() : validationContext.getTemplate().name(); String message = String.format("Task of job '%s' in stage '%s' of %s '%s' has %s path '%s' which is outside the working directory.", validationContext.getJob().name(), validationContext.getStage().name(), parentType, parentName, propertyName, path); addError(propertyName, message); } }
private void validateDependencies(CruiseConfig preprocessedConfig) { List<CaseInsensitiveString> pipelineNames = preprocessedConfig.pipelinesAssociatedWithTemplate(this.name()); ParamsConfig paramsConfig = this.referredParams(); for (CaseInsensitiveString pipelineName : pipelineNames) { PipelineConfig pipelineConfig = preprocessedConfig.getPipelineConfigByName(pipelineName); PipelineConfigs pipelineGroup = preprocessedConfig.findGroupOfPipeline(pipelineConfig); PipelineConfigSaveValidationContext contextForStages = PipelineConfigSaveValidationContext.forChain(false, pipelineGroup.getGroup(), preprocessedConfig, pipelineConfig); validateParams(pipelineConfig, paramsConfig); validatePartsOfPipelineConfig(pipelineConfig, contextForStages); validateDependenciesOfDownstreams(pipelineConfig, contextForStages); } }
@Test public void shouldErrorOutIfTemplateNameIsAlreadyPresent() { PipelineTemplateConfig template = template("template1"); TemplatesConfig templates = new TemplatesConfig(template); PipelineTemplateConfig duplicateTemplate = template("template1"); templates.add(duplicateTemplate); templates.validate(null); assertThat(template.errors().isEmpty(), is(false)); assertThat(duplicateTemplate.errors().isEmpty(), is(false)); assertThat(template.errors().on(PipelineTemplateConfig.NAME), is(String.format("Template name '%s' is not unique", template.name()))); assertThat(duplicateTemplate.errors().on(PipelineTemplateConfig.NAME), is(String.format("Template name '%s' is not unique", template.name()))); }
@Test public void shouldSetPrimitiveAttributes() { PipelineTemplateConfig pipelineTemplateConfig = new PipelineTemplateConfig(); Map map = m(PipelineTemplateConfig.NAME, "templateName"); pipelineTemplateConfig.setConfigAttributes(map); assertThat(pipelineTemplateConfig.name(), is(new CaseInsensitiveString("templateName"))); }