/*
 * Copyright 2016-2022 Fraunhofer AISEC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *           $$\                           $$\ $$\   $$\
 *           $$ |                          $$ |\__|  $$ |
 *  $$$$$$$\ $$ | $$$$$$\  $$\   $$\  $$$$$$$ |$$\ $$$$$$\    $$$$$$\   $$$$$$\
 * $$  _____|$$ |$$  __$$\ $$ |  $$ |$$  __$$ |$$ |\_$$  _|  $$  __$$\ $$  __$$\
 * $$ /      $$ |$$ /  $$ |$$ |  $$ |$$ /  $$ |$$ |  $$ |    $$ /  $$ |$$ | \__|
 * $$ |      $$ |$$ |  $$ |$$ |  $$ |$$ |  $$ |$$ |  $$ |$$\ $$ |  $$ |$$ |
 * \$$$$$$\  $$ |\$$$$$   |\$$$$$   |\$$$$$$  |$$ |  \$$$   |\$$$$$   |$$ |
 *  \_______|\__| \______/  \______/  \_______|\__|   \____/  \______/ \__|
 *
 * This file is part of Clouditor Community Edition.
 */
syntax = "proto3";

package clouditor;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "evidence.proto";
import "metric.proto";

// Representing the link between orchestrator and discovery: Assessing evidences
// from discovery and sending results to orchestrator
service Assessment {

  // Triggers the assessment. Part of the private API. Not exposed as REST.
  rpc TriggerAssessment(TriggerAssessmentRequest)
      returns (google.protobuf.Empty) {}

  // Assesses the evidence sent by the discovery. Part of the public API, also
  // exposed as REST.
  rpc AssessEvidence(AssessEvidenceRequest) returns (AssessEvidenceResponse) {
    option (google.api.http) = {
      post : "/v1/assessment/evidences"
      body : "evidence"
      response_body : "status"
    };
  }

  // Assesses stream of evidences sent by the discovery and returns a response
  // stream. Part of the public API. Not exposed as REST.
  rpc AssessEvidences(stream AssessEvidenceRequest)
      returns (stream AssessEvidenceResponse) {};

  // List all assessment results. Part of the public API, also exposed as REST.
  rpc ListAssessmentResults(ListAssessmentResultsRequest)
      returns (ListAssessmentResultsResponse) {
    option (google.api.http) = {
      get : "/v1/assessment/results"
    };
  }
};

message ListAssessmentResultsRequest {}
message ListAssessmentResultsResponse { repeated AssessmentResult results = 1; }

message ConfigureAssessmentRequest {}
message ConfigureAssessmentResponse {}

message TriggerAssessmentRequest { string some_option = 1; }

message AssessEvidenceRequest { Evidence evidence = 1; }
message AssessEvidenceResponse {
  enum AssessmentStatus {
    ASSESSMENT_STATUS_UNSPECIFIED = 0;
    WAITING_FOR_RELATED = 1;
    ASSESSED = 2;
    FAILED = 3;
  }
  AssessmentStatus status = 1;

  string status_message = 2;
}

// A result resource, representing the result after assessing the cloud resource
// with id resource_id.
message AssessmentResult {
  // Assessment result id
  string id = 1;

  // Time of assessment
  google.protobuf.Timestamp timestamp = 2;

  // Reference to the metric the assessment was based on
  string metric_id = 3;

  // Data corresponding to the metric by the given metric id
  MetricConfiguration metric_configuration = 4;

  // Compliant case: true or false
  bool compliant = 5;

  // Reference to the assessed evidence
  string evidence_id = 6;

  // Reference to the resource of the assessed evidence
  string resource_id = 7;

  // Some comments on the reason for non-compliance
  string non_compliance_comments = 8;
}