View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.generator.sigstore;
20  
21  import javax.inject.Inject;
22  import javax.inject.Named;
23  import javax.inject.Singleton;
24  
25  import java.util.Collection;
26  
27  import org.eclipse.aether.RepositorySystemSession;
28  import org.eclipse.aether.artifact.Artifact;
29  import org.eclipse.aether.deployment.DeployRequest;
30  import org.eclipse.aether.installation.InstallRequest;
31  import org.eclipse.aether.spi.artifact.ArtifactPredicateFactory;
32  import org.eclipse.aether.spi.artifact.generator.ArtifactGenerator;
33  import org.eclipse.aether.spi.artifact.generator.ArtifactGeneratorFactory;
34  import org.eclipse.aether.spi.io.PathProcessor;
35  import org.eclipse.aether.util.ConfigUtils;
36  
37  @Singleton
38  @Named(SigstoreSignatureArtifactGeneratorFactory.NAME)
39  public final class SigstoreSignatureArtifactGeneratorFactory implements ArtifactGeneratorFactory {
40  
41      public static final String NAME = "sigstore";
42  
43      private final ArtifactPredicateFactory artifactPredicateFactory;
44      private final PathProcessor pathProcessor;
45  
46      @Inject
47      public SigstoreSignatureArtifactGeneratorFactory(
48              ArtifactPredicateFactory artifactPredicateFactory, PathProcessor pathProcessor) {
49          this.artifactPredicateFactory = artifactPredicateFactory;
50          this.pathProcessor = pathProcessor;
51      }
52  
53      @Override
54      public ArtifactGenerator newInstance(RepositorySystemSession session, InstallRequest request) {
55          return null; // nothing on install
56      }
57  
58      @Override
59      public ArtifactGenerator newInstance(RepositorySystemSession session, DeployRequest request) {
60          return newInstance(session, request.getArtifacts()); // generate on deploy
61      }
62  
63      private ArtifactGenerator newInstance(RepositorySystemSession session, Collection<Artifact> artifacts) {
64          final boolean enabled = ConfigUtils.getBoolean(
65                  session, SigstoreConfigurationKeys.DEFAULT_ENABLED, SigstoreConfigurationKeys.CONFIG_PROP_ENABLED);
66          if (!enabled) {
67              return null;
68          }
69          final boolean publicStaging = ConfigUtils.getBoolean(
70                  session,
71                  SigstoreConfigurationKeys.DEFAULT_PUBLIC_STAGING,
72                  SigstoreConfigurationKeys.CONFIG_PROP_PUBLIC_STAGING);
73  
74          return new SigstoreSignatureArtifactGenerator(
75                  pathProcessor, artifacts, artifactPredicateFactory.newInstance(session)::hasChecksums, publicStaging);
76      }
77  
78      @Override
79      public float getPriority() {
80          return 150;
81      }
82  }