syntax = "proto3";

option go_package = "v1";
option java_package = "io.stackrox.proto.api.v1";

import "google/api/annotations.proto";
import "api/v1/common.proto";
import "api/v1/empty.proto";
import "api/v1/search_service.proto";
import "storage/policy.proto";

package v1;

message DryRunResponse {
    message Alert {
        string deployment          = 1;
        repeated string violations = 2;
    }
    repeated Alert alerts = 1;
    message Excluded {
        string deployment   = 1;
        storage.Whitelist whitelist = 2;
    }
    repeated Excluded excluded     = 2;
}

message PolicyCategoriesResponse {
    repeated string categories = 1;
}

message RenamePolicyCategoryRequest {
    string old_category = 1;
    string new_category = 2;
}

message DeletePolicyCategoryRequest {
    string category = 1;
}

message ListPoliciesResponse {
    repeated storage.ListPolicy policies = 1;
}

message PatchPolicyRequest {
    string id         = 1;
    oneof set_disabled {
        bool disabled = 2;
    }
}

service PolicyService {

    rpc GetPolicy (ResourceByID) returns (storage.Policy) {
        option (google.api.http) = {
            get: "/v1/policies/{id}"
        };
    }

    rpc ListPolicies (RawQuery) returns (ListPoliciesResponse) {
        option (google.api.http) = {
            get: "/v1/policies"
        };
    }

    rpc PostPolicy (storage.Policy) returns (storage.Policy) {
        option (google.api.http) = {
            post: "/v1/policies"
            body: "*"
        };
    }

    rpc PutPolicy (storage.Policy) returns (Empty) {
        option (google.api.http) = {
            put: "/v1/policies/{id}"
            body: "*"
        };
    }

    rpc PatchPolicy (PatchPolicyRequest) returns (Empty) {
        option (google.api.http) = {
            patch: "/v1/policies/{id}"
            body: "*"
        };
    }

    rpc DeletePolicy (ResourceByID) returns (Empty) {
        option (google.api.http) = {
            delete: "/v1/policies/{id}"
        };
    }

    rpc ReassessPolicies (Empty) returns (Empty) {
        option (google.api.http) = {
            post: "/v1/policies/reassess"
        };
    }

    rpc DryRunPolicy (storage.Policy) returns (DryRunResponse) {
        option (google.api.http) = {
            post: "/v1/policies/dryrun"
            body: "*"
        };
    }

    rpc GetPolicyCategories (Empty) returns (PolicyCategoriesResponse) {
        option (google.api.http) = {
            get: "/v1/policyCategories"
        };
    }

    rpc RenamePolicyCategory (RenamePolicyCategoryRequest) returns (Empty) {
        option (google.api.http) = {
            put: "/v1/policyCategories/{old_category}"
            body: "*"
        };
    }

    rpc DeletePolicyCategory (DeletePolicyCategoryRequest) returns (Empty) {
        option (google.api.http) = {
            delete: "/v1/policyCategories/{category}"
        };
    }
}
