1   /*
2    * Copyright 2023 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  
17  package com.linecorp.centraldogma.server.plugin;
18  
19  import static java.util.Objects.requireNonNull;
20  
21  import java.util.concurrent.ScheduledExecutorService;
22  import java.util.function.Function;
23  
24  import com.linecorp.armeria.server.HttpService;
25  import com.linecorp.armeria.server.ServerBuilder;
26  import com.linecorp.armeria.server.auth.AuthService;
27  import com.linecorp.centraldogma.server.CentralDogmaConfig;
28  import com.linecorp.centraldogma.server.command.CommandExecutor;
29  import com.linecorp.centraldogma.server.mirror.MirrorAccessController;
30  import com.linecorp.centraldogma.server.storage.project.InternalProjectInitializer;
31  import com.linecorp.centraldogma.server.storage.project.ProjectManager;
32  
33  import io.micrometer.core.instrument.MeterRegistry;
34  
35  /**
36   * A context that is used to pass when calling {@link AllReplicasPlugin#init(PluginInitContext)}.
37   */
38  public final class PluginInitContext extends PluginContext {
39  
40      private final ServerBuilder serverBuilder;
41      private final Function<? super HttpService, AuthService> authService;
42  
43      /**
44       * Creates a new instance.
45       */
46      public PluginInitContext(CentralDogmaConfig config,
47                               ProjectManager projectManager,
48                               CommandExecutor commandExecutor,
49                               MeterRegistry meterRegistry,
50                               ScheduledExecutorService purgeWorker, ServerBuilder serverBuilder,
51                               Function<? super HttpService, AuthService> authService,
52                               InternalProjectInitializer projectInitializer,
53                               MirrorAccessController mirrorAccessController) {
54          super(config, projectManager, commandExecutor, meterRegistry, purgeWorker, projectInitializer,
55                mirrorAccessController);
56          this.serverBuilder = requireNonNull(serverBuilder, "serverBuilder");
57          this.authService = requireNonNull(authService, "authService");
58      }
59  
60      /**
61       * Returns the {@link ServerBuilder} of the Central Dogma server.
62       */
63      public ServerBuilder serverBuilder() {
64          return serverBuilder;
65      }
66  
67      /**
68       * Returns the {@link AuthService} of the Central Dogma server.
69       */
70      public Function<? super HttpService, AuthService> authService() {
71          return authService;
72      }
73  }