All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.security.keyvault.keys.implementation.models.KeyBundle Maven / Gradle / Ivy

There is a newer version: 4.9.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.security.keyvault.keys.implementation.models;

import com.azure.core.annotation.Fluent;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.Map;

/** A KeyBundle consisting of a WebKey plus its attributes. */
@Fluent
public class KeyBundle implements JsonSerializable {
    /*
     * The Json web key.
     */
    private JsonWebKey key;

    /*
     * The key management attributes.
     */
    private KeyAttributes attributes;

    /*
     * Application specific metadata in the form of key-value pairs.
     */
    private Map tags;

    /*
     * True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will be
     * true.
     */
    private Boolean managed;

    /*
     * The policy rules under which the key can be exported.
     */
    private KeyReleasePolicy releasePolicy;

    /** Creates an instance of KeyBundle class. */
    public KeyBundle() {}

    /**
     * Get the key property: The Json web key.
     *
     * @return the key value.
     */
    public JsonWebKey getKey() {
        return this.key;
    }

    /**
     * Set the key property: The Json web key.
     *
     * @param key the key value to set.
     * @return the KeyBundle object itself.
     */
    public KeyBundle setKey(JsonWebKey key) {
        this.key = key;
        return this;
    }

    /**
     * Get the attributes property: The key management attributes.
     *
     * @return the attributes value.
     */
    public KeyAttributes getAttributes() {
        return this.attributes;
    }

    /**
     * Set the attributes property: The key management attributes.
     *
     * @param attributes the attributes value to set.
     * @return the KeyBundle object itself.
     */
    public KeyBundle setAttributes(KeyAttributes attributes) {
        this.attributes = attributes;
        return this;
    }

    /**
     * Get the tags property: Application specific metadata in the form of key-value pairs.
     *
     * @return the tags value.
     */
    public Map getTags() {
        return this.tags;
    }

    /**
     * Set the tags property: Application specific metadata in the form of key-value pairs.
     *
     * @param tags the tags value to set.
     * @return the KeyBundle object itself.
     */
    public KeyBundle setTags(Map tags) {
        this.tags = tags;
        return this;
    }

    /**
     * Get the managed property: True if the key's lifetime is managed by key vault. If this is a key backing a
     * certificate, then managed will be true.
     *
     * @return the managed value.
     */
    public Boolean isManaged() {
        return this.managed;
    }

    /**
     * Set the managed property: True if the key's lifetime is managed by key vault. If this is a key backing a
     * certificate, then managed will be true.
     *
     * @param managed the managed value to set.
     * @return the KeyBundle object itself.
     */
    KeyBundle setManaged(Boolean managed) {
        this.managed = managed;
        return this;
    }

    /**
     * Get the releasePolicy property: The policy rules under which the key can be exported.
     *
     * @return the releasePolicy value.
     */
    public KeyReleasePolicy getReleasePolicy() {
        return this.releasePolicy;
    }

    /**
     * Set the releasePolicy property: The policy rules under which the key can be exported.
     *
     * @param releasePolicy the releasePolicy value to set.
     * @return the KeyBundle object itself.
     */
    public KeyBundle setReleasePolicy(KeyReleasePolicy releasePolicy) {
        this.releasePolicy = releasePolicy;
        return this;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeJsonField("key", this.key);
        jsonWriter.writeJsonField("attributes", this.attributes);
        jsonWriter.writeMapField("tags", this.tags, (writer, element) -> writer.writeString(element));
        jsonWriter.writeJsonField("release_policy", this.releasePolicy);
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of KeyBundle from the JsonReader.
     *
     * @param jsonReader The JsonReader being read.
     * @return An instance of KeyBundle if the JsonReader was pointing to an instance of it, or null if it was pointing
     *     to JSON null.
     * @throws IOException If an error occurs while reading the KeyBundle.
     */
    public static KeyBundle fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(
                reader -> {
                    KeyBundle deserializedKeyBundle = new KeyBundle();
                    while (reader.nextToken() != JsonToken.END_OBJECT) {
                        String fieldName = reader.getFieldName();
                        reader.nextToken();

                        if ("key".equals(fieldName)) {
                            deserializedKeyBundle.key = JsonWebKey.fromJson(reader);
                        } else if ("attributes".equals(fieldName)) {
                            deserializedKeyBundle.attributes = KeyAttributes.fromJson(reader);
                        } else if ("tags".equals(fieldName)) {
                            Map tags = reader.readMap(reader1 -> reader1.getString());
                            deserializedKeyBundle.tags = tags;
                        } else if ("managed".equals(fieldName)) {
                            deserializedKeyBundle.managed = reader.getNullable(JsonReader::getBoolean);
                        } else if ("release_policy".equals(fieldName)) {
                            deserializedKeyBundle.releasePolicy = KeyReleasePolicy.fromJson(reader);
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedKeyBundle;
                });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy