Procházet zdrojové kódy

added vanity name, fixed deletion revision

Stefan McShane před 3 roky
rodič
revize
c6bd47ac7c

+ 2 - 1
api/server/authz/api_contract.go

@@ -45,6 +45,7 @@ func (n *APIContractRevisionMiddleware) ServeHTTP(w http.ResponseWriter, r *http
 		return
 	}
 
+	fmt.Println("STEFAN", uid)
 	rev, err := n.config.Repo.APIContractRevisioner().Get(ctx, uid)
 	if err != nil {
 		if err == gorm.ErrRecordNotFound {
@@ -56,7 +57,7 @@ func (n *APIContractRevisionMiddleware) ServeHTTP(w http.ResponseWriter, r *http
 		apierrors.HandleAPIError(n.config.Logger, n.config.Alerter, w, r, apierrors.NewErrInternal(err), true)
 		return
 	}
-	fmt.Println("STEFAN", rev, uid)
+	fmt.Println("STEFANREV", rev)
 
 	r = r.Clone(NewAPIContractRevisionContext(ctx, rev))
 	n.next.ServeHTTP(w, r)

+ 6 - 6
api/server/handlers/api_contract/delete.go

@@ -1,9 +1,11 @@
 package api_contract
 
 import (
+	"errors"
 	"fmt"
 	"net/http"
 
+	"github.com/google/uuid"
 	"github.com/porter-dev/porter/api/server/handlers"
 	"github.com/porter-dev/porter/api/server/shared"
 	"github.com/porter-dev/porter/api/server/shared/apierrors"
@@ -28,14 +30,12 @@ func NewAPIContractRevisionDeleteHandler(
 
 // ServeHTTP returns deletes a given project and cluster's contract revision
 func (c *APIContractRevisionDeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-	proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
-	revision, _ := r.Context().Value(types.APIContractRevisionScope).(*models.APIContractRevision)
-
 	ctx := r.Context()
-	fmt.Println("STEFAN", revision)
+	proj, _ := ctx.Value(types.ProjectScope).(*models.Project)
+	revision := ctx.Value(types.APIContractRevisionScope).(models.APIContractRevision)
 
-	if revision == nil {
-		e := fmt.Errorf("nil revision: %s", r.URL.Path)
+	if revision.ID == uuid.Nil {
+		e := errors.New("nil revision provided in path")
 		c.HandleAPIError(w, r, apierrors.NewErrInternal(e))
 		return
 	}

+ 1 - 1
api/server/handlers/api_contract/update.go

@@ -108,5 +108,5 @@ func (c *APIContractUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Requ
 	}
 
 	w.WriteHeader(http.StatusCreated)
-	c.WriteResult(w, r, revision)
+	c.WriteResult(w, r, revision.Msg)
 }

+ 3 - 0
api/types/cluster.go

@@ -18,6 +18,9 @@ type Cluster struct {
 	// Name of the cluster
 	Name string `json:"name"`
 
+	// VanityName is the display name of the cluster
+	VanityName string `json:"vanity_name"`
+
 	// Server endpoint for the cluster
 	Server string `json:"server"`
 

+ 1 - 0
internal/models/cluster.go

@@ -120,6 +120,7 @@ func (c *Cluster) ToClusterType() *types.Cluster {
 		ID:                                c.ID,
 		ProjectID:                         c.ProjectID,
 		Name:                              c.Name,
+		VanityName:                        c.VanityName,
 		Server:                            c.Server,
 		Service:                           serv,
 		AgentIntegrationEnabled:           c.AgentIntegrationEnabled,

+ 6 - 8
internal/repository/gorm/api_contract.go

@@ -3,6 +3,7 @@ package gorm
 import (
 	"context"
 	"errors"
+	"fmt"
 
 	"github.com/google/uuid"
 	"github.com/porter-dev/porter/internal/models"
@@ -78,14 +79,11 @@ func (cr APIContractRepository) Get(ctx context.Context, revisionID uuid.UUID) (
 		return models.APIContractRevision{}, errors.New("invalid contract revision id supplied")
 	}
 
-	rev, ok := cr.db.Get(revisionID.String())
-	if !ok {
-		return models.APIContractRevision{}, errors.New("no contract revision found for that id")
-	}
-
-	if revision, ok := rev.(models.APIContractRevision); ok {
-		return revision, nil
+	var acr models.APIContractRevision
+	tx := cr.db.Find(&acr, "id = ?", revisionID.String())
+	if tx.Error != nil {
+		return models.APIContractRevision{}, fmt.Errorf("no contract revision found for id %s: %w", revisionID, tx.Error)
 	}
 
-	return models.APIContractRevision{}, errors.New("unable to convert response to contract revision")
+	return acr, nil
 }