syntax = "proto3";

package yandex.cloud.containerregistry.v1;

import "yandex/cloud/api/operation.proto";
import "yandex/cloud/containerregistry/v1/scanner.proto";
import "yandex/cloud/operation/operation.proto";
import "yandex/cloud/validation.proto";
import "google/api/annotations.proto";

option go_package = "github.com/yandex-cloud/go-genproto/yandex/cloud/containerregistry/v1;containerregistry";
option java_package = "yandex.cloud.api.containerregistry.v1";

// A set of methods for scanning Docker images.
service ScannerService {

    // Executes scanning of specified image.
    rpc Scan (ScanRequest) returns (operation.Operation) {
        option (google.api.http) = { post: "/container-registry/v1/scans" body: "*" };
        option (yandex.cloud.api.operation) = {
          metadata: "ScanMetadata"
          response: "ScanResult"
        };
    }

    // Returns the specified ScanResult resource.
    //
    // To get the list of ScanResults for specified Image, make a [List] request.
    rpc Get (GetScanResultRequest) returns (ScanResult) {
        option (google.api.http) = { get: "/container-registry/v1/scans/{scan_result_id}" };
    }

    // Returns the last finished ScanResult for the specified Image.
    rpc GetLast (GetLastScanResultRequest) returns (ScanResult) {
        option (google.api.http) = { get: "/container-registry/v1/images/{image_id}:lastScanResult" };
    }

    // Retrieves the list of ScanResults for specified Image.
    rpc List (ListScanResultsRequest) returns (ListScanResultsResponse) {
        option (google.api.http) = { get: "/container-registry/v1/scans" };
    }

    // Retrieves the list of vulnerabilities found in particular scan.
    rpc ListVulnerabilities (ListVulnerabilitiesRequest) returns (ListVulnerabilitiesResponse) {
        option (google.api.http) = { get: "/container-registry/v1/scans/{scan_result_id}:listVulnerabilities" };
    }

}

message ScanRequest {
    // ID of the Image to be scanned for vulnerabilities.
    string image_id = 1 [(required) = true, (length) = "<=50"];
}

message ScanMetadata {
    // ID of the ScanResult that is being created.
    string scan_result_id = 1;
}

message GetScanResultRequest {
    // ID of the ScanResult to return.
    string scan_result_id = 1 [(required) = true, (length) = "<=50"];
}

message GetLastScanResultRequest {
    // ID of the Image to get last finished ScanResult.
    string image_id = 1 [(length) = "<=50"];
}

message ListScanResultsRequest {
    // ID of the Image or Repository to list ScanResults for.
    //
    // To get the image ID use a [yandex.cloud.containerregistry.v1.ImageService.List] request.
    // To get the repository ID use a [yandex.cloud.containerregistry.v1.RepositoryService.List] request.
    oneof id {
        option (exactly_one) = true;
        string image_id = 1 [(length) = "<=50"];
        string repository_id = 2 [(length) = "<=50"];
    }

    // The maximum number of results per page to return. If the number of available
    // results is larger than [page_size],
    // the service returns a [ListRegistriesResponse.next_page_token]
    // that can be used to get the next page of results in subsequent list requests.
    // Default value: 100.
    int64 page_size = 3 [(value) = "0-1000"];

    // Page token. To get the next page of results, set [page_token] to the
    // [ListRegistriesResponse.next_page_token] returned by a previous list request.
    string page_token = 4 [(length) = "<=100"];

    // A filter expression that filters resources listed in the response.
    // The expression must specify:
    // 1. The field name. Currently you can use filtering only on [ScanResult.status] field.
    // 2. An operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN` for lists of values.
    // 3. Value or a list of values to compare against the values of the field.
    string filter = 5 [(length) = "<=1000"];

    // An order expression that orders resources listed in the response.
    // The expression must specify:
    // 1. The field name. Currently you can use filtering only on [ScanResult.status] field.
    // 2. Order selector. Currently you can use ordering only on `ScanResult.status` field (critical first).
    string order_by = 6 [(length) = "<=100"];
}

message ListScanResultsResponse {
    // List of ScanResult resources.
    repeated ScanResult scan_results = 1;

    // This token allows you to get the next page of results for list requests. If the number of results
    // is larger than [ListImagesRequest.page_size], use
    // the [next_page_token] as the value
    // for the [ListImagesRequest.page_token] query parameter
    // in the next list request. Each subsequent list request will have its own
    // [next_page_token] to continue paging through the results.
    string next_page_token = 2;
}

message ListVulnerabilitiesRequest {
    // ID of the ScanResult to get list of vulnerabilities for.
    string scan_result_id = 1 [(required) = true, (length) = "<=50"];

    // The maximum number of results per page to return. If the number of available
    // results is larger than [page_size],
    // the service returns a [ListRegistriesResponse.next_page_token]
    // that can be used to get the next page of results in subsequent list requests.
    // Default value: 100.
    int64 page_size = 2 [(value) = "0-1000"];

    // Page token. To get the next page of results, set [page_token] to the
    // [ListRegistriesResponse.next_page_token] returned by a previous list request.
    string page_token = 3 [(length) = "<=100"];

    // A filter expression that filters resources listed in the response.
    // The expression must specify:
    // 1. The field name. Currently you can use filtering only on [Vulnerability.severity] and [PackageVulnerability.name] fields.
    // 2. An operator. Can be either `=` or `!=` for single values, `IN` or `NOT IN` for lists of values.
    // 3. Value or a list of values to compare against the values of the field.
    string filter = 4 [(length) = "<=1000"];

    // An order expression that orders resources listed in the response.
    // The expression must specify:
    // 1. The field name. Currently you can use filtering only on [Vulnerability.severity] and [PackageVulnerability.name] fields.
    // 2. Order selector. Currently you can use ordering only on `Vulnerability.severity` field (recent first).
    string order_by = 5 [(length) = "<=100"];
}

message ListVulnerabilitiesResponse {
    // List of Vulnerability resources.
    repeated Vulnerability vulnerabilities = 1;

    // This token allows you to get the next page of results for list requests. If the number of results
    // is larger than [ListImagesRequest.page_size], use
    // the [next_page_token] as the value
    // for the [ListImagesRequest.page_token] query parameter
    // in the next list request. Each subsequent list request will have its own
    // [next_page_token] to continue paging through the results.
    string next_page_token = 2;
}
