go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/explorer/cnquery_explorer.ranger.go (about) 1 // Code generated by protoc-gen-rangerrpc version DO NOT EDIT. 2 // source: cnquery_explorer.proto 3 4 package explorer 5 6 import ( 7 "context" 8 "errors" 9 "net/http" 10 "net/url" 11 "strings" 12 13 ranger "go.mondoo.com/ranger-rpc" 14 "go.mondoo.com/ranger-rpc/metadata" 15 jsonpb "google.golang.org/protobuf/encoding/protojson" 16 pb "google.golang.org/protobuf/proto" 17 ) 18 19 // service interface definition 20 21 type QueryHub interface { 22 SetBundle(context.Context, *Bundle) (*Empty, error) 23 DeleteQueryPack(context.Context, *Mrn) (*Empty, error) 24 ValidateBundle(context.Context, *Bundle) (*Empty, error) 25 GetBundle(context.Context, *Mrn) (*Bundle, error) 26 GetQueryPack(context.Context, *Mrn) (*QueryPack, error) 27 GetFilters(context.Context, *Mrn) (*Mqueries, error) 28 List(context.Context, *ListReq) (*QueryPacks, error) 29 DefaultPacks(context.Context, *DefaultPacksReq) (*URLs, error) 30 } 31 32 // client implementation 33 34 type QueryHubClient struct { 35 ranger.Client 36 httpclient ranger.HTTPClient 37 prefix string 38 } 39 40 func NewQueryHubClient(addr string, client ranger.HTTPClient, plugins ...ranger.ClientPlugin) (*QueryHubClient, error) { 41 base, err := url.Parse(ranger.SanitizeUrl(addr)) 42 if err != nil { 43 return nil, err 44 } 45 46 u, err := url.Parse("./QueryHub") 47 if err != nil { 48 return nil, err 49 } 50 51 serviceClient := &QueryHubClient{ 52 httpclient: client, 53 prefix: base.ResolveReference(u).String(), 54 } 55 serviceClient.AddPlugins(plugins...) 56 return serviceClient, nil 57 } 58 func (c *QueryHubClient) SetBundle(ctx context.Context, in *Bundle) (*Empty, error) { 59 out := new(Empty) 60 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/SetBundle"}, ""), in, out) 61 return out, err 62 } 63 func (c *QueryHubClient) DeleteQueryPack(ctx context.Context, in *Mrn) (*Empty, error) { 64 out := new(Empty) 65 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/DeleteQueryPack"}, ""), in, out) 66 return out, err 67 } 68 func (c *QueryHubClient) ValidateBundle(ctx context.Context, in *Bundle) (*Empty, error) { 69 out := new(Empty) 70 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/ValidateBundle"}, ""), in, out) 71 return out, err 72 } 73 func (c *QueryHubClient) GetBundle(ctx context.Context, in *Mrn) (*Bundle, error) { 74 out := new(Bundle) 75 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/GetBundle"}, ""), in, out) 76 return out, err 77 } 78 func (c *QueryHubClient) GetQueryPack(ctx context.Context, in *Mrn) (*QueryPack, error) { 79 out := new(QueryPack) 80 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/GetQueryPack"}, ""), in, out) 81 return out, err 82 } 83 func (c *QueryHubClient) GetFilters(ctx context.Context, in *Mrn) (*Mqueries, error) { 84 out := new(Mqueries) 85 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/GetFilters"}, ""), in, out) 86 return out, err 87 } 88 func (c *QueryHubClient) List(ctx context.Context, in *ListReq) (*QueryPacks, error) { 89 out := new(QueryPacks) 90 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/List"}, ""), in, out) 91 return out, err 92 } 93 func (c *QueryHubClient) DefaultPacks(ctx context.Context, in *DefaultPacksReq) (*URLs, error) { 94 out := new(URLs) 95 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/DefaultPacks"}, ""), in, out) 96 return out, err 97 } 98 99 // server implementation 100 101 type QueryHubServerOption func(s *QueryHubServer) 102 103 func WithUnknownFieldsForQueryHubServer() QueryHubServerOption { 104 return func(s *QueryHubServer) { 105 s.allowUnknownFields = true 106 } 107 } 108 109 func NewQueryHubServer(handler QueryHub, opts ...QueryHubServerOption) http.Handler { 110 srv := &QueryHubServer{ 111 handler: handler, 112 } 113 114 for i := range opts { 115 opts[i](srv) 116 } 117 118 service := ranger.Service{ 119 Name: "QueryHub", 120 Methods: map[string]ranger.Method{ 121 "SetBundle": srv.SetBundle, 122 "DeleteQueryPack": srv.DeleteQueryPack, 123 "ValidateBundle": srv.ValidateBundle, 124 "GetBundle": srv.GetBundle, 125 "GetQueryPack": srv.GetQueryPack, 126 "GetFilters": srv.GetFilters, 127 "List": srv.List, 128 "DefaultPacks": srv.DefaultPacks, 129 }, 130 } 131 return ranger.NewRPCServer(&service) 132 } 133 134 type QueryHubServer struct { 135 handler QueryHub 136 allowUnknownFields bool 137 } 138 139 func (p *QueryHubServer) SetBundle(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 140 var req Bundle 141 var err error 142 143 md, ok := metadata.FromIncomingContext(ctx) 144 if !ok { 145 return nil, errors.New("could not access header") 146 } 147 148 switch md.First("Content-Type") { 149 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 150 err = pb.Unmarshal(*reqBytes, &req) 151 default: 152 // handle case of empty object 153 if len(*reqBytes) > 0 { 154 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 155 } 156 } 157 158 if err != nil { 159 return nil, err 160 } 161 return p.handler.SetBundle(ctx, &req) 162 } 163 func (p *QueryHubServer) DeleteQueryPack(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 164 var req Mrn 165 var err error 166 167 md, ok := metadata.FromIncomingContext(ctx) 168 if !ok { 169 return nil, errors.New("could not access header") 170 } 171 172 switch md.First("Content-Type") { 173 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 174 err = pb.Unmarshal(*reqBytes, &req) 175 default: 176 // handle case of empty object 177 if len(*reqBytes) > 0 { 178 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 179 } 180 } 181 182 if err != nil { 183 return nil, err 184 } 185 return p.handler.DeleteQueryPack(ctx, &req) 186 } 187 func (p *QueryHubServer) ValidateBundle(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 188 var req Bundle 189 var err error 190 191 md, ok := metadata.FromIncomingContext(ctx) 192 if !ok { 193 return nil, errors.New("could not access header") 194 } 195 196 switch md.First("Content-Type") { 197 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 198 err = pb.Unmarshal(*reqBytes, &req) 199 default: 200 // handle case of empty object 201 if len(*reqBytes) > 0 { 202 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 203 } 204 } 205 206 if err != nil { 207 return nil, err 208 } 209 return p.handler.ValidateBundle(ctx, &req) 210 } 211 func (p *QueryHubServer) GetBundle(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 212 var req Mrn 213 var err error 214 215 md, ok := metadata.FromIncomingContext(ctx) 216 if !ok { 217 return nil, errors.New("could not access header") 218 } 219 220 switch md.First("Content-Type") { 221 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 222 err = pb.Unmarshal(*reqBytes, &req) 223 default: 224 // handle case of empty object 225 if len(*reqBytes) > 0 { 226 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 227 } 228 } 229 230 if err != nil { 231 return nil, err 232 } 233 return p.handler.GetBundle(ctx, &req) 234 } 235 func (p *QueryHubServer) GetQueryPack(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 236 var req Mrn 237 var err error 238 239 md, ok := metadata.FromIncomingContext(ctx) 240 if !ok { 241 return nil, errors.New("could not access header") 242 } 243 244 switch md.First("Content-Type") { 245 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 246 err = pb.Unmarshal(*reqBytes, &req) 247 default: 248 // handle case of empty object 249 if len(*reqBytes) > 0 { 250 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 251 } 252 } 253 254 if err != nil { 255 return nil, err 256 } 257 return p.handler.GetQueryPack(ctx, &req) 258 } 259 func (p *QueryHubServer) GetFilters(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 260 var req Mrn 261 var err error 262 263 md, ok := metadata.FromIncomingContext(ctx) 264 if !ok { 265 return nil, errors.New("could not access header") 266 } 267 268 switch md.First("Content-Type") { 269 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 270 err = pb.Unmarshal(*reqBytes, &req) 271 default: 272 // handle case of empty object 273 if len(*reqBytes) > 0 { 274 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 275 } 276 } 277 278 if err != nil { 279 return nil, err 280 } 281 return p.handler.GetFilters(ctx, &req) 282 } 283 func (p *QueryHubServer) List(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 284 var req ListReq 285 var err error 286 287 md, ok := metadata.FromIncomingContext(ctx) 288 if !ok { 289 return nil, errors.New("could not access header") 290 } 291 292 switch md.First("Content-Type") { 293 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 294 err = pb.Unmarshal(*reqBytes, &req) 295 default: 296 // handle case of empty object 297 if len(*reqBytes) > 0 { 298 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 299 } 300 } 301 302 if err != nil { 303 return nil, err 304 } 305 return p.handler.List(ctx, &req) 306 } 307 func (p *QueryHubServer) DefaultPacks(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 308 var req DefaultPacksReq 309 var err error 310 311 md, ok := metadata.FromIncomingContext(ctx) 312 if !ok { 313 return nil, errors.New("could not access header") 314 } 315 316 switch md.First("Content-Type") { 317 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 318 err = pb.Unmarshal(*reqBytes, &req) 319 default: 320 // handle case of empty object 321 if len(*reqBytes) > 0 { 322 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 323 } 324 } 325 326 if err != nil { 327 return nil, err 328 } 329 return p.handler.DefaultPacks(ctx, &req) 330 } 331 332 // service interface definition 333 334 type QueryConductor interface { 335 Assign(context.Context, *Assignment) (*Empty, error) 336 Unassign(context.Context, *Assignment) (*Empty, error) 337 SetProps(context.Context, *PropsReq) (*Empty, error) 338 Resolve(context.Context, *ResolveReq) (*ResolvedPack, error) 339 StoreResults(context.Context, *StoreResultsReq) (*Empty, error) 340 GetReport(context.Context, *EntityDataRequest) (*Report, error) 341 SynchronizeAssets(context.Context, *SynchronizeAssetsReq) (*SynchronizeAssetsResp, error) 342 } 343 344 // client implementation 345 346 type QueryConductorClient struct { 347 ranger.Client 348 httpclient ranger.HTTPClient 349 prefix string 350 } 351 352 func NewQueryConductorClient(addr string, client ranger.HTTPClient, plugins ...ranger.ClientPlugin) (*QueryConductorClient, error) { 353 base, err := url.Parse(ranger.SanitizeUrl(addr)) 354 if err != nil { 355 return nil, err 356 } 357 358 u, err := url.Parse("./QueryConductor") 359 if err != nil { 360 return nil, err 361 } 362 363 serviceClient := &QueryConductorClient{ 364 httpclient: client, 365 prefix: base.ResolveReference(u).String(), 366 } 367 serviceClient.AddPlugins(plugins...) 368 return serviceClient, nil 369 } 370 func (c *QueryConductorClient) Assign(ctx context.Context, in *Assignment) (*Empty, error) { 371 out := new(Empty) 372 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/Assign"}, ""), in, out) 373 return out, err 374 } 375 func (c *QueryConductorClient) Unassign(ctx context.Context, in *Assignment) (*Empty, error) { 376 out := new(Empty) 377 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/Unassign"}, ""), in, out) 378 return out, err 379 } 380 func (c *QueryConductorClient) SetProps(ctx context.Context, in *PropsReq) (*Empty, error) { 381 out := new(Empty) 382 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/SetProps"}, ""), in, out) 383 return out, err 384 } 385 func (c *QueryConductorClient) Resolve(ctx context.Context, in *ResolveReq) (*ResolvedPack, error) { 386 out := new(ResolvedPack) 387 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/Resolve"}, ""), in, out) 388 return out, err 389 } 390 func (c *QueryConductorClient) StoreResults(ctx context.Context, in *StoreResultsReq) (*Empty, error) { 391 out := new(Empty) 392 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/StoreResults"}, ""), in, out) 393 return out, err 394 } 395 func (c *QueryConductorClient) GetReport(ctx context.Context, in *EntityDataRequest) (*Report, error) { 396 out := new(Report) 397 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/GetReport"}, ""), in, out) 398 return out, err 399 } 400 func (c *QueryConductorClient) SynchronizeAssets(ctx context.Context, in *SynchronizeAssetsReq) (*SynchronizeAssetsResp, error) { 401 out := new(SynchronizeAssetsResp) 402 err := c.DoClientRequest(ctx, c.httpclient, strings.Join([]string{c.prefix, "/SynchronizeAssets"}, ""), in, out) 403 return out, err 404 } 405 406 // server implementation 407 408 type QueryConductorServerOption func(s *QueryConductorServer) 409 410 func WithUnknownFieldsForQueryConductorServer() QueryConductorServerOption { 411 return func(s *QueryConductorServer) { 412 s.allowUnknownFields = true 413 } 414 } 415 416 func NewQueryConductorServer(handler QueryConductor, opts ...QueryConductorServerOption) http.Handler { 417 srv := &QueryConductorServer{ 418 handler: handler, 419 } 420 421 for i := range opts { 422 opts[i](srv) 423 } 424 425 service := ranger.Service{ 426 Name: "QueryConductor", 427 Methods: map[string]ranger.Method{ 428 "Assign": srv.Assign, 429 "Unassign": srv.Unassign, 430 "SetProps": srv.SetProps, 431 "Resolve": srv.Resolve, 432 "StoreResults": srv.StoreResults, 433 "GetReport": srv.GetReport, 434 "SynchronizeAssets": srv.SynchronizeAssets, 435 }, 436 } 437 return ranger.NewRPCServer(&service) 438 } 439 440 type QueryConductorServer struct { 441 handler QueryConductor 442 allowUnknownFields bool 443 } 444 445 func (p *QueryConductorServer) Assign(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 446 var req Assignment 447 var err error 448 449 md, ok := metadata.FromIncomingContext(ctx) 450 if !ok { 451 return nil, errors.New("could not access header") 452 } 453 454 switch md.First("Content-Type") { 455 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 456 err = pb.Unmarshal(*reqBytes, &req) 457 default: 458 // handle case of empty object 459 if len(*reqBytes) > 0 { 460 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 461 } 462 } 463 464 if err != nil { 465 return nil, err 466 } 467 return p.handler.Assign(ctx, &req) 468 } 469 func (p *QueryConductorServer) Unassign(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 470 var req Assignment 471 var err error 472 473 md, ok := metadata.FromIncomingContext(ctx) 474 if !ok { 475 return nil, errors.New("could not access header") 476 } 477 478 switch md.First("Content-Type") { 479 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 480 err = pb.Unmarshal(*reqBytes, &req) 481 default: 482 // handle case of empty object 483 if len(*reqBytes) > 0 { 484 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 485 } 486 } 487 488 if err != nil { 489 return nil, err 490 } 491 return p.handler.Unassign(ctx, &req) 492 } 493 func (p *QueryConductorServer) SetProps(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 494 var req PropsReq 495 var err error 496 497 md, ok := metadata.FromIncomingContext(ctx) 498 if !ok { 499 return nil, errors.New("could not access header") 500 } 501 502 switch md.First("Content-Type") { 503 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 504 err = pb.Unmarshal(*reqBytes, &req) 505 default: 506 // handle case of empty object 507 if len(*reqBytes) > 0 { 508 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 509 } 510 } 511 512 if err != nil { 513 return nil, err 514 } 515 return p.handler.SetProps(ctx, &req) 516 } 517 func (p *QueryConductorServer) Resolve(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 518 var req ResolveReq 519 var err error 520 521 md, ok := metadata.FromIncomingContext(ctx) 522 if !ok { 523 return nil, errors.New("could not access header") 524 } 525 526 switch md.First("Content-Type") { 527 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 528 err = pb.Unmarshal(*reqBytes, &req) 529 default: 530 // handle case of empty object 531 if len(*reqBytes) > 0 { 532 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 533 } 534 } 535 536 if err != nil { 537 return nil, err 538 } 539 return p.handler.Resolve(ctx, &req) 540 } 541 func (p *QueryConductorServer) StoreResults(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 542 var req StoreResultsReq 543 var err error 544 545 md, ok := metadata.FromIncomingContext(ctx) 546 if !ok { 547 return nil, errors.New("could not access header") 548 } 549 550 switch md.First("Content-Type") { 551 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 552 err = pb.Unmarshal(*reqBytes, &req) 553 default: 554 // handle case of empty object 555 if len(*reqBytes) > 0 { 556 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 557 } 558 } 559 560 if err != nil { 561 return nil, err 562 } 563 return p.handler.StoreResults(ctx, &req) 564 } 565 func (p *QueryConductorServer) GetReport(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 566 var req EntityDataRequest 567 var err error 568 569 md, ok := metadata.FromIncomingContext(ctx) 570 if !ok { 571 return nil, errors.New("could not access header") 572 } 573 574 switch md.First("Content-Type") { 575 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 576 err = pb.Unmarshal(*reqBytes, &req) 577 default: 578 // handle case of empty object 579 if len(*reqBytes) > 0 { 580 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 581 } 582 } 583 584 if err != nil { 585 return nil, err 586 } 587 return p.handler.GetReport(ctx, &req) 588 } 589 func (p *QueryConductorServer) SynchronizeAssets(ctx context.Context, reqBytes *[]byte) (pb.Message, error) { 590 var req SynchronizeAssetsReq 591 var err error 592 593 md, ok := metadata.FromIncomingContext(ctx) 594 if !ok { 595 return nil, errors.New("could not access header") 596 } 597 598 switch md.First("Content-Type") { 599 case "application/protobuf", "application/octet-stream", "application/grpc+proto": 600 err = pb.Unmarshal(*reqBytes, &req) 601 default: 602 // handle case of empty object 603 if len(*reqBytes) > 0 { 604 err = jsonpb.UnmarshalOptions{DiscardUnknown: true}.Unmarshal(*reqBytes, &req) 605 } 606 } 607 608 if err != nil { 609 return nil, err 610 } 611 return p.handler.SynchronizeAssets(ctx, &req) 612 }