/
assessment.go
142 lines (110 loc) · 4.19 KB
/
assessment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// 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.
package standalone
import (
"context"
"clouditor.io/clouditor/api/assessment"
"clouditor.io/clouditor/api/evidence"
service_assessment "clouditor.io/clouditor/service/assessment"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/protobuf/types/known/emptypb"
)
var assessmentService assessment.AssessmentServer
type standaloneEvidenceStream struct {
serverChannel chan *evidence.Evidence
clientChannel chan *emptypb.Empty
ctx context.Context
}
type standaloneEvidenceClient struct{}
func (s standaloneEvidenceStream) SendAndClose(*emptypb.Empty) error {
s.clientChannel <- &emptypb.Empty{}
return nil
}
func (s standaloneEvidenceStream) CloseAndRecv() (*emptypb.Empty, error) {
empty := <-s.clientChannel
return empty, nil
}
func (standaloneEvidenceStream) CloseSend() error {
return nil
}
func (standaloneEvidenceStream) Header() (metadata.MD, error) {
return nil, nil
}
func (standaloneEvidenceStream) Trailer() metadata.MD {
return nil
}
func (standaloneEvidenceStream) Context() context.Context {
return nil
}
func (s standaloneEvidenceStream) Send(evidence *evidence.Evidence) error {
s.serverChannel <- evidence
return nil
}
func (standaloneEvidenceStream) SendHeader(metadata.MD) error {
return nil
}
func (standaloneEvidenceStream) SetHeader(metadata.MD) error {
return nil
}
func (standaloneEvidenceStream) SetTrailer(metadata.MD) {
}
func (s standaloneEvidenceStream) Recv() (*evidence.Evidence, error) {
evidence := <-s.serverChannel
return evidence, nil
}
func (standaloneEvidenceStream) RecvMsg(_ interface{}) error {
return nil
}
func (standaloneEvidenceStream) SendMsg(_ interface{}) error {
return nil
}
func (standaloneEvidenceClient) TriggerAssessment(ctx context.Context, in *assessment.TriggerAssessmentRequest, _ ...grpc.CallOption) (*emptypb.Empty, error) {
return assessmentService.TriggerAssessment(ctx, in)
}
func (standaloneEvidenceClient) AssessEvidence(ctx context.Context, in *assessment.AssessEvidenceRequest, _ ...grpc.CallOption) (*assessment.AssessEvidenceResponse, error) {
return assessmentService.AssessEvidence(ctx, in)
}
func (standaloneEvidenceClient) ListAssessmentResults(ctx context.Context, in *assessment.ListAssessmentResultsRequest, _ ...grpc.CallOption) (*assessment.ListAssessmentResultsResponse, error) {
return assessmentService.ListAssessmentResults(ctx, in)
}
func (standaloneEvidenceClient) AssessEvidences(_ context.Context, _ ...grpc.CallOption) (assessment.Assessment_AssessEvidencesClient, error) {
var stream = &standaloneEvidenceStream{
serverChannel: make(chan *evidence.Evidence),
clientChannel: make(chan *emptypb.Empty),
ctx: context.Background(),
}
go func() {
_ = assessmentService.AssessEvidences(stream)
}()
return stream, nil
}
func NewAssessmentClient() assessment.AssessmentClient {
return &standaloneEvidenceClient{}
}
func NewAssessmentServer() assessment.AssessmentServer {
assessmentService = service_assessment.NewService()
return assessmentService
}