syntax = "proto3";

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

import "storage/cluster.proto";
import "storage/deployment.proto";
import "storage/namespace.proto";
import "storage/network_policy.proto";
import "storage/node.proto";
import "storage/secret.proto";
import "storage/policy.proto";
import "storage/process_indicator.proto";


package v1;

enum ResourceAction {
    UNSET_ACTION_RESOURCE   = 0;
    CREATE_RESOURCE         = 1;
    REMOVE_RESOURCE         = 2;
    UPDATE_RESOURCE         = 3;
}

message SensorEvent {
    // These fields may be duplicated in the individual events, but avoid the need to branch all the time
    string         id                           = 1;
    ResourceAction action                       = 2;
    string         cluster_id                   = 3;

    oneof resource {
        storage.NetworkPolicy    network_policy    = 4;
        storage.Deployment       deployment        = 5;
        storage.Namespace        namespace         = 6;
        storage.Secret           secret            = 7;
        storage.Node             node              = 9;

        // Indicators
        storage.ProcessIndicator process_indicator = 8;
        storage.ProviderMetadata provider_metadata = 10;
    }
}

message SensorEnforcement {
    storage.EnforcementAction enforcement = 1;

    oneof resource {
        DeploymentEnforcement        deployment         = 2;
        ContainerInstanceEnforcement container_instance = 3;
    }
}

message DeploymentEnforcement {
    string deployment_id   = 1;
    string deployment_name = 2;
    string deployment_type = 3;
    string namespace       = 4;
    string alert_id        = 5;
}

message ContainerInstanceEnforcement {
    string container_instance_id = 1;
    string pod_id                = 2;
}

service SensorEventService {

    rpc RecordEvent(stream SensorEvent) returns (stream SensorEnforcement);

}
