/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF 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.
 */

/**
 * These .proto interfaces are private and unstable.
 * Please see http://wiki.apache.org/hadoop/Compatibility
 * for what changes are allowed for a *unstable* .proto interface.
 */
syntax = "proto2";

option java_package = "org.apache.hadoop.hdds.protocol.proto";

option java_outer_classname = "SCMSecretKeyProtocolProtos";

option java_generic_services = true;

option java_generate_equals_and_hash = true;

package hadoop.hdds.security.symmetric;

import "hdds.proto";

/**
All commands is send as request and all response come back via
Response class. If adding new functions please follow this protocol, since
our tracing and visibility tools depend on this pattern.
*/
message SCMSecretKeyRequest {
    required Type cmdType = 1; // Type of the command

    optional string traceID = 2;

    optional SCMGetSecretKeyRequest getSecretKeyRequest = 3;

    optional SCMGetCheckAndRotateRequest checkAndRotateRequest = 4;
}

message SCMSecretKeyResponse {
    required Type cmdType = 1; // Type of the command

    // A string that identifies this command, we generate  Trace ID in Ozone
    // frontend and this allows us to trace that command all over ozone.
    optional string traceID = 2;

    optional bool success = 3 [default = true];

    optional string message = 4;

    required Status status = 5;

    optional SCMGetCurrentSecretKeyResponse currentSecretKeyResponseProto = 11;

    optional SCMGetSecretKeyResponse getSecretKeyResponseProto = 12;

    optional SCMSecretKeysListResponse secretKeysListResponseProto = 13;

    optional SCMGetCheckAndRotateResponse checkAndRotateResponseProto = 14;

}

enum Type {
    GetCurrentSecretKey = 1;
    GetSecretKey = 2;
    GetAllSecretKeys = 3;
    CheckAndRotate = 4;
}

enum Status {
    OK = 1;
    INTERNAL_ERROR = 2;
    SECRET_KEY_NOT_ENABLED = 3;
    SECRET_KEY_NOT_INITIALIZED = 4;
}

service SCMSecretKeyProtocolService {
    rpc submitRequest (SCMSecretKeyRequest) returns (SCMSecretKeyResponse);
}

message ManagedSecretKey {
    required UUID id = 1;
    required uint64 creationTime = 2;
    required uint64 expiryTime = 3;
    required string algorithm = 4;
    required bytes encoded = 5;
}

message SCMGetSecretKeyRequest {
    required UUID secretKeyId = 1;
}

message SCMGetCheckAndRotateRequest {
    optional bool force = 1 [default = false];
}

message SCMGetCurrentSecretKeyResponse {
    required ManagedSecretKey secretKey = 1;
}

message SCMGetSecretKeyResponse {
    optional ManagedSecretKey secretKey = 1;
}

message SCMSecretKeysListResponse {
    repeated ManagedSecretKey secretKeys = 1;
}

message SCMGetCheckAndRotateResponse {
    optional bool status = 1;
}
