co.elastic.clients.elasticsearch.security.RoleDescriptor Maven / Gradle / Ivy
Show all versions of elasticsearch-java Show documentation
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. 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
*
* http://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 co.elastic.clients.elasticsearch.security;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.JsonpUtils;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.String;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
//----------------------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------------------
//
// This code is generated from the Elasticsearch API specification
// at https://github.com/elastic/elasticsearch-specification
//
// Manual updates to this file will be lost when the code is
// re-generated.
//
// If you find a property that is missing or wrongly typed, please
// open an issue or a PR on the API specification repository.
//
//----------------------------------------------------------------
// typedef: security._types.RoleDescriptor
/**
*
* @see API
* specification
*/
@JsonpDeserializable
public class RoleDescriptor implements JsonpSerializable {
private final List cluster;
private final List indices;
private final List global;
private final List applications;
private final Map metadata;
private final List runAs;
@Nullable
private final String description;
private final Map transientMetadata;
// ---------------------------------------------------------------------------------------------
protected RoleDescriptor(AbstractBuilder> builder) {
this.cluster = ApiTypeHelper.unmodifiable(builder.cluster);
this.indices = ApiTypeHelper.unmodifiable(builder.indices);
this.global = ApiTypeHelper.unmodifiable(builder.global);
this.applications = ApiTypeHelper.unmodifiable(builder.applications);
this.metadata = ApiTypeHelper.unmodifiable(builder.metadata);
this.runAs = ApiTypeHelper.unmodifiable(builder.runAs);
this.description = builder.description;
this.transientMetadata = ApiTypeHelper.unmodifiable(builder.transientMetadata);
}
public static RoleDescriptor roleDescriptorOf(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* A list of cluster privileges. These privileges define the cluster level
* actions that API keys are able to execute.
*
* API name: {@code cluster}
*/
public final List cluster() {
return this.cluster;
}
/**
* A list of indices permissions entries.
*
* API name: {@code indices}
*/
public final List indices() {
return this.indices;
}
/**
* An object defining global privileges. A global privilege is a form of cluster
* privilege that is request-aware. Support for global privileges is currently
* limited to the management of application privileges.
*
* API name: {@code global}
*/
public final List global() {
return this.global;
}
/**
* A list of application privilege entries
*
* API name: {@code applications}
*/
public final List applications() {
return this.applications;
}
/**
* Optional meta-data. Within the metadata object, keys that begin with
* _
are reserved for system usage.
*
* API name: {@code metadata}
*/
public final Map metadata() {
return this.metadata;
}
/**
* A list of users that the API keys can impersonate. Note: in
* Serverless, the run-as feature is disabled. For API compatibility, you can
* still specify an empty run_as
field, but a non-empty list will
* be rejected.
*
* API name: {@code run_as}
*/
public final List runAs() {
return this.runAs;
}
/**
* Optional description of the role descriptor
*
* API name: {@code description}
*/
@Nullable
public final String description() {
return this.description;
}
/**
* API name: {@code transient_metadata}
*/
public final Map transientMetadata() {
return this.transientMetadata;
}
/**
* Serialize this object to JSON.
*/
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
serializeInternal(generator, mapper);
generator.writeEnd();
}
protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
if (ApiTypeHelper.isDefined(this.cluster)) {
generator.writeKey("cluster");
generator.writeStartArray();
for (String item0 : this.cluster) {
generator.write(item0);
}
generator.writeEnd();
}
if (ApiTypeHelper.isDefined(this.indices)) {
generator.writeKey("indices");
generator.writeStartArray();
for (IndicesPrivileges item0 : this.indices) {
item0.serialize(generator, mapper);
}
generator.writeEnd();
}
if (ApiTypeHelper.isDefined(this.global)) {
generator.writeKey("global");
generator.writeStartArray();
for (GlobalPrivilege item0 : this.global) {
item0.serialize(generator, mapper);
}
generator.writeEnd();
}
if (ApiTypeHelper.isDefined(this.applications)) {
generator.writeKey("applications");
generator.writeStartArray();
for (ApplicationPrivileges item0 : this.applications) {
item0.serialize(generator, mapper);
}
generator.writeEnd();
}
if (ApiTypeHelper.isDefined(this.metadata)) {
generator.writeKey("metadata");
generator.writeStartObject();
for (Map.Entry item0 : this.metadata.entrySet()) {
generator.writeKey(item0.getKey());
item0.getValue().serialize(generator, mapper);
}
generator.writeEnd();
}
if (ApiTypeHelper.isDefined(this.runAs)) {
generator.writeKey("run_as");
generator.writeStartArray();
for (String item0 : this.runAs) {
generator.write(item0);
}
generator.writeEnd();
}
if (this.description != null) {
generator.writeKey("description");
generator.write(this.description);
}
if (ApiTypeHelper.isDefined(this.transientMetadata)) {
generator.writeKey("transient_metadata");
generator.writeStartObject();
for (Map.Entry item0 : this.transientMetadata.entrySet()) {
generator.writeKey(item0.getKey());
item0.getValue().serialize(generator, mapper);
}
generator.writeEnd();
}
}
@Override
public String toString() {
return JsonpUtils.toString(this);
}
// ---------------------------------------------------------------------------------------------
/**
* Builder for {@link RoleDescriptor}.
*/
public static class Builder extends RoleDescriptor.AbstractBuilder
implements
ObjectBuilder {
@Override
protected Builder self() {
return this;
}
/**
* Builds a {@link RoleDescriptor}.
*
* @throws NullPointerException
* if some of the required fields are null.
*/
public RoleDescriptor build() {
_checkSingleUse();
return new RoleDescriptor(this);
}
}
public abstract static class AbstractBuilder>
extends
WithJsonObjectBuilderBase {
@Nullable
private List cluster;
@Nullable
private List indices;
@Nullable
private List global;
@Nullable
private List applications;
@Nullable
private Map metadata;
@Nullable
private List runAs;
@Nullable
private String description;
@Nullable
private Map transientMetadata;
/**
* A list of cluster privileges. These privileges define the cluster level
* actions that API keys are able to execute.
*
* API name: {@code cluster}
*
* Adds all elements of list
to cluster
.
*/
public final BuilderT cluster(List list) {
this.cluster = _listAddAll(this.cluster, list);
return self();
}
/**
* A list of cluster privileges. These privileges define the cluster level
* actions that API keys are able to execute.
*
* API name: {@code cluster}
*
* Adds one or more values to cluster
.
*/
public final BuilderT cluster(String value, String... values) {
this.cluster = _listAdd(this.cluster, value, values);
return self();
}
/**
* A list of indices permissions entries.
*
* API name: {@code indices}
*
* Adds all elements of list
to indices
.
*/
public final BuilderT indices(List list) {
this.indices = _listAddAll(this.indices, list);
return self();
}
/**
* A list of indices permissions entries.
*
* API name: {@code indices}
*
* Adds one or more values to indices
.
*/
public final BuilderT indices(IndicesPrivileges value, IndicesPrivileges... values) {
this.indices = _listAdd(this.indices, value, values);
return self();
}
/**
* A list of indices permissions entries.
*
* API name: {@code indices}
*
* Adds a value to indices
using a builder lambda.
*/
public final BuilderT indices(Function> fn) {
return indices(fn.apply(new IndicesPrivileges.Builder()).build());
}
/**
* An object defining global privileges. A global privilege is a form of cluster
* privilege that is request-aware. Support for global privileges is currently
* limited to the management of application privileges.
*
* API name: {@code global}
*
* Adds all elements of list
to global
.
*/
public final BuilderT global(List list) {
this.global = _listAddAll(this.global, list);
return self();
}
/**
* An object defining global privileges. A global privilege is a form of cluster
* privilege that is request-aware. Support for global privileges is currently
* limited to the management of application privileges.
*
* API name: {@code global}
*
* Adds one or more values to global
.
*/
public final BuilderT global(GlobalPrivilege value, GlobalPrivilege... values) {
this.global = _listAdd(this.global, value, values);
return self();
}
/**
* An object defining global privileges. A global privilege is a form of cluster
* privilege that is request-aware. Support for global privileges is currently
* limited to the management of application privileges.
*
* API name: {@code global}
*
* Adds a value to global
using a builder lambda.
*/
public final BuilderT global(Function> fn) {
return global(fn.apply(new GlobalPrivilege.Builder()).build());
}
/**
* A list of application privilege entries
*
* API name: {@code applications}
*
* Adds all elements of list
to applications
.
*/
public final BuilderT applications(List list) {
this.applications = _listAddAll(this.applications, list);
return self();
}
/**
* A list of application privilege entries
*
* API name: {@code applications}
*
* Adds one or more values to applications
.
*/
public final BuilderT applications(ApplicationPrivileges value, ApplicationPrivileges... values) {
this.applications = _listAdd(this.applications, value, values);
return self();
}
/**
* A list of application privilege entries
*
* API name: {@code applications}
*
* Adds a value to applications
using a builder lambda.
*/
public final BuilderT applications(
Function> fn) {
return applications(fn.apply(new ApplicationPrivileges.Builder()).build());
}
/**
* Optional meta-data. Within the metadata object, keys that begin with
* _
are reserved for system usage.
*
* API name: {@code metadata}
*
* Adds all entries of map
to metadata
.
*/
public final BuilderT metadata(Map map) {
this.metadata = _mapPutAll(this.metadata, map);
return self();
}
/**
* Optional meta-data. Within the metadata object, keys that begin with
* _
are reserved for system usage.
*
* API name: {@code metadata}
*
* Adds an entry to metadata
.
*/
public final BuilderT metadata(String key, JsonData value) {
this.metadata = _mapPut(this.metadata, key, value);
return self();
}
/**
* A list of users that the API keys can impersonate. Note: in
* Serverless, the run-as feature is disabled. For API compatibility, you can
* still specify an empty run_as
field, but a non-empty list will
* be rejected.
*
* API name: {@code run_as}
*
* Adds all elements of list
to runAs
.
*/
public final BuilderT runAs(List list) {
this.runAs = _listAddAll(this.runAs, list);
return self();
}
/**
* A list of users that the API keys can impersonate. Note: in
* Serverless, the run-as feature is disabled. For API compatibility, you can
* still specify an empty run_as
field, but a non-empty list will
* be rejected.
*
* API name: {@code run_as}
*
* Adds one or more values to runAs
.
*/
public final BuilderT runAs(String value, String... values) {
this.runAs = _listAdd(this.runAs, value, values);
return self();
}
/**
* Optional description of the role descriptor
*
* API name: {@code description}
*/
public final BuilderT description(@Nullable String value) {
this.description = value;
return self();
}
/**
* API name: {@code transient_metadata}
*
* Adds all entries of map
to transientMetadata
.
*/
public final BuilderT transientMetadata(Map map) {
this.transientMetadata = _mapPutAll(this.transientMetadata, map);
return self();
}
/**
* API name: {@code transient_metadata}
*
* Adds an entry to transientMetadata
.
*/
public final BuilderT transientMetadata(String key, JsonData value) {
this.transientMetadata = _mapPut(this.transientMetadata, key, value);
return self();
}
protected abstract BuilderT self();
}
// ---------------------------------------------------------------------------------------------
/**
* Json deserializer for {@link RoleDescriptor}
*/
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
RoleDescriptor::setupRoleDescriptorDeserializer);
protected static > void setupRoleDescriptorDeserializer(
ObjectDeserializer op) {
op.add(AbstractBuilder::cluster, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()),
"cluster");
op.add(AbstractBuilder::indices, JsonpDeserializer.arrayDeserializer(IndicesPrivileges._DESERIALIZER),
"indices", "index");
op.add(AbstractBuilder::global, JsonpDeserializer.arrayDeserializer(GlobalPrivilege._DESERIALIZER), "global");
op.add(AbstractBuilder::applications, JsonpDeserializer.arrayDeserializer(ApplicationPrivileges._DESERIALIZER),
"applications");
op.add(AbstractBuilder::metadata, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "metadata");
op.add(AbstractBuilder::runAs, JsonpDeserializer.arrayDeserializer(JsonpDeserializer.stringDeserializer()),
"run_as");
op.add(AbstractBuilder::description, JsonpDeserializer.stringDeserializer(), "description");
op.add(AbstractBuilder::transientMetadata, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER),
"transient_metadata");
}
}