MCPcopy
hub / github.com/lxc/incus / networkIntegrationGet

Function networkIntegrationGet

cmd/incusd/network_integrations.go:502–597  ·  view source on GitHub ↗

swagger:operation GET /1.0/network-integrations/{integration} network-integrations network_integration_get Get the network integration Gets a specific network integration. --- produces: - application/json parameters: - in: path name: integration description: Integration name

(d *Daemon, r *http.Request)

Source from the content-addressed store, hash-verified

500// "500":
501// $ref: "#/responses/InternalServerError"
502func networkIntegrationGet(d *Daemon, r *http.Request) response.Response {
503 s := d.State()
504
505 // Get the integration name.
506 integrationName, err := pathVar(r, "integration")
507 if err != nil {
508 return response.SmartError(err)
509 }
510
511 // Network integrations aren't project aware, we only load the per-project data to apply name restrictions.
512 projectName := request.ProjectParam(r)
513
514 // Get the integration.
515 var info *api.NetworkIntegration
516
517 err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error {
518 // Get the project.
519 dbProject, err := dbCluster.GetProject(ctx, tx.Tx(), projectName)
520 if err != nil {
521 return fmt.Errorf("Failed to load network restrictions from project %q: %w", projectName, err)
522 }
523
524 p, err := dbProject.ToAPI(ctx, tx.Tx())
525 if err != nil {
526 return fmt.Errorf("Failed to load network restrictions from project %q: %w", projectName, err)
527 }
528
529 // Filter for project restrictions.
530 if !project.NetworkIntegrationAllowed(p.Config, integrationName) {
531 return nil
532 }
533
534 // Get the integration.
535 dbRecord, err := dbCluster.GetNetworkIntegration(ctx, tx.Tx(), integrationName)
536 if err != nil {
537 return err
538 }
539
540 info, err = dbRecord.ToAPI(ctx, tx.Tx())
541 if err != nil {
542 return err
543 }
544
545 // Check if the user should see the configuration.
546 err = s.Authorizer.CheckPermission(r.Context(), r, auth.ObjectNetworkIntegration(info.Name), auth.EntitlementCanEdit)
547 if err != nil {
548 info.Config = map[string]string{}
549 }
550
551 // Add UsedBy field.
552 integrationID := dbRecord.ID
553 allPeers, err := dbCluster.GetNetworkPeers(ctx, tx.Tx()) // Fetch all peers
554 if err != nil {
555 return fmt.Errorf("Failed to load network peers: %w", err)
556 }
557
558 usedBy := []string{}
559 for _, peer := range allPeers {

Callers

nothing calls this directly

Calls 15

WritableMethod · 0.95
SmartErrorFunction · 0.92
ProjectParamFunction · 0.92
ObjectNetworkIntegrationFunction · 0.92
NewURLFunction · 0.92
NotFoundFunction · 0.92
SyncResponseETagFunction · 0.92
pathVarFunction · 0.85
ContextMethod · 0.80
TxMethod · 0.80
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…