/*
 * Copyright 2021 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";

option go_package = "api/assessment";

// 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) {}

  // TODO(all): Part of public API because external entities (mainly
  // discoveries) can use it? List the latest set of assessment results. Part of
  // the public API, also exposed as REST
  rpc ListAssessmentResults(ListAssessmentResultsRequest)
      returns (ListAssessmentResultsResponse) {
    option (google.api.http) = {
      post : "/v1/assessment/results"
      response_body : "*"
    };
  }

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

  // Assesses stream of evidences coming from the discovery. Part of the public
  // API, not exposed as REST
  rpc AssessEvidences(stream Evidence) returns (google.protobuf.Empty);
};

message TriggerAssessmentRequest { string someOption = 1; }

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

message AssessEvidenceRequest { Evidence evidence = 1; }
message AssessEvidenceResponse { bool status = 1; }

// A result resource, representing the result after assessing the cloud resource
// with id resource_id.
message Result {
  // 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_data = 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;
}