Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
import com.linecorp.centraldogma.server.internal.api.sysadmin.KeyManagementService;
import com.linecorp.centraldogma.server.internal.api.sysadmin.MirrorAccessControlService;
import com.linecorp.centraldogma.server.internal.api.sysadmin.ServerStatusService;
import com.linecorp.centraldogma.server.internal.api.variable.VariableServiceV1;
import com.linecorp.centraldogma.server.internal.api.template.SecretServiceV1;
import com.linecorp.centraldogma.server.internal.api.template.VariableServiceV1;
import com.linecorp.centraldogma.server.internal.mirror.DefaultMirrorAccessController;
import com.linecorp.centraldogma.server.internal.mirror.DefaultMirroringServicePlugin;
import com.linecorp.centraldogma.server.internal.mirror.MirrorAccessControl;
Expand Down Expand Up @@ -1008,7 +1009,8 @@ private void configureHttpApi(ServerBuilder sb,
.annotatedService(new ProjectServiceV1(projectApiManager, executor))
.annotatedService(new RepositoryServiceV1(executor, mds, encryptionStorageManager))
.annotatedService(new CredentialServiceV1(projectApiManager, executor))
.annotatedService(new VariableServiceV1(pm, executor));
.annotatedService(new VariableServiceV1(pm, executor))
.annotatedService(new SecretServiceV1(pm, executor));
if (LOGBACK_ENABLED) {
apiV1ServiceBuilder.annotatedService(new LoggerService());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
import com.linecorp.centraldogma.server.internal.api.converter.TemplateParamsConverter;
import com.linecorp.centraldogma.server.internal.api.converter.WatchRequestConverter;
import com.linecorp.centraldogma.server.internal.api.converter.WatchRequestConverter.WatchRequest;
import com.linecorp.centraldogma.server.internal.api.variable.Templater;
import com.linecorp.centraldogma.server.internal.api.template.Templater;
import com.linecorp.centraldogma.server.metadata.User;
import com.linecorp.centraldogma.server.storage.project.Project;
import com.linecorp.centraldogma.server.storage.project.ProjectManager;
import com.linecorp.centraldogma.server.storage.repository.EntryTransformer;
Expand Down Expand Up @@ -129,22 +130,23 @@ public ContentServiceV1(CommandExecutor executor, ProjectManager pm, WatchServic
public CompletableFuture<List<EntryDto<?>>> listFiles(ServiceRequestContext ctx,
@Param String path,
@Param @Default("-1") String revision,
Repository repository) {
Repository repository, User user) {
final String normalizedPath = normalizePath(path);
final Revision normalizedRev = repository.normalizeNow(new Revision(revision));
increaseCounterIfOldRevisionUsed(ctx, repository, normalizedRev);
final CompletableFuture<List<EntryDto<?>>> future = new CompletableFuture<>();
findFiles(repository, normalizedPath, normalizedRev, false, false, TemplateParams.disabled(), future);
findFiles(repository, normalizedPath, normalizedRev, false, false, TemplateParams.disabled(), future,
user);
return future;
}

private void findFiles(Repository repository, String pathPattern, Revision normalizedRev,
boolean withContent, boolean viewRaw, TemplateParams templateParams,
CompletableFuture<List<EntryDto<?>>> result) {
CompletableFuture<List<EntryDto<?>>> result, User user) {
final Map<FindOption<?>, ?> options = withContent ? FindOptions.FIND_ALL_WITH_CONTENT
: FindOptions.FIND_ALL_WITHOUT_CONTENT;

final EntryTransformer<Object> transformer = newTemplater(repository, templateParams);
final EntryTransformer<Object> transformer = newTemplater(repository, templateParams, user);
repository.find(normalizedRev, pathPattern, options, transformer).handle((entries, thrown) -> {
if (thrown != null) {
result.completeExceptionally(thrown);
Expand All @@ -157,7 +159,7 @@ private void findFiles(Repository repository, String pathPattern, Revision norma
if (isValidFilePath(pathPattern) && entries.size() == 1 &&
entries.values().iterator().next().type() == DIRECTORY) {
findFiles(repository, pathPattern + "/*", normalizedRev, withContent, viewRaw,
templateParams, result);
templateParams, result, user);
} else {
result.complete(entries.values().stream()
.map(entry -> newEntryDto(repository, normalizedRev, entry, withContent,
Expand Down Expand Up @@ -258,7 +260,7 @@ public CompletableFuture<Iterable<ChangeDto<?>>> preview(
* jsonpath={jsonpath}
*
* <p>Returns the entry of files in the path. This is same with
* {@link #listFiles(ServiceRequestContext, String, String, Repository)} except that containing
* {@link #listFiles(ServiceRequestContext, String, String, Repository, User)} except that containing
* the content of the files.
* Note that if the {@link HttpHeaderNames#IF_NONE_MATCH} in which has a revision is sent with,
* this will await for the time specified in {@link HttpHeaderNames#PREFER}.
Expand All @@ -274,7 +276,7 @@ public CompletableFuture<?> getFiles(
@RequestConverter(TemplateParamsConverter.class) TemplateParams templateParams,
Repository repository,
@RequestConverter(WatchRequestConverter.class) @Nullable WatchRequest watchRequest,
@RequestConverter(QueryRequestConverter.class) @Nullable Query<?> query) {
@RequestConverter(QueryRequestConverter.class) @Nullable Query<?> query, User user) {
increaseCounterIfOldRevisionUsed(ctx, repository, new Revision(revision));
final String normalizedPath = normalizePath(path);

Expand All @@ -286,7 +288,7 @@ public CompletableFuture<?> getFiles(
final boolean errorOnEntryNotFound = watchRequest.notifyEntryNotFound();
if (query != null) {
return watchFile(ctx, repository, lastKnownRevision, query, timeOutMillis,
errorOnEntryNotFound, viewRaw, templateParams);
errorOnEntryNotFound, viewRaw, templateParams, user);
}

return watchRepository(ctx, repository, lastKnownRevision, normalizedPath,
Expand All @@ -296,24 +298,24 @@ public CompletableFuture<?> getFiles(
final Revision normalizedRev = repository.normalizeNow(new Revision(revision));
if (query != null) {
// get a file
return repository.get(normalizedRev, query, newTemplater(repository, templateParams))
return repository.get(normalizedRev, query, newTemplater(repository, templateParams, user))
.thenApply(result -> newEntryDto(repository, normalizedRev,
result, true, viewRaw));
}
// get files

final CompletableFuture<List<EntryDto<?>>> future = new CompletableFuture<>();
findFiles(repository, normalizedPath, normalizedRev, true, viewRaw, templateParams, future);
findFiles(repository, normalizedPath, normalizedRev, true, viewRaw, templateParams, future, user);
return future;
}

private CompletableFuture<?> watchFile(ServiceRequestContext ctx,
Repository repository, Revision lastKnownRevision,
Query<?> query, long timeOutMillis, boolean errorOnEntryNotFound,
boolean viewRaw, TemplateParams templateParams) {
boolean viewRaw, TemplateParams templateParams, User user) {
final CompletableFuture<? extends Entry<?>> future = watchService.watchFile(
repository, lastKnownRevision, query, timeOutMillis, errorOnEntryNotFound, templateParams,
newTempRev -> newTemplater(repository, templateParams.withTemplateRevision(newTempRev)));
newTempRev -> newTemplater(repository, templateParams.withTemplateRevision(newTempRev), user));

if (!future.isDone()) {
ctx.log().whenComplete().thenRun(() -> future.cancel(false));
Expand All @@ -326,12 +328,14 @@ private CompletableFuture<?> watchFile(ServiceRequestContext ctx,
}).exceptionally(ContentServiceV1::handleWatchFailure);
}

private <T> EntryTransformer<T> newTemplater(Repository repository, TemplateParams templateParams) {
private <T> EntryTransformer<T> newTemplater(Repository repository, TemplateParams templateParams,
User user) {
if (!templateParams.renderTemplate()) {
return EntryTransformer.identity();
} else {
return entry -> templater.render(repository, entry,
templateParams.variableFile(), templateParams.templateRevision());
templateParams.variableFile(), templateParams.templateRevision(),
user);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright 2025 LY Corporation
*
* LY 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.server.internal.api.template;

import static java.util.Objects.requireNonNull;

import java.util.Objects;

import org.jspecify.annotations.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;

import com.linecorp.centraldogma.server.metadata.UserAndTimestamp;

@JsonInclude(Include.NON_NULL)
public final class Secret {

private final String id;
private final String value;
@Nullable
private final String description;

@Nullable
private String name;
@Nullable
private UserAndTimestamp creation;

public Secret(String id, String value, @Nullable String description) {
this.id = requireNonNull(id, "id");
this.value = requireNonNull(value, "value");
this.description = description;
}

@JsonCreator
public Secret(@JsonProperty("id") String id,
@JsonProperty("name") @Nullable String name,
@JsonProperty("value") String value,
@JsonProperty("creation") @Nullable UserAndTimestamp creation,
@JsonProperty("description") @Nullable String description) {
this.id = requireNonNull(id, "id");
this.name = name;
this.value = requireNonNull(value, "value");
this.description = description;
this.creation = creation;
}

@JsonProperty("id")
public String id() {
return id;
}

@Nullable
@JsonProperty("name")
public String name() {
return name;
}

void setName(String name) {
this.name = name;
}

@JsonProperty("value")
public String value() {
return value;
}

@Nullable
@JsonProperty("description")
public String description() {
return description;
}

@Nullable
@JsonProperty("creation")
public UserAndTimestamp creation() {
return creation;
}

void setCreation(UserAndTimestamp creation) {
this.creation = creation;
}

public Secret withoutValue() {
return new Secret(id, name, "****", creation, description);
}

@Override
public boolean equals(Object o) {
if (!(o instanceof Secret)) {
return false;
}

final Secret variable = (Secret) o;
return id.equals(variable.id) &&
Objects.equals(name, variable.name) &&
value.equals(variable.value) &&
Objects.equals(description, variable.description) &&
Objects.equals(creation, variable.creation);
}

@Override
public int hashCode() {
return Objects.hash(id, name, value, description, creation);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("id", id)
.add("name", name)
.add("value", "****")
.add("description", description)
.add("creation", creation)
.toString();
}
}
Loading
Loading