public void validateExternalArtifactConfig(PluggableArtifactConfig preprocessedPluggableArtifactConfig, ArtifactStore artifactStore, boolean addPluginIdError) { if (preprocessedPluggableArtifactConfig.hasValidPluginAndStore(artifactStore)) { String pluginId = artifactStore.getPluginId(); try { ValidationResult validationResult = artifactExtension.validatePluggableArtifactConfig(pluginId, preprocessedPluggableArtifactConfig.getConfiguration().getConfigurationAsMap(true)); mapErrorsToConfiguration(validationResult, preprocessedPluggableArtifactConfig.getConfiguration(), preprocessedPluggableArtifactConfig); } catch (PluginNotFoundException e) { preprocessedPluggableArtifactConfig.addError("pluginId", String.format("Plugin with id `%s` is not found.", pluginId)); } } else { if (addPluginIdError) { preprocessedPluggableArtifactConfig.addError("pluginId", "Could not determine the plugin to perform the plugin validations. Possible reasons: artifact store does not exist or plugin is not installed."); } } }
@Test public void hasValidPluginAndStore_shouldReturnTrueIfPluginAndStoreExist() { PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("dist", "s3"); assertTrue(pluggableArtifactConfig.hasValidPluginAndStore(new ArtifactStore("s3", "cd.go.s3"))); } }
private void validateFetchTasks(FetchPluggableArtifactTask preprocessedFetchPluggableArtifactTask, CruiseConfig preprocessedConfig, PluggableArtifactConfig specifiedExternalArtifact) { if (specifiedExternalArtifact != null) { ArtifactStore artifactStore = preprocessedConfig.getArtifactStores().find(specifiedExternalArtifact.getStoreId()); if (specifiedExternalArtifact.hasValidPluginAndStore(artifactStore)) { try { ValidationResult validationResult = artifactExtension.validateFetchArtifactConfig(artifactStore.getPluginId(), preprocessedFetchPluggableArtifactTask.getConfiguration().getConfigurationAsMap(true)); mapErrorsToConfiguration(validationResult, preprocessedFetchPluggableArtifactTask.getConfiguration(), preprocessedFetchPluggableArtifactTask); } catch (PluginNotFoundException e) { preprocessedFetchPluggableArtifactTask.addError("pluginId", String.format("Plugin with id `%s` is not found.", artifactStore.getPluginId())); } } else { preprocessedFetchPluggableArtifactTask.addError("pluginId", "Could not determine the plugin to perform the plugin validations. Possible reasons: artifact store does not exist or plugin is not installed."); } } }
@Test public void hasValidPluginAndStore_shouldReturnFalseIfStoreDoesNotExist() { PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("dist", "s3"); assertFalse(pluggableArtifactConfig.hasValidPluginAndStore(new ArtifactStore("docker", "cd.go.docker"))); }
@Test public void hasValidPluginAndStore_shouldReturnFalseIfPluginDoesNotExist() { ArtifactMetadataStore.instance().remove("cd.go.s3"); PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("dist", "s3"); assertFalse(pluggableArtifactConfig.hasValidPluginAndStore(new ArtifactStore("s3", "cd.go.s3"))); }