-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature activation for multi-tenancy #2568
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
58 changes: 58 additions & 0 deletions
58
src/main/java/org/opensearch/security/action/tenancy/BooleanSettingRetrieveResponse.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,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.action.tenancy; | ||
|
||
import java.io.IOException; | ||
|
||
import org.opensearch.action.ActionResponse; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.common.io.stream.StreamOutput; | ||
import org.opensearch.common.xcontent.XContentType; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
public class BooleanSettingRetrieveResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private Boolean value; | ||
|
||
public BooleanSettingRetrieveResponse(final StreamInput in) throws IOException { | ||
super(in); | ||
this.value = in.readBoolean(); | ||
} | ||
|
||
public BooleanSettingRetrieveResponse(final Boolean value) { | ||
this.value = value; | ||
} | ||
|
||
public Boolean getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public void writeTo(final StreamOutput out) throws IOException { | ||
out.writeBoolean(getValue()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Strings.toString(XContentType.JSON, this, true, true); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field("value", getValue()); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/org/opensearch/security/action/tenancy/BooleanSettingUpdateRequest.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,63 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.action.tenancy; | ||
|
||
import java.io.IOException; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
import org.opensearch.core.ParseField; | ||
import org.opensearch.core.xcontent.ConstructingObjectParser; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
|
||
public class BooleanSettingUpdateRequest extends ActionRequest { | ||
|
||
private Boolean value; | ||
|
||
public BooleanSettingUpdateRequest(final StreamInput in) throws IOException { | ||
super(in); | ||
in.readBoolean(); | ||
} | ||
|
||
public BooleanSettingUpdateRequest(final Boolean value) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
public Boolean getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (getValue() == null) { | ||
final ActionRequestValidationException validationException = new ActionRequestValidationException(); | ||
validationException.addValidationError("Missing boolean value"); | ||
return validationException; | ||
} | ||
return null; | ||
} | ||
|
||
private static final ConstructingObjectParser<BooleanSettingUpdateRequest, Void> PARSER = new ConstructingObjectParser<>( | ||
BooleanSettingUpdateRequest.class.getName(), | ||
args -> new BooleanSettingUpdateRequest((Boolean) args[0]) | ||
); | ||
|
||
static { | ||
PARSER.declareBoolean(ConstructingObjectParser.constructorArg(), new ParseField("value")); | ||
} | ||
|
||
public static BooleanSettingUpdateRequest fromXContent(final XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/opensearch/security/action/tenancy/EmptyRequest.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,34 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.action.tenancy; | ||
|
||
import java.io.IOException; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.common.io.stream.StreamInput; | ||
|
||
public class EmptyRequest extends ActionRequest { | ||
|
||
public EmptyRequest(final StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public EmptyRequest() throws IOException { | ||
super(); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/opensearch/security/action/tenancy/MultiTenancyRetrieveAction.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,24 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.action.tenancy; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class MultiTenancyRetrieveAction extends ActionType<BooleanSettingRetrieveResponse> { | ||
|
||
public static final MultiTenancyRetrieveAction INSTANCE = new MultiTenancyRetrieveAction(); | ||
public static final String NAME = "cluster:feature/tenancy/multitenancy_enabled/read"; | ||
|
||
protected MultiTenancyRetrieveAction() { | ||
super(NAME, BooleanSettingRetrieveResponse::new); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...main/java/org/opensearch/security/action/tenancy/MultiTenancyRetrieveTransportAction.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,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.action.tenancy; | ||
|
||
import java.util.Collections; | ||
|
||
import org.opensearch.action.ActionListener; | ||
import org.opensearch.action.support.ActionFilters; | ||
import org.opensearch.action.support.HandledTransportAction; | ||
import org.opensearch.common.inject.Inject; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.security.configuration.ConfigurationRepository; | ||
import org.opensearch.security.securityconf.impl.CType; | ||
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration; | ||
import org.opensearch.security.securityconf.impl.v7.ConfigV7; | ||
import org.opensearch.tasks.Task; | ||
import org.opensearch.transport.TransportService; | ||
|
||
public class MultiTenancyRetrieveTransportAction | ||
extends HandledTransportAction<EmptyRequest, BooleanSettingRetrieveResponse> { | ||
|
||
private final ConfigurationRepository config; | ||
|
||
@Inject | ||
public MultiTenancyRetrieveTransportAction(final Settings settings, | ||
final TransportService transportService, | ||
final ActionFilters actionFilters, | ||
final ConfigurationRepository config) { | ||
super(MultiTenancyRetrieveAction.NAME, transportService, actionFilters, EmptyRequest::new); | ||
|
||
this.config = config; | ||
} | ||
|
||
/** Load the configuration from the security index and return a copy */ | ||
protected final SecurityDynamicConfiguration<?> load() { | ||
return config.getConfigurationsFromIndex(Collections.singleton(CType.CONFIG), false).get(CType.CONFIG).deepClone(); | ||
} | ||
|
||
@Override | ||
protected void doExecute(final Task task, final EmptyRequest request, final ActionListener<BooleanSettingRetrieveResponse> listener) { | ||
// Get the security configuration and lookup the config setting state | ||
final SecurityDynamicConfiguration<?> dynamicConfig = load(); | ||
ConfigV7 config = (ConfigV7)dynamicConfig.getCEntry("config"); | ||
final Boolean value = config.dynamic.kibana.multitenancy_enabled; | ||
peternied marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
listener.onResponse(new BooleanSettingRetrieveResponse(value)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/org/opensearch/security/action/tenancy/MultiTenancyUpdateAction.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,24 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.action.tenancy; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class MultiTenancyUpdateAction extends ActionType<BooleanSettingRetrieveResponse> { | ||
|
||
public static final MultiTenancyUpdateAction INSTANCE = new MultiTenancyUpdateAction(); | ||
public static final String NAME = "cluster:feature/tenancy/multitenancy_enabled/update"; | ||
|
||
protected MultiTenancyUpdateAction() { | ||
super(NAME, BooleanSettingRetrieveResponse::new); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are additional actions that reuse this pattern
{ "value": {VALUE} }
these names might need to be made more generic and moved outside of the tenancy package. The same is true for the Request types as well.