default String etag() { return sha256Hex(Integer.toString(hashCode())); } }
private String etagFor(Object entity) { return sha256Hex(Integer.toString(entity.hashCode())); }
private String generateFingerprintFromCriteria(Map<String, Object> sqlCriteria) { List<String> list = new ArrayList<>(); for (Map.Entry<String, Object> criteria : sqlCriteria.entrySet()) { list.add(new StringBuilder().append(criteria.getKey()).append("=").append(criteria.getValue()).toString()); } String fingerprint = StringUtils.join(list, FINGERPRINT_DELIMITER); // CAREFUL! the hash algorithm has to be same as the one used in 47_create_new_materials.sql return CachedDigestUtils.sha256Hex(fingerprint); }
private String generateFingerprintFromCriteria(Map<String, Object> sqlCriteria) { List<String> list = new ArrayList<>(); for (Map.Entry<String, Object> criteria : sqlCriteria.entrySet()) { list.add(new StringBuilder().append(criteria.getKey()).append("=").append(criteria.getValue()).toString()); } String fingerprint = StringUtils.join(list, FINGERPRINT_DELIMITER); // CAREFUL! the hash algorithm has to be same as the one used in 47_create_new_materials.sql return CachedDigestUtils.sha256Hex(fingerprint); }
public String etagForExport(PipelineConfig pipelineConfig, String groupName) { return sha256Hex(Integer.toString(Objects.hash(pipelineConfig, groupName, crExtension.pluginDescriptorFor(pluginId)))); } }
public String getProcessNamespace(String fingerprint) { return CachedDigestUtils.sha256Hex(fingerprint + agentIdentifier.getUuid() + workingDirectory); }
public String getProcessNamespace(String fingerprint) { return CachedDigestUtils.sha256Hex(goConfigService.getServerId() + fingerprint);//memoize if necessary(for gc reasons) -jj }
public String getFingerprint() { List<String> list = new ArrayList<>(); list.add(format("%s=%s", "plugin-id", getPluginId())); handleSCMProperties(list); String fingerprint = StringUtils.join(list, AbstractMaterialConfig.FINGERPRINT_DELIMITER); // CAREFUL! the hash algorithm has to be same as the one used in 47_create_new_materials.sql return CachedDigestUtils.sha256Hex(fingerprint); }
public String getFingerprint(String fingerprintDelimiter) { List<String> list = new ArrayList<>(); list.add(format("%s=%s", "plugin-id", pluginId())); handlePackageDefinitionProperties(list); handlePackageRepositoryProperties(list); String fingerprint = StringUtils.join(list, fingerprintDelimiter); // CAREFUL! the hash algorithm has to be same as the one used in 47_create_new_materials.sql return CachedDigestUtils.sha256Hex(fingerprint); }
@Test public void shouldComputeForAGiveStringUsing256SHA() { String fingerprint = "Some String"; String computeMD5 = CachedDigestUtils.sha256Hex(fingerprint); assertThat(computeMD5, is(DigestUtils.sha256Hex(fingerprint))); }
@Test public void shouldComputeForAnEmptyStringUsing256SHA() { String fingerprint = ""; String computeMD5 = CachedDigestUtils.sha256Hex(fingerprint); assertThat(computeMD5, is(DigestUtils.sha256Hex(fingerprint))); }
@Test public void shouldReturnDigestOfMaterialFingerprintConcatinatedWithAgentUUID() { AgentIdentifier agentIdentifier = mock(AgentIdentifier.class); String uuid = "agent-uuid"; when(agentIdentifier.getUuid()).thenReturn(uuid); String fingerprint = "material-fingerprint"; String workingDirectory = "working-folder-full-path"; AgentSubprocessExecutionContext execCtx = new AgentSubprocessExecutionContext(agentIdentifier, workingDirectory); String workspaceName = execCtx.getProcessNamespace(fingerprint); assertThat(workspaceName, is(CachedDigestUtils.sha256Hex(fingerprint + uuid + workingDirectory))); assertThat(workspaceName.length(), is(64)); } }
@Test public void shouldGetFingerprintForMaterial() { ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1"); ConfigurationProperty k2 = ConfigurationPropertyMother.create("secure-key", true, "secure-value"); SCM scmConfig = SCMMother.create("scm-id", "scm-name", "pluginid", "version", new Configuration(k1, k2)); PluggableSCMMaterial material = new PluggableSCMMaterial(); material.setSCMConfig(scmConfig); assertThat(material.getFingerprint(), is(CachedDigestUtils.sha256Hex("plugin-id=pluginid<|>k1=v1<|>secure-key=secure-value"))); }
@Test public void shouldNotConsiderAllPropertiesForFingerprintWhenMetadataIsNotAvailable() { String pluginId = "plugin-id"; PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("rk1", false, "rv1"), create("rk2", false, "rv2"))); PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("pk1", false, "pv1"), create("pk2", false, "pv2")), repository); String fingerprint = packageDefinition.getFingerprint(AbstractMaterial.FINGERPRINT_DELIMITER); assertThat(fingerprint, is(CachedDigestUtils.sha256Hex("plugin-id=plugin-id<|>pk1=pv1<|>pk2=pv2<|>rk1=rv1<|>rk2=rv2"))); }
@Test public void shouldCreateMaterialAgent_withAgentsUuidAsSubprocessExecutionContextNamespace() throws IOException { String agentUuid = "uuid-01783738"; File workingDirectory = temporaryFolder.newFolder(); MaterialAgentFactory factory = new MaterialAgentFactory(new ProcessOutputStreamConsumer(new DevNull(), new DevNull()), workingDirectory, new AgentIdentifier("host", "1.1.1.1", agentUuid), scmExtension); GitMaterial gitMaterial = new GitMaterial("http://foo", "master", "dest_folder"); MaterialAgent agent = factory.createAgent(new MaterialRevision(gitMaterial)); assertThat(agent, is(instanceOf(AbstractMaterialAgent.class))); SubprocessExecutionContext execCtx = (SubprocessExecutionContext) ReflectionUtil.getField(agent, "execCtx"); assertThat(execCtx.getProcessNamespace("fingerprint"), is(CachedDigestUtils.sha256Hex(String.format("%s%s%s", "fingerprint", agentUuid, gitMaterial.workingdir(workingDirectory))))); }
@Test public void shouldGetFingerprintForMaterial() { PackageMaterial material = new PackageMaterial(); PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1"), ConfigurationPropertyMother.create("secure-key", true, "secure-value"))); material.setPackageDefinition(PackageDefinitionMother.create("p-id", "name", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2")), repository)); assertThat(material.getFingerprint(), is(CachedDigestUtils.sha256Hex("plugin-id=pluginid<|>k2=v2<|>k1=v1<|>secure-key=secure-value"))); }
@Test public void shouldGetFingerprint() { String pluginId = "pluginid"; PackageConfigurations repositoryConfigurations = new PackageConfigurations(); repositoryConfigurations.add(new PackageConfiguration("k1", "v1").with(PackageConfiguration.PART_OF_IDENTITY, true)); RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations); PackageConfigurations packageConfigurations = new PackageConfigurations(); packageConfigurations.add(new PackageConfiguration("k2", "v2").with(PackageConfiguration.PART_OF_IDENTITY, true)); PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations); PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("k1", false, "v1"))); PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("k2", false, "v2")), repository); String fingerprint = packageDefinition.getFingerprint(AbstractMaterial.FINGERPRINT_DELIMITER); assertThat(fingerprint, is(CachedDigestUtils.sha256Hex("plugin-id=pluginid<|>k2=v2<|>k1=v1"))); }
@Test public void shouldNotConsiderPropertiesMarkedAsNotPartOfIdentity_GetFingerprint() { String pluginId = "plugin-id"; PackageConfigurations repositoryConfigurations = new PackageConfigurations(); repositoryConfigurations.add(new PackageConfiguration("rk1", "rv1").with(PackageConfiguration.PART_OF_IDENTITY, true)); repositoryConfigurations.add(new PackageConfiguration("rk2", "rv2").with(PackageConfiguration.PART_OF_IDENTITY, false)); RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations); PackageConfigurations packageConfigurations = new PackageConfigurations(); packageConfigurations.add(new PackageConfiguration("pk1", "pv1").with(PackageConfiguration.PART_OF_IDENTITY, false)); packageConfigurations.add(new PackageConfiguration("pk2", "pv2").with(PackageConfiguration.PART_OF_IDENTITY, true)); PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations); PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("rk1", false, "rv1"), create("rk2", false, "rv2"))); PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", new Configuration(create("pk1", false, "pv1"), create("pk2", false, "pv2")), repository); String fingerprint = packageDefinition.getFingerprint(AbstractMaterial.FINGERPRINT_DELIMITER); assertThat(fingerprint, is(CachedDigestUtils.sha256Hex("plugin-id=plugin-id<|>pk2=pv2<|>rk1=rv1"))); }