@Test public void shouldValidateArtifactStoreIdPattern() { ArtifactStore store = new ArtifactStore("!123", "docker"); store.validate(null); assertThat(store.errors().size(), is(1)); assertThat(store.errors().on(ArtifactStore.ID), is("Invalid id '!123'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.")); }
public boolean hasValidPluginAndStore(ArtifactStore artifactStore) { if (artifactStore == null) { return false; } ArtifactPluginInfo pluginInfo = ArtifactMetadataStore.instance().getPluginInfo(artifactStore.getPluginId()); return pluginInfo != null; }
private Map getArtifactStore(ArtifactStore artifactStore) { final HashMap<String, Object> artifactStoreAndPlans = new HashMap<>(); artifactStoreAndPlans.put("id", artifactStore.getId()); artifactStoreAndPlans.put("configuration", artifactStore.getConfigurationAsMap(true)); return artifactStoreAndPlans; }
@Override protected boolean hasPluginInfo() { return metadataStore().getPluginInfo(getPluginId()) != null; } }
public Map<String, String> storeIdToPluginId() { HashMap<String, String> artifactStoreToPluginId = new HashMap<>(); for (ArtifactStore artifactStore : getPluginProfiles()) { artifactStoreToPluginId.put(artifactStore.getId(), artifactStore.getPluginId()); } return artifactStoreToPluginId; } }
@Test public void validateTree_shouldValidateNullId() { PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig(null, "s3"); final ArtifactStores artifactStores = new ArtifactStores(new ArtifactStore("s3", "cd.go.s3")); final boolean result = artifactConfig.validateTree(ValidationContextMother.validationContext(artifactStores)); assertFalse(result); }
public static void toJSON(OutputWriter outputWriter, ArtifactStore store) { outputWriter .addLinks(linksWriter -> linksWriter .addLink("self", Routes.ArtifactStoreConfig.id(store.getId())) .addAbsoluteLink("doc", Routes.ArtifactStoreConfig.DOC) .addLink("find", Routes.ArtifactStoreConfig.find())) .add("id", store.getId()) .add("plugin_id", store.getPluginId()) .addChildList("properties", listWriter -> store.forEach(property -> listWriter.addChild(propertyWriter -> ConfigurationPropertyRepresenter.toJSON(propertyWriter, property)))); if (store.hasErrors()) { Map<String, String> fieldMapping = Collections.singletonMap("pluginId", "plugin_id"); outputWriter.addChild("errors", errorWriter -> new ErrorGetter(fieldMapping).toJSON(errorWriter, store)); } }
@Test public void addConfigurations_shouldAddConfigurationsWithValue() { ConfigurationProperty property = create("username", false, "some_value"); ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id"); artifactStore.addConfigurations(Arrays.asList(property)); assertThat(artifactStore.size(), is(1)); assertThat(artifactStore, contains(create("username", false, "some_value"))); }
@Test public void postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined() { ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); artifactStore.encryptSecureConfigurations(); assertThat(artifactStore.size(), is(1)); assertFalse(artifactStore.first().isSecure()); }
public static ArtifactStore fromJSON(JsonReader jsonReader) { ArtifactStore artifactStore = new ArtifactStore( jsonReader.getString("id"), jsonReader.getString("plugin_id")); artifactStore.addConfigurations(ConfigurationPropertyRepresenter.fromJSONArray(jsonReader, "properties")); return artifactStore; } }
@Test public void shouldReturnFalseIfPluginInfoIsDefined() { final ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id"); assertFalse(artifactStore.hasPluginInfo()); }
@Test public void shouldReturnObjectDescription() { assertThat(new ArtifactStore().getObjectDescription(), is("Artifact store")); }
private void haltIfEntityWithSameIdExists(ArtifactStore artifactStore) { if (artifactStoreService.findArtifactStore(artifactStore.getId()) == null) { return; } artifactStore.addError("id", "Artifact store ids should be unique. Artifact store with the same id exists."); throw haltBecauseEntityAlreadyExists(jsonWriter(artifactStore), "artifactStore", artifactStore.getId()); } }
@Test public void validate_shouldAddAnErrorIfArtifactIdIsInvalid() { PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("asf@%", "f"); final ArtifactStores artifactStores = new ArtifactStores(new ArtifactStore("docker", "cd.go.docker")); final boolean result = artifactConfig.validateTree(ValidationContextMother.validationContext(artifactStores)); assertFalse(result); assertThat(artifactConfig.errors().getAllOn("id"), is(Arrays.asList("Invalid pluggable artifact id name 'asf@%'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."))); }
@Test public void addConfigurations_shouldAddConfigurationsWithEncryptedValue() { ConfigurationProperty property = create("username", true, "some_value"); ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id"); artifactStore.addConfigurations(Arrays.asList(property)); assertThat(artifactStore.size(), is(1)); assertThat(artifactStore, contains(create("username", true, "some_value"))); }
@Test public void postConstruct_shouldEncryptSecureConfigurations() { final PluggableInstanceSettings storeConfig = new PluggableInstanceSettings( Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))) ); final ArtifactPluginInfo pluginInfo = new ArtifactPluginInfo(pluginDescriptor("plugin_id"), storeConfig, null, null, null, null); store.setPluginInfo(pluginInfo); ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); artifactStore.encryptSecureConfigurations(); assertThat(artifactStore.size(), is(1)); assertTrue(artifactStore.first().isSecure()); }
@Test public void shouldReturnTrueIfPluginInfoIsDefined() { final ArtifactPluginInfo pluginInfo = new ArtifactPluginInfo(pluginDescriptor("plugin_id"), null, null, null, null, null); store.setPluginInfo(pluginInfo); final ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id"); assertTrue(artifactStore.hasPluginInfo()); }
@Override protected boolean isSecure(String key) { ArtifactPluginInfo pluginInfo = metadataStore().getPluginInfo(getPluginId()); if (pluginInfo == null || pluginInfo.getStoreConfigSettings() == null || pluginInfo.getStoreConfigSettings().getConfiguration(key) == null) { return false; } return pluginInfo.getStoreConfigSettings().getConfiguration(key).isSecure(); }
private Map getArtifactStore(ArtifactStore artifactStore) { final HashMap<String, Object> artifactStoreAndPlans = new HashMap<>(); artifactStoreAndPlans.put("id", artifactStore.getId()); artifactStoreAndPlans.put("configuration", artifactStore.getConfigurationAsMap(true)); return artifactStoreAndPlans; }