hudson.model.Fingerprint Java Examples
The following examples show how to use
hudson.model.Fingerprint.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WithMavenStepTest.java From pipeline-maven-plugin with MIT License | 6 votes |
@Test public void disable_all_publishers() throws Exception { loadMonoDependencyMavenProjectInGitRepo( this.gitRepoRule ); String pipelineScript = "node('master') {\n" + " git($/" + gitRepoRule.toString() + "/$)\n" + " withMaven(publisherStrategy: 'EXPLICIT') {\n" + " sh 'mvn package'\n" + " }\n" + "}"; String commonsLang3version35Md5 = "780b5a8b72eebe6d0dbff1c11b5658fa"; WorkflowJob firstPipeline = jenkinsRule.createProject(WorkflowJob.class, "disable-all-publishers"); firstPipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true)); jenkinsRule.assertBuildStatus(Result.SUCCESS, firstPipeline.scheduleBuild2(0)); FingerprintMap fingerprintMap = jenkinsRule.jenkins.getFingerprintMap(); Fingerprint fingerprint = fingerprintMap.get(commonsLang3version35Md5); Assert.assertThat( fingerprint, Matchers.nullValue() ); }
Example #2
Source File: FromFingerprintStepTest.java From docker-workflow-plugin with MIT License | 6 votes |
private void assertBuild(final String projectName, final String pipelineCode, final String fromImage) throws Exception { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { assumeDocker(); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, projectName); p.setDefinition(new CpsFlowDefinition(pipelineCode, true)); WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)); DockerClient client = new DockerClient(new LocalLauncher(StreamTaskListener.NULL), null, null); String ancestorImageId = client.inspect(new EnvVars(), fromImage, ".Id"); story.j.assertLogContains(ancestorImageId.replaceFirst("^sha256:", "").substring(0, 12), b); Fingerprint f = DockerFingerprints.of(ancestorImageId); assertNotNull(f); DockerDescendantFingerprintFacet descendantFacet = f.getFacet(DockerDescendantFingerprintFacet.class); assertNotNull(descendantFacet); } }); }
Example #3
Source File: SaveableChangeListener.java From audit-log-plugin with MIT License | 6 votes |
/** * Fired when a saveable object is created. But for now this is customized to only log * the saveable fingerprint instances. * * @param o the saveable object. * @param file the XmlFile for this saveable object. */ @Override public void onChange(Saveable o, XmlFile file) { if(o instanceof Fingerprint){ UseCredentials useCredentials = LogEventFactory.getEvent(UseCredentials.class); Fingerprint fp = (Fingerprint) o; useCredentials.setFileName(fp.getFileName()); useCredentials.setName(fp.getDisplayName()); useCredentials.setTimestamp(formatDateISO(fp.getTimestamp().getTime())); Hashtable<String, Fingerprint.RangeSet> usages = fp.getUsages(); if (usages != null) { usages.values().forEach(value -> { useCredentials.setUsage(value.toString()); useCredentials.logEvent(); }); } } }
Example #4
Source File: DockerRunFingerprintFacetTest.java From docker-commons-plugin with MIT License | 6 votes |
@Test public void test_readResolve() throws Exception { FreeStyleProject p = rule.createFreeStyleProject("test"); FreeStyleBuild b = rule.assertBuildStatusSuccess(p.scheduleBuild2(0)); ContainerRecord r1 = new ContainerRecord("192.168.1.10", "cid", IMAGE_ID, "magic", System.currentTimeMillis(), Collections.<String, String>emptyMap()); DockerFingerprints.addRunFacet(r1, b); Fingerprint fingerprint = DockerFingerprints.of(IMAGE_ID); DockerRunFingerprintFacet facet = new DockerRunFingerprintFacet(fingerprint, System.currentTimeMillis(), IMAGE_ID); ContainerRecord r2 = new ContainerRecord("192.168.1.10", "cid", null, "magic", System.currentTimeMillis(), Collections.<String, String>emptyMap()); facet.add(r2); Assert.assertNull(r2.getImageId()); facet.readResolve(); Assert.assertEquals(IMAGE_ID, r2.getImageId()); // Check that actions have been automatically added DockerFingerprintAction fpAction = b.getAction(DockerFingerprintAction.class); Assert.assertNotNull("DockerFingerprintAction should be added automatically", fpAction); Assert.assertTrue("Docker image should be referred in the action", fpAction.getImageIDs().contains(IMAGE_ID)); }
Example #5
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Checks that the existence {@link DockerDeploymentRefFacet}. * @param containerId Container ID * @param imageId image ID * @return Facet (if validation passes) * @throws IOException test failure * @throws AssertionError Validation failure */ public DockerDeploymentRefFacet assertExistsDeploymentRefFacet (@Nonnull String containerId, @Nonnull String imageId) throws IOException { final Fingerprint imageFP = DockerFingerprints.of(imageId); assertNotNull(imageFP); final DockerDeploymentRefFacet containerRefFacet = FingerprintsHelper.getFacet(imageFP, DockerDeploymentRefFacet.class); assertNotNull(containerRefFacet); assertEquals(1, containerRefFacet.getContainerIds().size()); for (String containerRefId : containerRefFacet.getContainerIds()) { assertNotNull(containerRefFacet.getLastStatus(containerRefId)); } assertEquals(containerId, containerRefFacet.getContainerIds().toArray()[0]); return containerRefFacet; }
Example #6
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Checks that the existence {@link DockerDeploymentFacet}. * @param containerId Container ID * @param imageId image ID * @return Facet (if validation passes) * @throws IOException test failure * @throws AssertionError Validation failure */ private @Nonnull DockerDeploymentFacet assertExistsDeploymentFacet (@Nonnull String containerId, @Nonnull String imageId) throws IOException { final Fingerprint containerFP = DockerTraceabilityHelper.ofValidated(containerId); assertNotNull(containerFP); final DockerDeploymentFacet containerFacet = FingerprintsHelper.getFacet(containerFP, DockerDeploymentFacet.class); assertNotNull(containerFacet); assertEquals(1, containerFacet.getDeploymentRecords().size()); final DockerContainerRecord record = containerFacet.getLatest(); assertNotNull(containerFacet.getLatest()); assertEquals(containerId, record.getContainerId()); assertEquals(DockerTraceabilityHelper.getImageHash(imageId), record.getImageFingerprintHash()); return containerFacet; }
Example #7
Source File: DockerTraceabilityHelper.java From docker-traceability-plugin with MIT License | 6 votes |
/** * Retrieves the last {@link InspectImageResponse} for the specified image. * @param imageId Image Id * @return Last available report. Null if there is no data available * (or if an internal exception happens) */ public static @CheckForNull InspectImageResponse getLastInspectImageResponse(@Nonnull String imageId) { try { final Fingerprint fp = DockerFingerprints.of(imageId); if (fp != null) { final DockerInspectImageFacet facet = FingerprintsHelper.getFacet(fp, DockerInspectImageFacet.class); if (facet != null) { return facet.getData(); } } return null; } catch (IOException ex) { LOGGER.log(Level.WARNING, "Cannot retrieve deployment reports for imageId="+imageId, ex); return null; } }
Example #8
Source File: DockerFingerprintAction.java From docker-commons-plugin with MIT License | 5 votes |
/** * Adds an action with a reference to fingerprint if required. It's * recommended to call the method from { * * @BulkChange} transaction to avoid saving the {@link Run} multiple times. * @param fp Fingerprint * @param imageId ID of the docker image * @param run Run to be updated * @throws IOException Cannot save the action */ static void addToRun(Fingerprint fp, String imageId, Run run) throws IOException { synchronized (run) { DockerFingerprintAction action = run.getAction(DockerFingerprintAction.class); if (action == null) { action = new DockerFingerprintAction(); run.addAction(action); } if (action.imageIDs.add(imageId)) { run.save(); } // else no need to save updates } }
Example #9
Source File: WithMavenStepOnMasterTest.java From pipeline-maven-plugin with MIT License | 5 votes |
private void verifyFileIsFingerPrinted(WorkflowJob pipeline, WorkflowRun build, String fileName) throws java.io.IOException { System.out.println(getClass() + " verifyFileIsFingerPrinted(" + build + ", " + fileName + ")"); Fingerprinter.FingerprintAction fingerprintAction = build.getAction(Fingerprinter.FingerprintAction.class); Map<String, String> records = fingerprintAction.getRecords(); System.out.println(getClass() + " records: " + records); String jarFileMd5sum = records.get(fileName); assertThat(jarFileMd5sum, not(nullValue())); Fingerprint jarFileFingerPrint = jenkinsRule.getInstance().getFingerprintMap().get(jarFileMd5sum); assertThat(jarFileFingerPrint.getFileName(), is(fileName)); assertThat(jarFileFingerPrint.getOriginal().getJob().getName(), is(pipeline.getName())); assertThat(jarFileFingerPrint.getOriginal().getNumber(), is(build.getNumber())); }
Example #10
Source File: DockerTraceabilityHelper.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Retrieves the last deployment record for the specified container. * @param containerId Container Id * @return Last registered record. Null if there is no data available * (or if an internal exception happens) */ public static @CheckForNull DockerContainerRecord getLastContainerRecord(@Nonnull String containerId) { final Fingerprint fp = of(containerId); if (fp != null) { final DockerDeploymentFacet facet = FingerprintsHelper.getFacet(fp, DockerDeploymentFacet.class); if (facet != null) { return facet.getLatest(); } } return null; }
Example #11
Source File: DockerTraceabilityHelper.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Get or create a fingerprint by the specified image ID. * @param imageId Full 64-symbol image id. Short forms are not supported. * @param name Optional container name * @param timestamp Timestamp if there is a need to create a new image * @return Fingerprint. null if Jenkins has not been initialized yet * @throws IOException Fingerprint loading error */ public static @CheckForNull Fingerprint makeImage(@Nonnull String imageId, @CheckForNull String name, long timestamp) throws IOException { final Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { return null; } // TODO: this image is not protected from the fingerprint cleanup thread final Fingerprint fp = jenkins.getFingerprintMap().getOrCreate( null, "Image "+(name != null ? name : imageId), getImageHash(imageId)); return fp; }
Example #12
Source File: DockerInspectImageFacet.java From docker-traceability-plugin with MIT License | 5 votes |
public DockerInspectImageFacet(@Nonnull Fingerprint fingerprint, long timestamp, @Nonnull InspectImageResponse data, @Nonnull String imageName) { super(fingerprint, timestamp); this.data = data; this.reportTimeInSeconds = timestamp; this.imageName = hudson.Util.fixEmpty(imageName); }
Example #13
Source File: DockerInspectImageFacet.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Updates the facet by a new report. * The submission will be ignored if the current {@link #reportTimeInSeconds} is * greater than the submitted one, * @param fingerprint Fingerprint to be updated * @param reportTimeInSeconds Report generation time. * The time is specified in seconds since January 1, 1970, 00:00:00 GMT * @param data Report data from "docker inspect image" output * @param imageName Optional name of the image * @throws IOException Fingerprint save error */ public static void updateData(@Nonnull Fingerprint fingerprint, long reportTimeInSeconds, @Nonnull InspectImageResponse data, @CheckForNull String imageName) throws IOException { DockerInspectImageFacet facet = FingerprintsHelper.getFacet(fingerprint, DockerInspectImageFacet.class); if (facet == null) { facet = new DockerInspectImageFacet(fingerprint, reportTimeInSeconds, data, imageName); fingerprint.getFacets().add(facet); } else { facet.updateData(data, reportTimeInSeconds, imageName); } fingerprint.save(); }
Example #14
Source File: DockerTraceabilityHelper.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Get or create a fingerprint by the specified container ID. * @param containerId Full 64-symbol container id. Short forms are not supported. * @param name Optional name of the container. If it is not available, * the container ID will be used to produce the name * @return Fingerprint. null if Jenkins has not been initialized yet * @throws IOException Fingerprint loading error */ public static @CheckForNull Fingerprint make(@Nonnull String containerId, @CheckForNull String name) throws IOException { final Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { return null; } return jenkins.getFingerprintMap().getOrCreate(null, "Container "+(name != null ? name : containerId), getContainerHash(containerId)); }
Example #15
Source File: DockerDeploymentRefFacet.java From docker-traceability-plugin with MIT License | 5 votes |
public static DockerDeploymentRefFacet addRef(@Nonnull Fingerprint fingerprint, @Nonnull String containerId) throws IOException { DockerDeploymentRefFacet facet = getOrCreate(fingerprint, new Date().getTime()); facet.addRef(containerId); fingerprint.save(); return facet; }
Example #16
Source File: DockerTraceabilityHelper.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Get a fingerprint by the specified container ID. * Logs and ignores {@link IOException}s on fingerprint loading. * @param containerId Full 64-symbol container id. Short forms are not supported. * @return Fingerprint. null if it is not available or if a loading error happens */ public static @CheckForNull Fingerprint of(@Nonnull String containerId) { try { return ofValidated(containerId); } catch (IOException ex) { LOGGER.log(Level.SEVERE, "Cannot load fingerprint for containerId=" + containerId, ex); return null; } }
Example #17
Source File: DockerDeploymentFacet.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Retrieves a deployment facet for the specified container. * @param containerId Container ID (64-char) * @return Facet. Null if it is not available */ public static @CheckForNull DockerDeploymentFacet getDeploymentFacet(String containerId) { Fingerprint fp = DockerTraceabilityHelper.of(containerId); if (fp == null) { return null; } return FingerprintsHelper.getFacet(fp, DockerDeploymentFacet.class); }
Example #18
Source File: DockerDeploymentFacet.java From docker-traceability-plugin with MIT License | 5 votes |
public static @Nonnull DockerDeploymentFacet getOrCreate(@Nonnull Fingerprint fingerprint) throws IOException { DockerDeploymentFacet res = DockerFingerprints.getFacet(fingerprint, DockerDeploymentFacet.class); if (res != null) { return res; } // Create new one DockerDeploymentFacet facet = new DockerDeploymentFacet(fingerprint); fingerprint.getFacets().add(facet); fingerprint.save(); return facet; }
Example #19
Source File: DockerDeploymentFacet.java From docker-traceability-plugin with MIT License | 5 votes |
public static DockerDeploymentFacet addEvent(@Nonnull Fingerprint fingerprint, @Nonnull DockerTraceabilityReport event) throws IOException { DockerDeploymentFacet facet = getOrCreate(fingerprint); facet.add(new DockerContainerRecord(event)); fingerprint.save(); return facet; }
Example #20
Source File: FingerprintsHelper.java From docker-traceability-plugin with MIT License | 5 votes |
public static @CheckForNull @SuppressWarnings("unchecked") <TFacet extends FingerprintFacet> TFacet getFacet (@Nonnull Fingerprint fingerprint, @Nonnull Class<TFacet> facetClass) { for ( FingerprintFacet facet : fingerprint.getFacets()) { if (facetClass.isAssignableFrom(facet.getClass())) { return (TFacet)facet; } } return null; }
Example #21
Source File: DockerAPIReport.java From docker-traceability-plugin with MIT License | 5 votes |
@Exported(visibility = 999) public Hashtable<String, RangeSet> getUsages() { Hashtable<String, RangeSet> res = new Hashtable<String, RangeSet>(fingerprint.getUsages().size()); for (Map.Entry<String, Fingerprint.RangeSet> set : fingerprint.getUsages().entrySet()) { res.put(set.getKey(), new RangeSet(set.getValue())); } return res; }
Example #22
Source File: DockerFingerprintAction.java From docker-commons-plugin with MIT License | 5 votes |
@Restricted(NoExternalUse.class) public @CheckForNull Fingerprint getFingerprint(@CheckForNull String imageId) { if (imageId == null) { return null; } try { return DockerFingerprints.of(imageId); } catch (IOException ex) { return null; // nothing to do in web UI - return null as well } }
Example #23
Source File: BindingStepTest.java From credentials-binding-plugin with MIT License | 5 votes |
@Issue("JENKINS-38831") @Test public void testTrackingOfCredential() { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { String credentialsId = "creds"; String secret = "s3cr3t"; StringCredentialsImpl credentials = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample", Secret.fromString(secret)); Fingerprint fingerprint = CredentialsProvider.getFingerprintOf(credentials); CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), credentials); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); p.setDefinition(new CpsFlowDefinition("" + "def extract(id) {\n" + " def v\n" + " withCredentials([[$class: 'StringBinding', credentialsId: id, variable: 'temp']]) {\n" + " v = env.temp\n" + " }\n" + " v\n" + "}\n" + "node {\n" + " echo \"got: ${extract('" + credentialsId + "')}\"\n" + "}", true)); assertThat("No fingerprint created until first use", fingerprint, nullValue()); story.j.assertLogContains("got: " + secret, story.j.assertBuildStatusSuccess(p.scheduleBuild2(0).get())); fingerprint = CredentialsProvider.getFingerprintOf(credentials); assertThat(fingerprint, notNullValue()); assertThat(fingerprint.getJobs(), hasItem(is(p.getFullName()))); } }); }
Example #24
Source File: CredentialsTest.java From git-client-plugin with MIT License | 5 votes |
@After public void checkFingerprintNotSet() throws Exception { /* Since these are API level tests, they should not track credential usage */ /* Credential usage is tracked at the job / project level */ Fingerprint fingerprint = CredentialsProvider.getFingerprintOf(testedCredential); assertThat("Fingerprint should not be set after API level use", fingerprint, nullValue()); }
Example #25
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 5 votes |
/** * Checks that the existence {@link DockerInspectImageFacet}. * @param imageId image ID * @return Facet (if validation passes) * @throws IOException test failure * @throws AssertionError Validation failure */ public DockerInspectImageFacet assertExistsInspectImageFacet (@Nonnull String imageId) throws IOException { final Fingerprint imageFP = DockerFingerprints.of(imageId); assertNotNull(imageFP); final DockerInspectImageFacet inspectImageFacet = FingerprintsHelper.getFacet(imageFP, DockerInspectImageFacet.class); assertNotNull(inspectImageFacet); assertEquals(imageId, inspectImageFacet.getData().getId()); return inspectImageFacet; }
Example #26
Source File: DockerFingerprints.java From docker-commons-plugin with MIT License | 5 votes |
private static @CheckForNull Fingerprint ofNoException(@Nonnull String id) { try { return of(id); } catch (IOException ex) { // The error is not a hazard in CheckForNull logic LOGGER.log(Level.WARNING, "Cannot retrieve a fingerprint for Docker id="+id, ex); } return null; }
Example #27
Source File: DockerTraceabilityRootActionTest.java From docker-traceability-plugin with MIT License | 5 votes |
@Test @Bug(28656) public void createFingerPrintsOnDemand() throws Exception { // Read data from resources String inspectData = JSONSamples.inspectContainerData.readString(); InspectContainerResponse inspectResponse = JSONSamples.inspectContainerData. readObject(InspectContainerResponse[].class)[0]; final String containerId = inspectResponse.getId(); final String imageId = inspectResponse.getImageId(); // Retrieve instances final DockerTraceabilityRootAction action = DockerTraceabilityRootAction.getInstance(); assertNotNull(action); // Enable automatic fingerprints creation DockerTraceabilityPluginConfiguration config = new DockerTraceabilityPluginConfiguration(true, false); DockerTraceabilityPluginTest.configure(config); DockerTraceabilityPlugin plugin = DockerTraceabilityPlugin.getInstance(); assertTrue(plugin.getConfiguration().isCreateImageFingerprints()); // Submit JSON HttpResponse res = action.doSubmitContainerStatus(inspectData, null, null, null, 0, null, null); // Ensure that both container and images have been created with proper facets Fingerprint imageFP = DockerFingerprints.of(imageId); Fingerprint containerFP = DockerFingerprints.of(containerId); assertNotNull(imageFP); assertNotNull(DockerFingerprints.getFacet(imageFP, DockerDeploymentRefFacet.class)); assertNotNull(containerFP); assertNotNull(DockerFingerprints.getFacet(containerFP, DockerDeploymentFacet.class)); // TODO: JENKINS-28655 (Fingerprints cleanup) // Check original references - Docker Traceability Manager should create runs // assertNotNull(imageFP.getOriginal().getJob()); // assertNotNull(containerFP.getOriginal().getJob()); }
Example #28
Source File: DockerFingerprints.java From docker-commons-plugin with MIT License | 5 votes |
private static @Nonnull Fingerprint forDockerInstance(@CheckForNull Run<?,?> run, @Nonnull String id, @CheckForNull String name, @Nonnull String prefix) throws IOException { final Jenkins j = Jenkins.getInstance(); if (j == null) { throw new IOException("Jenkins instance is not ready"); } final String imageName = prefix + (StringUtils.isNotBlank(name) ? name : id); return j.getFingerprintMap().getOrCreate(run, imageName, getFingerprintHash(id)); }
Example #29
Source File: DockerFingerprints.java From docker-commons-plugin with MIT License | 5 votes |
/** * Retrieves a facet from the {@link Fingerprint}. * @param <TFacet> Facet type to be retrieved * @param fingerprint Fingerprint, which stores facets * @param facetClass Class to be retrieved * @return First matching facet. */ @SuppressWarnings("unchecked") public static @CheckForNull <TFacet extends FingerprintFacet> TFacet getFacet (@Nonnull Fingerprint fingerprint, @Nonnull Class<TFacet> facetClass) { for ( FingerprintFacet facet : fingerprint.getFacets()) { if (facetClass.isAssignableFrom(facet.getClass())) { return (TFacet)facet; } } return null; }
Example #30
Source File: DockerFingerprints.java From docker-commons-plugin with MIT License | 5 votes |
/** * Retrieves facets from the {@link Fingerprint}. * @param <TFacet> Facet type to be retrieved * @param fingerprint Fingerprint, which stores facets * @param facetClass Facet class to be retrieved * @return All found facets */ public static @Nonnull @SuppressWarnings("unchecked") <TFacet extends FingerprintFacet> Collection<TFacet> getFacets (@Nonnull Fingerprint fingerprint, @Nonnull Class<TFacet> facetClass) { final List<TFacet> res = new LinkedList<TFacet>(); for ( FingerprintFacet facet : fingerprint.getFacets()) { if (facetClass.isAssignableFrom(facet.getClass())) { res.add((TFacet)facet); } } return res; }