From 3f3bed8ffc9948d4f1fd4e266e1192b4ded3855f Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Mon, 15 Jan 2024 10:52:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20remove=20unused=20proto=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 6 +- policy/upstream/reporting_upstream.pb.go | 169 ------------------- policy/upstream/reporting_upstream.proto | 18 -- policy/upstream/reporting_upstream.ranger.go | 114 ------------- policy/upstream/upstream.go | 32 ---- upstream/cnspec_upstream.pb.go | 168 ------------------ upstream/cnspec_upstream.proto | 19 --- upstream/cnspec_upstream.ranger.go | 114 ------------- upstream/upstream.go | 32 ---- 9 files changed, 1 insertion(+), 671 deletions(-) delete mode 100644 policy/upstream/reporting_upstream.pb.go delete mode 100644 policy/upstream/reporting_upstream.proto delete mode 100644 policy/upstream/reporting_upstream.ranger.go delete mode 100644 policy/upstream/upstream.go delete mode 100644 upstream/cnspec_upstream.pb.go delete mode 100644 upstream/cnspec_upstream.proto delete mode 100644 upstream/cnspec_upstream.ranger.go delete mode 100644 upstream/upstream.go diff --git a/Makefile b/Makefile index 113919da..80c07328 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ prep/tools: # 🌙 cnspec # -cnspec/generate: clean/proto cli/generate policy/generate upstream/generate +cnspec/generate: clean/proto cli/generate policy/generate .PHONY: cli cli/generate: @@ -76,12 +76,8 @@ cli/generate: policy/generate: go generate ./policy go generate ./policy/scan - go generate ./policy/upstream go generate ./internal/bundle/yacit -upstream/generate: - go generate ./upstream - # 🏗 Binary # .PHONY: cnspec/build diff --git a/policy/upstream/reporting_upstream.pb.go b/policy/upstream/reporting_upstream.pb.go deleted file mode 100644 index ef45663f..00000000 --- a/policy/upstream/reporting_upstream.pb.go +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright (c) Mondoo, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.32.0 -// protoc v4.25.1 -// source: reporting_upstream.proto - -package upstream - -import ( - policy "go.mondoo.com/cnspec/v10/policy" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type ReportID struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` -} - -func (x *ReportID) Reset() { - *x = ReportID{} - if protoimpl.UnsafeEnabled { - mi := &file_reporting_upstream_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ReportID) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReportID) ProtoMessage() {} - -func (x *ReportID) ProtoReflect() protoreflect.Message { - mi := &file_reporting_upstream_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ReportID.ProtoReflect.Descriptor instead. -func (*ReportID) Descriptor() ([]byte, []int) { - return file_reporting_upstream_proto_rawDescGZIP(), []int{0} -} - -func (x *ReportID) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *ReportID) GetUrl() string { - if x != nil { - return x.Url - } - return "" -} - -var File_reporting_upstream_proto protoreflect.FileDescriptor - -var file_reporting_upstream_proto_rawDesc = []byte{ - 0x0a, 0x18, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x5f, 0x75, 0x70, 0x73, 0x74, - 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x19, 0x63, 0x6e, 0x73, 0x70, - 0x65, 0x63, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x2e, 0x76, 0x31, 0x1a, 0x1a, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2f, 0x63, 0x6e, - 0x73, 0x70, 0x65, 0x63, 0x5f, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0x2c, 0x0a, 0x08, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x49, 0x44, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, - 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x32, - 0x65, 0x0a, 0x09, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x58, 0x0a, 0x0b, - 0x53, 0x74, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x22, 0x2e, 0x63, 0x6e, - 0x73, 0x70, 0x65, 0x63, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x52, - 0x65, 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, - 0x23, 0x2e, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2e, - 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x70, 0x6f, - 0x72, 0x74, 0x49, 0x44, 0x22, 0x00, 0x42, 0x2a, 0x5a, 0x28, 0x67, 0x6f, 0x2e, 0x6d, 0x6f, 0x6e, - 0x64, 0x6f, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x76, - 0x31, 0x30, 0x2f, 0x70, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x2f, 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, - 0x61, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_reporting_upstream_proto_rawDescOnce sync.Once - file_reporting_upstream_proto_rawDescData = file_reporting_upstream_proto_rawDesc -) - -func file_reporting_upstream_proto_rawDescGZIP() []byte { - file_reporting_upstream_proto_rawDescOnce.Do(func() { - file_reporting_upstream_proto_rawDescData = protoimpl.X.CompressGZIP(file_reporting_upstream_proto_rawDescData) - }) - return file_reporting_upstream_proto_rawDescData -} - -var file_reporting_upstream_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_reporting_upstream_proto_goTypes = []interface{}{ - (*ReportID)(nil), // 0: cnspec.policy.upstream.v1.ReportID - (*policy.ReportCollection)(nil), // 1: cnspec.policy.v1.ReportCollection -} -var file_reporting_upstream_proto_depIdxs = []int32{ - 1, // 0: cnspec.policy.upstream.v1.Reporting.StoreReport:input_type -> cnspec.policy.v1.ReportCollection - 0, // 1: cnspec.policy.upstream.v1.Reporting.StoreReport:output_type -> cnspec.policy.upstream.v1.ReportID - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_reporting_upstream_proto_init() } -func file_reporting_upstream_proto_init() { - if File_reporting_upstream_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_reporting_upstream_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReportID); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_reporting_upstream_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_reporting_upstream_proto_goTypes, - DependencyIndexes: file_reporting_upstream_proto_depIdxs, - MessageInfos: file_reporting_upstream_proto_msgTypes, - }.Build() - File_reporting_upstream_proto = out.File - file_reporting_upstream_proto_rawDesc = nil - file_reporting_upstream_proto_goTypes = nil - file_reporting_upstream_proto_depIdxs = nil -} diff --git a/policy/upstream/reporting_upstream.proto b/policy/upstream/reporting_upstream.proto deleted file mode 100644 index c26b2bbf..00000000 --- a/policy/upstream/reporting_upstream.proto +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Mondoo, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -syntax = "proto3"; - -package cnspec.policy.upstream.v1; -option go_package = "go.mondoo.com/cnspec/v10/policy/upstream"; - -import "policy/cnspec_policy.proto"; - -service Reporting { - rpc StoreReport(cnspec.policy.v1.ReportCollection) returns (ReportID) {} -} - -message ReportID { - string id = 1; - string url = 2; -} diff --git a/policy/upstream/reporting_upstream.ranger.go b/policy/upstream/reporting_upstream.ranger.go deleted file mode 100644 index f15a1a48..00000000 --- a/policy/upstream/reporting_upstream.ranger.go +++ /dev/null @@ -1,114 +0,0 @@ -// Code generated by protoc-gen-rangerrpc version DO NOT EDIT. -// source: reporting_upstream.proto - -package upstream - -import ( - "context" - "errors" - "net/http" - "net/url" - "strings" - - "go.mondoo.com/cnspec/v10/policy" - ranger "go.mondoo.com/ranger-rpc" - "go.mondoo.com/ranger-rpc/metadata" - jsonpb "google.golang.org/protobuf/encoding/protojson" - pb "google.golang.org/protobuf/proto" -) - -// service interface definition - -type Reporting interface { - StoreReport(context.Context, *policy.ReportCollection) (*ReportID, error) -} - -// client implementation - -type ReportingClient struct { - ranger.Client - httpclient ranger.HTTPClient - prefix string -} - -func NewReportingClient(addr string, client ranger.HTTPClient, plugins ...ranger.ClientPlugin) (*ReportingClient, error) { - base, err := url.Parse(ranger.SanitizeUrl(addr)) - if err != nil { - return nil, err - } - - u, err := url.Parse("./Reporting") - if err != nil { - return nil, err - } - - serviceClient := &ReportingClient{ - httpclient: client, - prefix: base.ResolveReference(u).String(), - } - serviceClient.AddPlugins(plugins...) - return serviceClient, nil -} -func (c *ReportingClient) StoreReport(ctx context.Context, in *policy.ReportCollection) (*ReportID, error) { - out := new(ReportID) - err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/StoreReport"}, ""), in, out) - return out, err -} - -// server implementation - -type ReportingServerOption func(s *ReportingServer) - -func WithUnknownFieldsForReportingServer() ReportingServerOption { - return func(s *ReportingServer) { - s.allowUnknownFields = true - } -} - -func NewReportingServer(handler Reporting, opts ...ReportingServerOption) http.Handler { - srv := &ReportingServer{ - handler: handler, - } - - for i := range opts { - opts[i](srv) - } - - service := ranger.Service{ - Name: "Reporting", - Methods: map[string]ranger.Method{ - "StoreReport": srv.StoreReport, - }, - } - return ranger.NewRPCServer(&service) -} - -type ReportingServer struct { - handler Reporting - allowUnknownFields bool -} - -func (p *ReportingServer) StoreReport(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { - var req policy.ReportCollection - var err error - - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil, errors.New("could not access header") - } - - switch md.First("Content-Type") { - case "application/protobuf", "application/octet-stream", "application/grpc+proto": - err = pb.Unmarshal(*reqBytes, &req) - default: - // handle case of empty object - if len(*reqBytes) > 0 { - err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) - } - } - - if err != nil { - return nil, err - } - return p.handler.StoreReport(ctx, &req) -} diff --git a/policy/upstream/upstream.go b/policy/upstream/upstream.go deleted file mode 100644 index 0f4bfa2e..00000000 --- a/policy/upstream/upstream.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Mondoo, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -package upstream - -//go:generate protoc --proto_path=../../:../../cnquery:. --go_out=. --go_opt=paths=source_relative --rangerrpc_out=. reporting_upstream.proto - -import ( - "context" - "net/url" - - "github.com/rs/zerolog/log" - "go.mondoo.com/cnspec/v10/policy" - "go.mondoo.com/ranger-rpc" -) - -const sharedReportUrl = "https://report.api.mondoo.com" - -func UploadSharedReport(report *policy.ReportCollection, reportUrl string, proxy *url.URL) (*ReportID, error) { - if reportUrl == "" { - reportUrl = sharedReportUrl - } - - httpClient := ranger.NewHttpClient(ranger.WithProxy(proxy)) - sharedReportClient, err := NewReportingClient(reportUrl, httpClient) - if err != nil { - log.Error().Err(err).Msg("error initializing shared report client") - return nil, err - } - - return sharedReportClient.StoreReport(context.Background(), report) -} diff --git a/upstream/cnspec_upstream.pb.go b/upstream/cnspec_upstream.pb.go deleted file mode 100644 index 40c3a7f8..00000000 --- a/upstream/cnspec_upstream.pb.go +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) Mondoo, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.32.0 -// protoc v4.25.1 -// source: cnspec_upstream.proto - -package upstream - -import ( - policy "go.mondoo.com/cnspec/v10/policy" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type ReportID struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Url string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` -} - -func (x *ReportID) Reset() { - *x = ReportID{} - if protoimpl.UnsafeEnabled { - mi := &file_cnspec_upstream_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ReportID) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ReportID) ProtoMessage() {} - -func (x *ReportID) ProtoReflect() protoreflect.Message { - mi := &file_cnspec_upstream_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ReportID.ProtoReflect.Descriptor instead. -func (*ReportID) Descriptor() ([]byte, []int) { - return file_cnspec_upstream_proto_rawDescGZIP(), []int{0} -} - -func (x *ReportID) GetId() string { - if x != nil { - return x.Id - } - return "" -} - -func (x *ReportID) GetUrl() string { - if x != nil { - return x.Url - } - return "" -} - -var File_cnspec_upstream_proto protoreflect.FileDescriptor - -var file_cnspec_upstream_proto_rawDesc = []byte{ - 0x0a, 0x15, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x5f, 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, - 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x12, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x2e, - 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x76, 0x31, 0x1a, 0x1a, 0x70, 0x6f, 0x6c, - 0x69, 0x63, 0x79, 0x2f, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x5f, 0x70, 0x6f, 0x6c, 0x69, 0x63, - 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x2c, 0x0a, 0x08, 0x52, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x49, 0x44, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x03, 0x75, 0x72, 0x6c, 0x32, 0x5e, 0x0a, 0x09, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x69, - 0x6e, 0x67, 0x12, 0x51, 0x0a, 0x0b, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x52, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x12, 0x22, 0x2e, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x2e, 0x70, 0x6f, 0x6c, 0x69, 0x63, - 0x79, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6f, 0x6c, 0x6c, 0x65, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x1c, 0x2e, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x2e, 0x75, - 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x76, 0x31, 0x2e, 0x52, 0x65, 0x70, 0x6f, 0x72, - 0x74, 0x49, 0x44, 0x22, 0x00, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x6f, 0x2e, 0x6d, 0x6f, 0x6e, 0x64, - 0x6f, 0x6f, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6e, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x76, 0x31, - 0x30, 0x2f, 0x75, 0x70, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, -} - -var ( - file_cnspec_upstream_proto_rawDescOnce sync.Once - file_cnspec_upstream_proto_rawDescData = file_cnspec_upstream_proto_rawDesc -) - -func file_cnspec_upstream_proto_rawDescGZIP() []byte { - file_cnspec_upstream_proto_rawDescOnce.Do(func() { - file_cnspec_upstream_proto_rawDescData = protoimpl.X.CompressGZIP(file_cnspec_upstream_proto_rawDescData) - }) - return file_cnspec_upstream_proto_rawDescData -} - -var file_cnspec_upstream_proto_msgTypes = make([]protoimpl.MessageInfo, 1) -var file_cnspec_upstream_proto_goTypes = []interface{}{ - (*ReportID)(nil), // 0: cnspec.upstream.v1.ReportID - (*policy.ReportCollection)(nil), // 1: cnspec.policy.v1.ReportCollection -} -var file_cnspec_upstream_proto_depIdxs = []int32{ - 1, // 0: cnspec.upstream.v1.Reporting.StoreReport:input_type -> cnspec.policy.v1.ReportCollection - 0, // 1: cnspec.upstream.v1.Reporting.StoreReport:output_type -> cnspec.upstream.v1.ReportID - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name -} - -func init() { file_cnspec_upstream_proto_init() } -func file_cnspec_upstream_proto_init() { - if File_cnspec_upstream_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_cnspec_upstream_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ReportID); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_cnspec_upstream_proto_rawDesc, - NumEnums: 0, - NumMessages: 1, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_cnspec_upstream_proto_goTypes, - DependencyIndexes: file_cnspec_upstream_proto_depIdxs, - MessageInfos: file_cnspec_upstream_proto_msgTypes, - }.Build() - File_cnspec_upstream_proto = out.File - file_cnspec_upstream_proto_rawDesc = nil - file_cnspec_upstream_proto_goTypes = nil - file_cnspec_upstream_proto_depIdxs = nil -} diff --git a/upstream/cnspec_upstream.proto b/upstream/cnspec_upstream.proto deleted file mode 100644 index c0ff126f..00000000 --- a/upstream/cnspec_upstream.proto +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Mondoo, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -syntax = "proto3"; - -package cnspec.upstream.v1; -option go_package = "go.mondoo.com/cnspec/v10/upstream"; - -import "policy/cnspec_policy.proto"; - -service Reporting { - rpc StoreReport(cnspec.policy.v1.ReportCollection) returns (ReportID) {} -} - -message ReportID { - string id = 1; - string url = 2; -} - diff --git a/upstream/cnspec_upstream.ranger.go b/upstream/cnspec_upstream.ranger.go deleted file mode 100644 index a6380ded..00000000 --- a/upstream/cnspec_upstream.ranger.go +++ /dev/null @@ -1,114 +0,0 @@ -// Code generated by protoc-gen-rangerrpc version DO NOT EDIT. -// source: cnspec_upstream.proto - -package upstream - -import ( - "context" - "errors" - "net/http" - "net/url" - "strings" - - "go.mondoo.com/cnspec/v10/policy" - ranger "go.mondoo.com/ranger-rpc" - "go.mondoo.com/ranger-rpc/metadata" - jsonpb "google.golang.org/protobuf/encoding/protojson" - pb "google.golang.org/protobuf/proto" -) - -// service interface definition - -type Reporting interface { - StoreReport(context.Context, *policy.ReportCollection) (*ReportID, error) -} - -// client implementation - -type ReportingClient struct { - ranger.Client - httpclient ranger.HTTPClient - prefix string -} - -func NewReportingClient(addr string, client ranger.HTTPClient, plugins ...ranger.ClientPlugin) (*ReportingClient, error) { - base, err := url.Parse(ranger.SanitizeUrl(addr)) - if err != nil { - return nil, err - } - - u, err := url.Parse("./Reporting") - if err != nil { - return nil, err - } - - serviceClient := &ReportingClient{ - httpclient: client, - prefix: base.ResolveReference(u).String(), - } - serviceClient.AddPlugins(plugins...) - return serviceClient, nil -} -func (c *ReportingClient) StoreReport(ctx context.Context, in *policy.ReportCollection) (*ReportID, error) { - out := new(ReportID) - err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/StoreReport"}, ""), in, out) - return out, err -} - -// server implementation - -type ReportingServerOption func(s *ReportingServer) - -func WithUnknownFieldsForReportingServer() ReportingServerOption { - return func(s *ReportingServer) { - s.allowUnknownFields = true - } -} - -func NewReportingServer(handler Reporting, opts ...ReportingServerOption) http.Handler { - srv := &ReportingServer{ - handler: handler, - } - - for i := range opts { - opts[i](srv) - } - - service := ranger.Service{ - Name: "Reporting", - Methods: map[string]ranger.Method{ - "StoreReport": srv.StoreReport, - }, - } - return ranger.NewRPCServer(&service) -} - -type ReportingServer struct { - handler Reporting - allowUnknownFields bool -} - -func (p *ReportingServer) StoreReport(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { - var req policy.ReportCollection - var err error - - md, ok := metadata.FromIncomingContext(ctx) - if !ok { - return nil, errors.New("could not access header") - } - - switch md.First("Content-Type") { - case "application/protobuf", "application/octet-stream", "application/grpc+proto": - err = pb.Unmarshal(*reqBytes, &req) - default: - // handle case of empty object - if len(*reqBytes) > 0 { - err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) - } - } - - if err != nil { - return nil, err - } - return p.handler.StoreReport(ctx, &req) -} diff --git a/upstream/upstream.go b/upstream/upstream.go deleted file mode 100644 index 3d97f071..00000000 --- a/upstream/upstream.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Mondoo, Inc. -// SPDX-License-Identifier: BUSL-1.1 - -package upstream - -//go:generate protoc --proto_path=../:../cnquery:. --go_out=. --go_opt=paths=source_relative --rangerrpc_out=. cnspec_upstream.proto - -import ( - "context" - "net/url" - - "github.com/rs/zerolog/log" - "go.mondoo.com/cnspec/v10/policy" - "go.mondoo.com/ranger-rpc" -) - -const sharedReportUrl = "https://report.api.mondoo.com" - -func UploadSharedReport(report *policy.ReportCollection, reportUrl string, proxy *url.URL) (*ReportID, error) { - if reportUrl == "" { - reportUrl = sharedReportUrl - } - - httpClient := ranger.NewHttpClient(ranger.WithProxy(proxy)) - sharedReportClient, err := NewReportingClient(reportUrl, httpClient) - if err != nil { - log.Error().Err(err).Msg("error initializing shared report client") - return nil, err - } - - return sharedReportClient.StoreReport(context.Background(), report) -}