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.mirror;
18  
19  import static java.util.Objects.requireNonNull;
20  
21  import java.net.URI;
22  
23  import javax.annotation.Nullable;
24  
25  import com.cronutils.model.Cron;
26  import com.google.common.base.MoreObjects;
27  
28  import com.linecorp.centraldogma.server.storage.repository.Repository;
29  
30  /**
31   * A context of a mirror.
32   */
33  public final class MirrorContext {
34  
35      private final Cron schedule;
36      private final MirrorDirection direction;
37      private final MirrorCredential credential;
38      private final Repository localRepo;
39      private final String localPath;
40      private final URI remoteUri;
41      @Nullable
42      private final String gitignore;
43  
44      /**
45       * Creates a new instance.
46       */
47      public MirrorContext(Cron schedule, MirrorDirection direction, MirrorCredential credential,
48                           Repository localRepo, String localPath, URI remoteUri, @Nullable String gitignore) {
49          this.schedule = requireNonNull(schedule, "schedule");
50          this.direction = requireNonNull(direction, "direction");
51          this.credential = requireNonNull(credential, "credential");
52          this.localRepo = requireNonNull(localRepo, "localRepo");
53          this.localPath = requireNonNull(localPath, "localPath");
54          this.remoteUri = requireNonNull(remoteUri, "remoteUri");
55          this.gitignore = gitignore;
56      }
57  
58      /**
59       * Returns the cron schedule of this mirror.
60       */
61      public Cron schedule() {
62          return schedule;
63      }
64  
65      /**
66       * Returns the direction of this mirror.
67       */
68      public MirrorDirection direction() {
69          return direction;
70      }
71  
72      /**
73       * Returns the credential of this mirror.
74       */
75      public MirrorCredential credential() {
76          return credential;
77      }
78  
79      /**
80       * Returns the local repository of this mirror.
81       */
82      public Repository localRepo() {
83          return localRepo;
84      }
85  
86      /**
87       * Returns the local path of this mirror.
88       */
89      public String localPath() {
90          return localPath;
91      }
92  
93      /**
94       * Returns the remote URI of this mirror.
95       */
96      public URI remoteUri() {
97          return remoteUri;
98      }
99  
100     /**
101      * Returns the gitignore of this mirror.
102      */
103     @Nullable
104     public String gitignore() {
105         return gitignore;
106     }
107 
108     @Override
109     public String toString() {
110         return MoreObjects.toStringHelper(this).omitNullValues()
111                           .add("schedule", schedule)
112                           .add("direction", direction)
113                           .add("credential", credential)
114                           .add("localRepo", localRepo)
115                           .add("localPath", localPath)
116                           .add("remoteUri", remoteUri)
117                           .add("gitignore", gitignore)
118                           .toString();
119     }
120 }