Skip to content
Merged
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 @@ -13,8 +13,11 @@
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.cluster.metadata.ProjectMetadata;
import org.elasticsearch.cluster.routing.RoutingTable;
import org.elasticsearch.common.settings.ProjectSecrets;
import org.elasticsearch.common.settings.SecureString;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -52,6 +55,11 @@ public ClusterBlocks blocks() {
return cluster().blocks();
}

public Optional<SecureString> getSecret(String key) {
return Optional.ofNullable(metadata().<ProjectSecrets>custom(ProjectSecrets.TYPE))
.map(secrets -> secrets.getSettings().getString(key));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see https://github.com/elastic/elasticsearch-serverless/pull/3676#discussion_r2018002701 is where this idea originated. Intuitively, since this method is a pure function of ProjectMetadata, I'd be inclined to have this method in ProjectMetadata instead of here. That would change Tim's example snippet to

Optional<SecureString> hash = projectState.metadata().getSecret(
	MULTI_PROJECT_PASSWORD_HASH.apply(principal).getConcreteSettingForNamespace(realmRef().getName())
);
return hash.orElse(null);

That would make more sense to me. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. The point of adding it is to make it a better interface that's easier for the caller to use, does the caller need to know that project secrets are stored in a custom in metadata or does the state abstraction make sense? I'm leaning towards keeping it, but I'm not 100% sure, I see your point of it being a pure function of ProjectMetadata too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main "pain" current callers see is the null-check - not obtaining the ProjectMetadata. We also don't have any precedent for adding utility methods like these on ProjectState. If we add this method here, we could add all sorts of methods like retrieving indices etc. - which I don't think we want to do. I'd also argue that in most places you'll have to get a reference to a ProjectMetadata first, because you'll want to retrieve things from there multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional context.

I think the main "pain" current callers see is the null-check - not obtaining the ProjectMetadata

Yes, I agree, but obtaining ProjectMetadata is also more painful than not doing it.

I'd also argue that in most places you'll have to get a reference to a ProjectMetadata first, because you'll want to retrieve things from there multiple times.

In the new realm, only the state is required and if you have the state, you can also get the ProjectMetadata from there.

we could add all sorts of methods like retrieving indices etc. - which I don't think we want to do.

I agree with this, but there is an ongoing discussion if the secrets and settings should really be part of metadata, since they're not persisted across restarts. If we don't put it in metadata, we have the option to change it later. Maybe that's not a strong enough argument though, we can always move it later anyway but it would be less code to change. I'll move it for now.

Thanks for the discussion!


@Override
public boolean equals(Object obj) {
if (obj == this) return true;
Expand Down