![JAR search and dependency download from the Maven repository](/logo.png)
software.amazon.awssdk.services.appsync.model.ApiKey Maven / Gradle / Ivy
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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 software.amazon.awssdk.services.appsync.model;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Describes an API key.
*
*
* Customers invoke AppSync GraphQL API operations with API keys as an identity mechanism. There are two key versions:
*
*
* da1: We introduced this version at launch in November 2017. These keys always expire after 7 days. Amazon
* DynamoDB TTL manages key expiration. These keys ceased to be valid after February 21, 2018, and they should no longer
* be used.
*
*
* -
*
* ListApiKeys
returns the expiration time in milliseconds.
*
*
* -
*
* CreateApiKey
returns the expiration time in milliseconds.
*
*
* -
*
* UpdateApiKey
is not available for this key version.
*
*
* -
*
* DeleteApiKey
deletes the item from the table.
*
*
* -
*
* Expiration is stored in DynamoDB as milliseconds. This results in a bug where keys are not automatically deleted
* because DynamoDB expects the TTL to be stored in seconds. As a one-time action, we deleted these keys from the table
* on February 21, 2018.
*
*
*
*
* da2: We introduced this version in February 2018 when AppSync added support to extend key expiration.
*
*
* -
*
* ListApiKeys
returns the expiration time and deletion time in seconds.
*
*
* -
*
* CreateApiKey
returns the expiration time and deletion time in seconds and accepts a user-provided
* expiration time in seconds.
*
*
* -
*
* UpdateApiKey
returns the expiration time and and deletion time in seconds and accepts a user-provided
* expiration time in seconds. Expired API keys are kept for 60 days after the expiration time. You can update the key
* expiration time as long as the key isn't deleted.
*
*
* -
*
* DeleteApiKey
deletes the item from the table.
*
*
* -
*
* Expiration is stored in DynamoDB as seconds. After the expiration time, using the key to authenticate will fail.
* However, you can reinstate the key before deletion.
*
*
* -
*
* Deletion is stored in DynamoDB as seconds. The key is deleted after deletion time.
*
*
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class ApiKey implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField ID_FIELD = SdkField. builder(MarshallingType.STRING).memberName("id")
.getter(getter(ApiKey::id)).setter(setter(Builder::id))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("id").build()).build();
private static final SdkField DESCRIPTION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("description").getter(getter(ApiKey::description)).setter(setter(Builder::description))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("description").build()).build();
private static final SdkField EXPIRES_FIELD = SdkField. builder(MarshallingType.LONG).memberName("expires")
.getter(getter(ApiKey::expires)).setter(setter(Builder::expires))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("expires").build()).build();
private static final SdkField DELETES_FIELD = SdkField. builder(MarshallingType.LONG).memberName("deletes")
.getter(getter(ApiKey::deletes)).setter(setter(Builder::deletes))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("deletes").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(ID_FIELD, DESCRIPTION_FIELD,
EXPIRES_FIELD, DELETES_FIELD));
private static final long serialVersionUID = 1L;
private final String id;
private final String description;
private final Long expires;
private final Long deletes;
private ApiKey(BuilderImpl builder) {
this.id = builder.id;
this.description = builder.description;
this.expires = builder.expires;
this.deletes = builder.deletes;
}
/**
*
* The API key ID.
*
*
* @return The API key ID.
*/
public final String id() {
return id;
}
/**
*
* A description of the purpose of the API key.
*
*
* @return A description of the purpose of the API key.
*/
public final String description() {
return description;
}
/**
*
* The time after which the API key expires. The date is represented as seconds since the epoch, rounded down to the
* nearest hour.
*
*
* @return The time after which the API key expires. The date is represented as seconds since the epoch, rounded
* down to the nearest hour.
*/
public final Long expires() {
return expires;
}
/**
*
* The time after which the API key is deleted. The date is represented as seconds since the epoch, rounded down to
* the nearest hour.
*
*
* @return The time after which the API key is deleted. The date is represented as seconds since the epoch, rounded
* down to the nearest hour.
*/
public final Long deletes() {
return deletes;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(id());
hashCode = 31 * hashCode + Objects.hashCode(description());
hashCode = 31 * hashCode + Objects.hashCode(expires());
hashCode = 31 * hashCode + Objects.hashCode(deletes());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof ApiKey)) {
return false;
}
ApiKey other = (ApiKey) obj;
return Objects.equals(id(), other.id()) && Objects.equals(description(), other.description())
&& Objects.equals(expires(), other.expires()) && Objects.equals(deletes(), other.deletes());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("ApiKey").add("Id", id()).add("Description", description()).add("Expires", expires())
.add("Deletes", deletes()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "id":
return Optional.ofNullable(clazz.cast(id()));
case "description":
return Optional.ofNullable(clazz.cast(description()));
case "expires":
return Optional.ofNullable(clazz.cast(expires()));
case "deletes":
return Optional.ofNullable(clazz.cast(deletes()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function