-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new mirroring and credential settings format and REST API (#…
…880) Motivation: The ID for mirroring and credential configurations is optional, so I found it difficult to safely update a configuration with REST API. If a user updates a file manually on UI or commit API, the REST API may update a wrong configuration without a unique ID. @trustin suggested changing the directory layout to store a configuration to a file with a unique ID. #838 (review) This PR has three major changes: - Migrate the old mirror and credential settings to the new layout. ``` - mirrors - <mirror-id>.json - ... - credentials - <credentials-id>.json - ... ``` - Add a migration job to automatically migrate the old settings to the new format when a server starts. The old files are renamed by adding `.bak` suffix. e,g. `mirrors.json` -> `mirrors.json.bak`, `credentials.json` -> `credentials.json.bak`. - Add REST API for mirroring and credential configurations. This is a necessary task to add mirror UI. #838 Modifications: - Add `MirroringMigrationService` that is executed when a server starts and scan all `/mirrors.json` and `/credentials.json` in the meta repo of projects and migrate them to the new format. - "id" is a required property in each configuration. Human-readable random words are used to create a unique ID. - Mirror ID format: `mirror-<projectName>-<localRepo>-<shortWord>` - Credential ID format: `credential-<projectName>-<shortWord>` - `short_wordlist.txt` is used as the word database. - Change `Mirror` and related classes to have `id`, `enabled` as required fields. - Add `CredentailServiceV1` and `MirrorServiceV1` to serve REST API for CRU. - Create, read, and update operations are implemented in `DefaultMetaRepository`. - Add `RepositoryUri` to represent a repository-specific URI such as a Git repository URL. - Add `MirrorDto` to serialize a mirroring configuration. `Mirror` represents a mirroring task, so `Mirror` is not suitable for serialization. - `MirrorCredential` is used as is instead of creating a new DTO. - Migrated all mirroring tests to use the new configuration format. - Updated site documentation with the new format. Result: - Mirroring and credential settings have been updated to the new formats. - You can now access and modify mirroring and credential resources using the REST API.
- Loading branch information
Showing
75 changed files
with
4,477 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,7 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
.swc | ||
|
||
# macOS folder meta-data | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
common/src/main/java/com/linecorp/centraldogma/internal/api/v1/MirrorDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
/* | ||
* Copyright 2023 LINE Corporation | ||
* | ||
* LINE Corporation 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: | ||
* | ||
* https://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. | ||
* | ||
*/ | ||
|
||
package com.linecorp.centraldogma.internal.api.v1; | ||
|
||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.MoreObjects; | ||
|
||
@JsonInclude(Include.NON_NULL) | ||
public final class MirrorDto { | ||
|
||
private final String id; | ||
private final boolean enabled; | ||
private final String projectName; | ||
private final String schedule; | ||
private final String direction; | ||
private final String localRepo; | ||
private final String localPath; | ||
private final String remoteScheme; | ||
private final String remoteUrl; | ||
private final String remotePath; | ||
private final String remoteBranch; | ||
@Nullable | ||
private final String gitignore; | ||
private final String credentialId; | ||
|
||
@JsonCreator | ||
public MirrorDto(@JsonProperty("id") String id, | ||
@JsonProperty("enabled") @Nullable Boolean enabled, | ||
@JsonProperty("projectName") String projectName, | ||
@JsonProperty("schedule") String schedule, | ||
@JsonProperty("direction") String direction, | ||
@JsonProperty("localRepo") String localRepo, | ||
@JsonProperty("localPath") String localPath, | ||
@JsonProperty("remoteScheme") String remoteScheme, | ||
@JsonProperty("remoteUrl") String remoteUrl, | ||
@JsonProperty("remotePath") String remotePath, | ||
@JsonProperty("remoteBranch") String remoteBranch, | ||
@JsonProperty("gitignore") @Nullable String gitignore, | ||
@JsonProperty("credentialId") String credentialId) { | ||
this.id = requireNonNull(id, "id"); | ||
this.enabled = firstNonNull(enabled, true); | ||
this.projectName = requireNonNull(projectName, "projectName"); | ||
this.schedule = requireNonNull(schedule, "schedule"); | ||
this.direction = requireNonNull(direction, "direction"); | ||
this.localRepo = requireNonNull(localRepo, "localRepo"); | ||
this.localPath = requireNonNull(localPath, "localPath"); | ||
this.remoteScheme = requireNonNull(remoteScheme, "remoteScheme"); | ||
this.remoteUrl = requireNonNull(remoteUrl, "remoteUrl"); | ||
this.remotePath = requireNonNull(remotePath, "remotePath"); | ||
this.remoteBranch = requireNonNull(remoteBranch, "remoteBranch"); | ||
this.gitignore = gitignore; | ||
this.credentialId = requireNonNull(credentialId, "credentialId"); | ||
} | ||
|
||
@JsonProperty("id") | ||
public String id() { | ||
return id; | ||
} | ||
|
||
@JsonProperty("enabled") | ||
public boolean enabled() { | ||
return enabled; | ||
} | ||
|
||
@JsonProperty("projectName") | ||
public String projectName() { | ||
return projectName; | ||
} | ||
|
||
@JsonProperty("schedule") | ||
public String schedule() { | ||
return schedule; | ||
} | ||
|
||
@JsonProperty("direction") | ||
public String direction() { | ||
return direction; | ||
} | ||
|
||
@JsonProperty("localRepo") | ||
public String localRepo() { | ||
return localRepo; | ||
} | ||
|
||
@JsonProperty("localPath") | ||
public String localPath() { | ||
return localPath; | ||
} | ||
|
||
@JsonProperty("remoteScheme") | ||
public String remoteScheme() { | ||
return remoteScheme; | ||
} | ||
|
||
@JsonProperty("remoteUrl") | ||
public String remoteUrl() { | ||
return remoteUrl; | ||
} | ||
|
||
@JsonProperty("remotePath") | ||
public String remotePath() { | ||
return remotePath; | ||
} | ||
|
||
@JsonProperty("remoteBranch") | ||
public String remoteBranch() { | ||
return remoteBranch; | ||
} | ||
|
||
@Nullable | ||
@JsonProperty("gitignore") | ||
public String gitignore() { | ||
return gitignore; | ||
} | ||
|
||
@JsonProperty("credentialId") | ||
public String credentialId() { | ||
return credentialId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof MirrorDto)) { | ||
return false; | ||
} | ||
final MirrorDto mirrorDto = (MirrorDto) o; | ||
return id.equals(mirrorDto.id) && | ||
enabled == mirrorDto.enabled && | ||
projectName.equals(mirrorDto.projectName) && | ||
schedule.equals(mirrorDto.schedule) && | ||
direction.equals(mirrorDto.direction) && | ||
localRepo.equals(mirrorDto.localRepo) && | ||
localPath.equals(mirrorDto.localPath) && | ||
remoteScheme.equals(mirrorDto.remoteScheme) && | ||
remoteUrl.equals(mirrorDto.remoteUrl) && | ||
remotePath.equals(mirrorDto.remotePath) && | ||
remoteBranch.equals(mirrorDto.remoteBranch) && | ||
Objects.equals(gitignore, mirrorDto.gitignore) && | ||
credentialId.equals(mirrorDto.credentialId); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, projectName, schedule, direction, localRepo, localPath, remoteScheme, | ||
remoteUrl, remotePath, remoteBranch, gitignore, credentialId, enabled); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.omitNullValues() | ||
.add("id", id) | ||
.add("enabled", enabled) | ||
.add("projectName", projectName) | ||
.add("schedule", schedule) | ||
.add("direction", direction) | ||
.add("localRepo", localRepo) | ||
.add("localPath", localPath) | ||
.add("remoteScheme", remoteScheme) | ||
.add("remoteUrl", remoteUrl) | ||
.add("remotePath", remotePath) | ||
.add("gitignore", gitignore) | ||
.add("credentialId", credentialId) | ||
.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.