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.util.ConfigUtils;
35  
36  @Singleton
37  @Named(SigstoreSignatureArtifactGeneratorFactory.NAME)
38  public final class SigstoreSignatureArtifactGeneratorFactory implements ArtifactGeneratorFactory {
39  
40      public static final String NAME = "sigstore";
41  
42      private final ArtifactPredicateFactory artifactPredicateFactory;
43  
44      @Inject
45      public SigstoreSignatureArtifactGeneratorFactory(ArtifactPredicateFactory artifactPredicateFactory) {
46          this.artifactPredicateFactory = artifactPredicateFactory;
47      }
48  
49      @Override
50      public ArtifactGenerator newInstance(RepositorySystemSession session, InstallRequest request) {
51          return null; // nothing on install
52      }
53  
54      @Override
55      public ArtifactGenerator newInstance(RepositorySystemSession session, DeployRequest request) {
56          return newInstance(session, request.getArtifacts()); // generate on deploy
57      }
58  
59      private ArtifactGenerator newInstance(RepositorySystemSession session, Collection<Artifact> artifacts) {
60          final boolean enabled = ConfigUtils.getBoolean(
61                  session, SigstoreConfigurationKeys.DEFAULT_ENABLED, SigstoreConfigurationKeys.CONFIG_PROP_ENABLED);
62          if (!enabled) {
63              return null;
64          }
65          final boolean publicStaging = ConfigUtils.getBoolean(
66                  session,
67                  SigstoreConfigurationKeys.DEFAULT_PUBLIC_STAGING,
68                  SigstoreConfigurationKeys.CONFIG_PROP_PUBLIC_STAGING);
69  
70          return new SigstoreSignatureArtifactGenerator(
71                  artifacts, artifactPredicateFactory.newInstance(session)::hasChecksums, publicStaging);
72      }
73  
74      @Override
75      public float getPriority() {
76          return 150;
77      }
78  }