Skip to content

Commit

Permalink
Address comments from @ikhoon
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Jan 7, 2025
1 parent bc26c96 commit ec709b7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ public CredentialServiceV1(ProjectApiManager projectApiManager, CommandExecutor
@Get("/projects/{projectName}/credentials")
public CompletableFuture<List<Credential>> listCredentials(User loginUser,
@Param String projectName) {
final CompletableFuture<List<Credential>> future = metaRepo(projectName, loginUser).credentials();
return credentials(loginUser, future);
final CompletableFuture<List<Credential>> future =
metaRepo(projectName, loginUser).projectCredentials();
return maybeMaskSecret(loginUser, future);
}

private static CompletableFuture<List<Credential>> credentials(User loginUser,
CompletableFuture<List<Credential>> future) {
private static CompletableFuture<List<Credential>> maybeMaskSecret(
User loginUser,
CompletableFuture<List<Credential>> future) {
if (loginUser.isSystemAdmin()) {
return future;
}
return future.thenApply(credentials -> {
return credentials
.stream()
.map(Credential::withoutSecret)
.collect(toImmutableList());
});
return future.thenApply(credentials -> credentials
.stream()
.map(Credential::withoutSecret)
.collect(toImmutableList()));
}

/**
Expand All @@ -96,7 +96,7 @@ private static CompletableFuture<List<Credential>> credentials(User loginUser,
@Get("/projects/{projectName}/credentials/{id}")
public CompletableFuture<Credential> getCredentialById(User loginUser,
@Param String projectName, @Param String id) {
final CompletableFuture<Credential> future = metaRepo(projectName, loginUser).credential(id);
final CompletableFuture<Credential> future = metaRepo(projectName, loginUser).projectCredential(id);
if (loginUser.isSystemAdmin()) {
return future;
}
Expand Down Expand Up @@ -141,7 +141,7 @@ public CompletableFuture<PushResultDto> updateCredential(@Param String projectNa
public CompletableFuture<Void> deleteCredential(@Param String projectName,
@Param String id, Author author, User user) {
final MetaRepository metaRepository = metaRepo(projectName, user);
return metaRepository.credential(id).thenCompose(credential -> {
return metaRepository.projectCredential(id).thenCompose(credential -> {
// credential exists.
final Command<CommitResult> command =
Command.push(author, projectName, metaRepository.name(),
Expand Down Expand Up @@ -182,8 +182,8 @@ public CompletableFuture<List<Credential>> listRepoCredentials(User loginUser,
@Param String projectName,
Repository repository) {
final CompletableFuture<List<Credential>> future =
metaRepo(projectName, loginUser).credentials(repository.name());
return credentials(loginUser, future);
metaRepo(projectName, loginUser).repoCredentials(repository.name());
return maybeMaskSecret(loginUser, future);
}

/**
Expand All @@ -198,7 +198,7 @@ public CompletableFuture<Credential> getRepoCredentialById(User loginUser,
Repository repository,
@Param String id) {
final CompletableFuture<Credential> future =
metaRepo(projectName, loginUser).credential(repository.name(), id);
metaRepo(projectName, loginUser).repoCredential(repository.name(), id);
if (loginUser.isSystemAdmin()) {
return future;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ public CompletableFuture<Void> deleteRepoCredential(@Param String projectName,
Repository repository,
@Param String id, Author author, User user) {
final MetaRepository metaRepository = metaRepo(projectName, user);
return metaRepository.credential(repository.name(), id).thenCompose(credential -> {
return metaRepository.repoCredential(repository.name(), id).thenCompose(credential -> {
// credential exists.
final Command<CommitResult> command =
Command.push(author, projectName, metaRepository.name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class DefaultMetaRepository extends RepositoryWrapper implements Me

private static final String PATH_CREDENTIALS = "/credentials/";

public static final String PATH_MIRRORS = "/mirrors/";
private static final String PATH_MIRRORS = "/mirrors/";

public static boolean isMetaFile(String path) {
return "/mirrors.json".equals(path) || "/credentials.json".equals(path) ||
Expand Down Expand Up @@ -126,9 +126,9 @@ public CompletableFuture<Mirror> mirror(String id) {

final CompletableFuture<List<Credential>> credentials;
if (Strings.isNullOrEmpty(c.credentialId())) {
credentials = credentials();
credentials = projectCredentials();
} else {
credentials = credential(c.credentialId()).thenApply(ImmutableList::of);
credentials = projectCredential(c.credentialId()).thenApply(ImmutableList::of);
}
return credentials.thenApply(credentials0 -> {
final Mirror mirror = c.toMirror(parent(), credentials0);
Expand All @@ -147,7 +147,7 @@ private CompletableFuture<List<Mirror>> allMirrors() {
return UnmodifiableFuture.completedFuture(ImmutableList.of());
}

return credentials().thenApply(credentials -> {
return projectCredentials().thenApply(credentials -> {
try {
return parseMirrors(entries, credentials);
} catch (JsonProcessingException e) {
Expand Down Expand Up @@ -178,12 +178,12 @@ private List<Mirror> parseMirrors(Map<String, Entry<?>> entries, List<Credential
}

@Override
public CompletableFuture<List<Credential>> credentials() {
public CompletableFuture<List<Credential>> projectCredentials() {
return find(PATH_CREDENTIALS + "*.json").thenApply(entries -> credentials(entries, null));
}

@Override
public CompletableFuture<List<Credential>> credentials(String repoName) {
public CompletableFuture<List<Credential>> repoCredentials(String repoName) {
return find("/repos/" + repoName + PATH_CREDENTIALS + "*.json").thenApply(
entries -> credentials(entries, repoName));
}
Expand All @@ -204,13 +204,13 @@ private List<Credential> credentials(Map<String, Entry<?>> entries, @Nullable St
}

@Override
public CompletableFuture<Credential> credential(String credentialId) {
public CompletableFuture<Credential> projectCredential(String credentialId) {
final String credentialFile = credentialFile(credentialId);
return credential0(credentialFile);
}

@Override
public CompletableFuture<Credential> credential(String repoName, String id) {
public CompletableFuture<Credential> repoCredential(String repoName, String id) {
final String credentialFile = credentialFile(repoName, id);
return credential0(credentialFile);
}
Expand Down Expand Up @@ -297,7 +297,7 @@ public CompletableFuture<Command<CommitResult>> createCredentialPushCommand(Cred
checkArgument(!credential.id().isEmpty(), "Credential ID should not be empty");

if (update) {
return credential(credential.id()).thenApply(c -> {
return projectCredential(credential.id()).thenApply(c -> {
final String summary = "Update the mirror credential '" + credential.id() + '\'';
return newCredentialCommand(credentialFile(credential.id()), credential, author, summary);
});
Expand All @@ -314,7 +314,7 @@ public CompletableFuture<Command<CommitResult>> createCredentialPushCommand(Stri
checkArgument(!credential.id().isEmpty(), "Credential ID should not be empty");

if (update) {
return credential(repoName, credential.id()).thenApply(c -> {
return repoCredential(repoName, credential.id()).thenApply(c -> {
final String summary =
"Update the mirror credential '" + repoName + '/' + credential.id() + '\'';
return newCredentialCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ default CompletableFuture<List<Mirror>> mirrors() {
/**
* Returns a list of project credentials.
*/
CompletableFuture<List<Credential>> credentials();
CompletableFuture<List<Credential>> projectCredentials();

/**
* Returns a list of credentials of the specified repository.
* Returns a project credential of the specified {@code id}.
*/
CompletableFuture<List<Credential>> credentials(String repoName);
CompletableFuture<Credential> projectCredential(String id);

/**
* Returns a project credential of the specified {@code id}.
* Returns a list of credentials of the specified repository.
*/
CompletableFuture<Credential> credential(String id);
CompletableFuture<List<Credential>> repoCredentials(String repoName);

/**
* Returns a credential of the specified {@code id} in the specified repository.
*/
CompletableFuture<Credential> credential(String repoName, String id);
CompletableFuture<Credential> repoCredential(String repoName, String id);

/**
* Create a push {@link Command} for the {@link MirrorDto}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private static CompletableFuture<Config> toConfig(Kubeconfig kubeconfig, MetaRep
return CompletableFuture.completedFuture(configBuilder.build());
}

return metaRepository.credential(credentialId)
return metaRepository.projectCredential(credentialId)
.thenApply(credential -> {
if (!(credential instanceof AccessTokenCredential)) {
throw new IllegalArgumentException(
Expand Down

0 comments on commit ec709b7

Please sign in to comment.