syntax = "proto3";
package paralus.dev.sentry.rpc;

import "google/api/annotations.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "proto/types/commonpb/v3/common.proto";
import "proto/types/sentry/sentry.proto";

option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
  info : {
    title : "Sentry Bootstrap Service"
    version : "2.0"
    contact : {name : "Paralus Dev"}
  }
  schemes : HTTPS
  consumes : "application/json"
  consumes : "application/yaml"
  produces : "application/json"
  produces : "application/yaml"
  security_definitions : {
    security : {
      key : "BasicAuth"
      value : {type : TYPE_BASIC}
    }
    security : {
      key : "ApiKeyAuth"
      value : {type : TYPE_API_KEY in : IN_HEADER name : "X-PARALUS-API-KEYID"}
    }
  }
  security : {
    security_requirement : {
      key : "BasicAuth"
      value : {}
    }
    security_requirement : {
      key : "ApiKeyAuth"
      value : {}
    }
  }
  responses : {
    key : "403"
    value : {
      description : "Returned when the user does not have permission to access "
                    "the resource."
    }
  }
  responses : {
    key : "404"
    value : {description : "Returned when the resource does not exist."}
  }
  responses : {
    key : "500"
    value : {description : "Returned for internal server error"}
  }
};

message RegisterAgentRequest {
  string templateToken = 1;
  string templateName = 2;
  string token = 3;
  bytes csr = 4;
  string ipAddress = 5;
  string name = 6;
}

message RegisterAgentResponse {
  bytes certificate = 1;
  bytes caCertificate = 2;
}

message GetBootstrapAgentsRequest {
  paralus.dev.types.common.v3.QueryOptions opts = 1;
  string templateScope = 2;
}

message DeleteBootstrapAgentResponse {}
message DeleteRelayNetworkResponse {}
message GetRelayNetworksRequest {
  paralus.dev.types.common.v3.QueryOptions opts = 1;
}

message RelayAgentDownloadRequest {
  paralus.dev.types.common.v3.Metadata metadata = 1
    [ (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = {
        title : "Metadata",
        description : "Metadata of the resource"
    }];
  string clusterScope = 2;
}

service BootstrapService {
  rpc PatchBootstrapInfra(paralus.dev.types.sentry.BootstrapInfra)
      returns (paralus.dev.types.sentry.BootstrapInfra) {
    option (google.api.http) = {
      put : "/v2/sentry/bootstrap/infra/{metadata.name}"
      body : "*"
    };
  }

  rpc GetBootstrapInfra(paralus.dev.types.sentry.BootstrapInfra)
      returns (paralus.dev.types.sentry.BootstrapInfra) {
    option (google.api.http) = {
      get : "/v2/sentry/bootstrap/infra/{metadata.name}"
    };
  }

  rpc PatchBootstrapAgentTemplate(
      paralus.dev.types.sentry.BootstrapAgentTemplate)
      returns (paralus.dev.types.sentry.BootstrapAgentTemplate) {
    option (google.api.http) = {
      put : "/v2/sentry/bootstrap/template/{metadata.name}"
      body : "*"
    };
  }

  rpc GetBootstrapAgentTemplate(
      paralus.dev.types.sentry.BootstrapAgentTemplate)
      returns (paralus.dev.types.sentry.BootstrapAgentTemplate) {
    option (google.api.http) = {
      get : "/v2/sentry/bootstrap/template/{metadata.name}"
    };
  }

  rpc GetBootstrapAgentTemplates(paralus.dev.types.common.v3.QueryOptions)
      returns (paralus.dev.types.sentry.BootstrapAgentTemplateList) {
    option (google.api.http) = {
      get : "/v2/sentry/bootstrap/template"
    };
  }

  rpc RegisterBootstrapAgent(RegisterAgentRequest)
      returns (RegisterAgentResponse) {
    option (google.api.http) = {
      post : "/v2/sentry/bootstrap/{templateToken=template/*}/register"
      body : "*"
    };
  }

  rpc GetBootstrapAgentConfig(paralus.dev.types.sentry.BootstrapAgent)
      returns (paralus.dev.types.common.v3.HttpBody) {
    option (google.api.http) = {
      get : "/v2/sentry/bootstrap/{spec.templateRef=template/*}/agent/"
            "{metadata.name}/config"
    };
  }

  rpc CreateBootstrapAgent(paralus.dev.types.sentry.BootstrapAgent)
      returns (paralus.dev.types.sentry.BootstrapAgent) {
    option (google.api.http) = {
      post : "/v2/sentry/bootstrap/{spec.templateRef=template/*}/agent"
      body : "*"
    };
  }

  rpc GetBootstrapAgent(paralus.dev.types.sentry.BootstrapAgent)
      returns (paralus.dev.types.sentry.BootstrapAgent) {
    option (google.api.http) = {
      get : "/v2/sentry/bootstrap/{spec.templateRef=template/*}/agent/"
            "{metadata.name}"
    };
  }

  rpc GetBootstrapAgents(GetBootstrapAgentsRequest)
      returns (paralus.dev.types.sentry.BootstrapAgentList) {
    option (google.api.http) = {
      get : "/v2/sentry/bootstrap/{templateScope=template/*}/agent"
    };
  }

  rpc DeleteBootstrapAgent(paralus.dev.types.sentry.BootstrapAgent)
      returns (DeleteBootstrapAgentResponse) {
    option (google.api.http) = {
      delete : "/v2/sentry/bootstrap/{spec.templateRef=template/*}/agent/"
               "{metadata.name}"
    };
  }

  rpc UpdateBootstrapAgent(paralus.dev.types.sentry.BootstrapAgent)
      returns (paralus.dev.types.sentry.BootstrapAgent) {
    option (google.api.http) = {
      put : "/v2/sentry/bootstrap/{spec.templateRef=template/*}/agent/"
            "{metadata.name}"
      body : "*"
    };
  }

}