swagger:operation POST /1.0/network-integrations/{integration} network-integrations network_integration_post Rename the network integration Renames the network integration. --- produces: - application/json parameters: - in: path name: integration description: Integration name
(d *Daemon, r *http.Request)
| 830 | // "500": |
| 831 | // $ref: "#/responses/InternalServerError" |
| 832 | func networkIntegrationPost(d *Daemon, r *http.Request) response.Response { |
| 833 | s := d.State() |
| 834 | |
| 835 | // Get the integration name. |
| 836 | integrationName, err := pathVar(r, "integration") |
| 837 | if err != nil { |
| 838 | return response.SmartError(err) |
| 839 | } |
| 840 | |
| 841 | // Decode the request. |
| 842 | req := api.NetworkIntegrationPost{} |
| 843 | |
| 844 | err = json.NewDecoder(r.Body).Decode(&req) |
| 845 | if err != nil { |
| 846 | return response.BadRequest(err) |
| 847 | } |
| 848 | |
| 849 | // Quick checks. |
| 850 | err = validate.IsAPIName(req.Name, false) |
| 851 | if err != nil { |
| 852 | return response.BadRequest(fmt.Errorf("Invalid network integration name: %w", err)) |
| 853 | } |
| 854 | |
| 855 | // Rename the DB record. |
| 856 | err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error { |
| 857 | err := dbCluster.RenameNetworkIntegration(ctx, tx.Tx(), integrationName, req.Name) |
| 858 | if err != nil { |
| 859 | return err |
| 860 | } |
| 861 | |
| 862 | return nil |
| 863 | }) |
| 864 | if err != nil { |
| 865 | return response.SmartError(err) |
| 866 | } |
| 867 | |
| 868 | // Rename the integration in the auth backend. |
| 869 | err = s.Authorizer.RenameNetworkIntegration(r.Context(), integrationName, req.Name) |
| 870 | if err != nil { |
| 871 | logger.Error("Failed to remove network integration from authorizer", logger.Ctx{"name": integrationName, "error": err}) |
| 872 | } |
| 873 | |
| 874 | // Emit the lifecycle event. |
| 875 | s.Events.SendLifecycle(api.ProjectDefaultName, lifecycle.NetworkIntegrationDeleted.Event(req.Name, request.CreateRequestor(r), logger.Ctx{"old_name": integrationName})) |
| 876 | |
| 877 | return response.EmptySyncResponse |
| 878 | } |
| 879 | |
| 880 | // networkIntegrationValidate validates the configuration keys/values for network integration. |
| 881 | func networkIntegrationValidate(integrationType string, inUse bool, oldConfig map[string]string, config map[string]string) error { |
nothing calls this directly
no test coverage detected
searching dependent graphs…