syntax = "proto3";

package yandex.cloud.mdb.mysql.v1alpha;

import "google/protobuf/wrappers.proto";
import "yandex/cloud/validation.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/mdb/mysql/v1alpha;mysql";
option java_package = "yandex.cloud.api.mdb.mysql.v1alpha";

// A MySQL user. For more information, see
// the [documentation](/docs/managed-mysql/concepts).
message User {
  // Name of the MySQL user.
  string name = 1;

  // ID of the MySQL cluster the user belongs to.
  string cluster_id = 2;

  // Set of permissions granted to the user.
  repeated Permission permissions = 3;
}

message Permission {
  enum Privilege {
    PRIVILEGE_UNSPECIFIED = 0;

    // All privileges that can be made available to the user.
    ALL_PRIVILEGES = 1;

    // Altering tables.
    ALTER = 2;

    // Altering stored routines (stored procedures and functions).
    ALTER_ROUTINE = 3;

    // Creating tables or indexes.
    CREATE = 4;

    // Creating stored routines.
    CREATE_ROUTINE = 5;

    // Creating temporary tables.
    CREATE_TEMPORARY_TABLES = 6;

    // Creating views.
    CREATE_VIEW = 7;

    // Deleting tables.
    DELETE = 8;

    // Removing tables or views.
    DROP = 9;

    // Creating, altering, dropping, or displaying events for the Event Scheduler.
    EVENT = 10;

    // Executing stored routines.
    EXECUTE = 11;

    // Creating and removing indexes.
    INDEX = 12;

    // Inserting rows into the database.
    INSERT = 13;

    // Using LOCK TABLES statement for tables available with SELECT privilege.
    LOCK_TABLES = 14;

    // Selecting rows from tables.
    //
    // Some SELECT statements can be allowed without the SELECT privilege. All
    // statements that read column values require the SELECT privilege. See
    // details in [MySQL documentation](https://dev.mysql.com/doc/refman/5.7/en/privileges-provided.html#priv_select).
    SELECT = 15;

    // Using the SHOW CREATE VIEW statement. Also needed for views used with EXPLAIN.
    SHOW_VIEW = 16;

    // Creating, removing, executing, or displaying triggers for a table.
    TRIGGER = 17;

    // Updating rows in the database.
    UPDATE = 18;
  }

  // Name of the database that the permission grants access to.
  string database_name = 1;

  // Roles granted to the user within the database.
  repeated Privilege roles = 2 [(size) = ">=1"];
}

message UserSpec {
  // Name of the MySQL user.
  string name = 1 [(required) = true, (length) = "<=32", (pattern) = "[a-zA-Z0-9_]*"];

  // Password of the MySQL user.
  string password = 2 [(required) = true, (length) = "8-128"];

  // Set of permissions to grant to the user.
  repeated Permission permissions = 3;
}
