cstamas commented on code in PR #200: URL: https://github.com/apache/maven-resolver/pull/200#discussion_r990937724
########## maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/resolution/TrustedChecksumArtifactResolverPostProcessor.java: ########## @@ -0,0 +1,226 @@ +package org.eclipse.aether.internal.impl.resolution; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.internal.impl.checksum.Sha1ChecksumAlgorithmFactory; +import org.eclipse.aether.repository.ArtifactRepository; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.spi.checksums.TrustedChecksumsSource; +import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory; +import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySelector; +import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmHelper; +import org.eclipse.aether.transfer.ChecksumFailureException; +import org.eclipse.aether.util.ConfigUtils; +import org.eclipse.aether.util.artifact.ArtifactIdUtils; + +import static java.util.Objects.requireNonNull; + +/** + * Artifact resolver processor that verifies the checksums all the resolved artifacts against trusted checksums. Is also + * able to "record" (calculate and write them to trusted checksum sources that does support this operation). + * + * @since TBD + */ +@Singleton +@Named( TrustedChecksumArtifactResolverPostProcessor.NAME ) +public final class TrustedChecksumArtifactResolverPostProcessor + extends ArtifactResolverPostProcessorSupport +{ + public static final String NAME = "trusted-checksum"; + + private static final String CONF_CHECKSUM_ALGORITHM = "checksumAlgorithm"; + + private static final String CONF_FAIL_IF_MISSING = "failIfMissing"; + + private static final String CONF_RECORD = "record"; + + private final ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector; + + private final Map<String, TrustedChecksumsSource> trustedChecksumsSources; + + @Inject + public TrustedChecksumArtifactResolverPostProcessor( + ChecksumAlgorithmFactorySelector checksumAlgorithmFactorySelector, + Map<String, TrustedChecksumsSource> trustedChecksumsSources ) + { + super( NAME ); + this.checksumAlgorithmFactorySelector = requireNonNull( checksumAlgorithmFactorySelector ); + this.trustedChecksumsSources = requireNonNull( trustedChecksumsSources ); + } + + @Override + protected Outcome doProcess( RepositorySystemSession session, List<ArtifactResult> artifactResults ) + { + final List<ChecksumAlgorithmFactory> checksumAlgorithmFactories = Collections.singletonList( + checksumAlgorithmFactorySelector.select( ConfigUtils.getString( session, + Sha1ChecksumAlgorithmFactory.NAME, configPropKey( CONF_CHECKSUM_ALGORITHM ) ) ) ); + final boolean failIfMissing = ConfigUtils.getBoolean( + session, false, configPropKey( CONF_FAIL_IF_MISSING ) ); + final boolean record = ConfigUtils.getBoolean( session, false, configPropKey( CONF_RECORD ) ); Review Comment: configPropKey prefixes it -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
