// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1

syntax = "proto3";

package controller.storage.target.store.v1;

import "controller/custom_options/v1/options.proto";
import "controller/storage/timestamp/v1/timestamp.proto";

option go_package = "github.com/hashicorp/boundary/internal/target/store;store";

// TargetView is a view that contains all the target subtypes
message TargetView {
  // public_id is used to access the Target via an API
  // @inject_tag: gorm:"primary_key"
  string public_id = 10;

  // project id for the Target
  // @inject_tag: `gorm:"default:null"`
  string project_id = 20;

  // name is the optional friendly name used to
  // access the Target via an API
  // @inject_tag: `gorm:"default:null"`
  string name = 30;

  // description of the Target
  // @inject_tag: `gorm:"default:null"`
  string description = 40;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 50;

  // update_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 60;

  // version allows optimistic locking of the Target when modifying the
  // Target
  // @inject_tag: `gorm:"default:null"`
  uint32 version = 70;

  // type represents the type of the Target
  // @inject_tag: `gorm:"default:null"`
  string type = 80;

  // default port of the Target
  // @inject_tag: `gorm:"default:null"`
  uint32 default_port = 90;

  // Default port for the listening client to use when establishing a session
  // @inject_tag: `gorm:"default:null"`
  uint32 default_client_port = 95;

  // Maximum total lifetime of a created session, in seconds
  // @inject_tag: `gorm:"default:null"`
  uint32 session_max_seconds = 100;

  // Maximum number of connections in a session
  // @inject_tag: `gorm:"default:null"`
  int32 session_connection_limit = 110;

  // A boolean expression that allows filtering the workers that can handle a session
  // @inject_tag: `gorm:"default:null"`
  string worker_filter = 120;

  // @inject_tag: `gorm:"default:null"`
  string egress_worker_filter = 130;

  // @inject_tag: `gorm:"default:null"`
  string ingress_worker_filter = 140;

  // A boolean indicating if session recording has been enabled
  // @inject_tag: `gorm:"default:null"`
  bool enable_session_recording = 150;

  // PublicId of the storage bucket associated with the target
  // @inject_tag: `gorm:"default:null"`
  string storage_bucket_id = 160;
}

message TargetHostSet {
  // target_id of the TargetHostSet
  // @inject_tag: gorm:"primary_key"
  string target_id = 10;

  // host_set_id of the TargetHostSet
  // @inject_tag: gorm:"primary_key"
  string host_set_id = 20;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 30;
}

message TargetAddress {
  // target_id of the Target
  // @inject_tag: gorm:"primary_key"
  string target_id = 10;

  // address associated to the Target
  // @inject_tag: `gorm:"not_null"`
  string address = 20 [(custom_options.v1.mask_mapping) = {
    this: "address"
    that: "address"
  }];
}

message CredentialLibrary {
  // target_id of the Target
  // @inject_tag: gorm:"primary_key"
  string target_id = 10;

  // credential_library_id of the CredentialLibrary
  // @inject_tag: gorm:"primary_key"
  string credential_library_id = 20;

  // credential_purpose is the purpose of the credential for the target
  // @inject_tag: gorm:"primary_key"
  string credential_purpose = 30;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 40;
}

message StaticCredential {
  // target_id of the Target
  // @inject_tag: gorm:"primary_key"
  string target_id = 10;

  // credential_id of the static Credential
  // @inject_tag: `gorm:"column:credential_static_id;primary_key"
  string credential_id = 20;

  // credential_purpose is the purpose of the credential for the target
  // @inject_tag: gorm:"primary_key"
  string credential_purpose = 30;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 40;
}

message CredentialSource {
  // target_id of the Target
  // @inject_tag: gorm:"primary_key"
  string target_id = 10;

  // credential_source_id of the Credential Library or static Credential
  // @inject_tag: gorm:"primary_key"
  string credential_source_id = 20;

  // credential_purpose is the purpose of the credential for the target
  // @inject_tag: gorm:"primary_key"
  string credential_purpose = 30;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 40;

  // type of credential source (library or static)
  // @inject_tag: `gorm:"not_null"`
  string type = 50;
}

message CredentialSourceView {
  // public_id of the Credential source
  // @inject_tag: gorm:"primary_key"
  string public_id = 10;

  // type of credential source (library or static)
  // @inject_tag: `gorm:"not_null"`
  string type = 20;
}

message TargetProxyCertificate {
  // public_id is used to identify the target proxy key
  // @inject_tag: `gorm:"primary_key"`
  string public_id = 10;

  // target_id is used to access the proxy target this key is for
  // @inject_tag: `gorm:"not_null"`
  string target_id = 20;

  // public_key is the public key associated with this certificate
  // @inject_tag: `gorm:"not_null"`
  bytes public_key = 30;

  // private_key is the plaintext key. this is not stored in the db
  // @inject_tag: `gorm:"-" wrapping:"pt,private_key"`
  bytes private_key = 40;

  // private_key_encrypted is the encrypted PEM encoded private key
  // @inject_tag: `gorm:"not_null" wrapping:"ct,private_key"`
  bytes private_key_encrypted = 50;

  // key_id is the kms private id used to encrypt this entry's private key
  // @inject_tag: `gorm:"not_null"`
  string key_id = 60;

  // certificate is the PEM encoded certificate
  // @inject_tag: `gorm:"not_null"`
  bytes certificate = 70;

  // not_valid_after is the timestamp at which this certificate's validity period ends
  // @inject_tag: `gorm:"not_null"`
  timestamp.v1.Timestamp not_valid_after = 80;

  // version allows optimistic locking during modification
  // @inject_tag: `gorm:"default:null"`
  uint32 version = 90;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 100;

  // update_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 110;
}

message TargetAliasProxyCertificate {
  // public_id is used to identify the target proxy key
  // @inject_tag: `gorm:"primary_key"`
  string public_id = 10;

  // target_id is used to access the proxy target this key is for
  // @inject_tag: `gorm:"not_null"`
  string target_id = 20;

  // public_key is the public key associated with this certificate
  // @inject_tag: `gorm:"not_null"`
  bytes public_key = 30;

  // private_key is the plaintext key. this is not stored in the db
  // @inject_tag: `gorm:"-" wrapping:"pt,private_key"`
  bytes private_key = 40;

  // private_key_encrypted is the encrypted PEM encoded private key
  // @inject_tag: `gorm:"not_null" wrapping:"ct,private_key"`
  bytes private_key_encrypted = 50;

  // key_id is the kms private id used to encrypt this entry's private key
  // @inject_tag: `gorm:"not_null"`
  string key_id = 60;

  // alias_id is the public id of the alias target
  // @inject_tag: `gorm:"not_null"`
  string alias_id = 70;

  // certificate is the PEM encoded certificate
  // @inject_tag: `gorm:"not_null"`
  bytes certificate = 80;

  // not_valid_after is the timestamp at which this certificate's validity period ends
  // @inject_tag: `gorm:"not_null"`
  timestamp.v1.Timestamp not_valid_after = 90;

  // version allows optimistic locking during modification
  // @inject_tag: `gorm:"default:null"`
  uint32 version = 100;

  // create_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp create_time = 110;

  // update_time from the RDBMS
  // @inject_tag: `gorm:"default:current_timestamp"`
  timestamp.v1.Timestamp update_time = 120;
}
