Przeglądaj źródła

update handlers and sentry

Alexander Belanger 4 lat temu
rodzic
commit
7b524d69d6

+ 13 - 0
api/client/api.go

@@ -7,6 +7,7 @@ import (
 	"io/ioutil"
 	"net/http"
 	"net/url"
+	"os"
 	"path/filepath"
 	"strings"
 	"time"
@@ -93,6 +94,8 @@ func (c *Client) postRequest(relPath string, data interface{}, response interfac
 		return nil
 	}
 
+	fmt.Println(string(strData))
+
 	req, err := http.NewRequest(
 		"POST",
 		fmt.Sprintf("%s/%s", c.BaseURL, relPath),
@@ -226,6 +229,16 @@ func (c *Client) getCookie() (*http.Cookie, error) {
 	return cookie.Cookie, nil
 }
 
+// retrieves single cookie from file
+func (c *Client) deleteCookie() error {
+	// if file does not exist, return no error
+	if _, err := os.Stat(c.CookieFilePath); os.IsNotExist(err) {
+		return nil
+	}
+
+	return os.Remove(c.CookieFilePath)
+}
+
 type TokenProjectID struct {
 	ProjectID uint `json:"project_id"`
 }

+ 8 - 1
api/client/user.go

@@ -39,13 +39,20 @@ func (c *Client) Login(ctx context.Context, req *types.LoginUserRequest) (*types
 
 // Logout logs the user out and deauthorizes the cookie-based session
 func (c *Client) Logout(ctx context.Context) error {
-	return c.postRequest(
+	err := c.postRequest(
 		fmt.Sprintf(
 			"/logout",
 		),
 		nil,
 		nil,
 	)
+
+	if err != nil {
+		return err
+	}
+
+	// remove the cookie, if it exists
+	return c.deleteCookie()
 }
 
 // CreateUser will create the user, authorize the user and grant them a cookie-based session

+ 2 - 1
api/server/handlers/cluster/create.go

@@ -120,6 +120,7 @@ func createClusterFromCandidate(
 	project *models.Project,
 	user *models.User,
 	candidate *models.ClusterCandidate,
+	clResolver *types.ClusterResolverAll,
 ) (*models.Cluster, *models.ClusterCandidate, error) {
 	// we query the repo again to get the decrypted version of the cluster candidate
 	cc, err := repo.Cluster().ReadClusterCandidate(project.ID, candidate.ID)
@@ -129,7 +130,7 @@ func createClusterFromCandidate(
 	}
 
 	cResolver := &resolver.CandidateResolver{
-		Resolver:           &types.ClusterResolverAll{},
+		Resolver:           clResolver,
 		ClusterCandidateID: cc.ID,
 		ProjectID:          project.ID,
 		UserID:             user.ID,

+ 1 - 1
api/server/handlers/cluster/create_candidate.go

@@ -59,7 +59,7 @@ func (c *CreateClusterCandidateHandler) ServeHTTP(w http.ResponseWriter, r *http
 		// if the ClusterCandidate does not have any actions to perform, create the Cluster
 		// automatically
 		if len(cc.Resolvers) == 0 {
-			_, cc, err = createClusterFromCandidate(c.Repo(), proj, user, cc)
+			_, cc, err = createClusterFromCandidate(c.Repo(), proj, user, cc, &types.ClusterResolverAll{})
 
 			if err != nil {
 				c.HandleAPIError(w, r, apierrors.NewErrInternal(err))

+ 1 - 1
api/server/handlers/cluster/resolve_candidate.go

@@ -45,7 +45,7 @@ func (c *ResolveClusterCandidateHandler) ServeHTTP(w http.ResponseWriter, r *htt
 		return
 	}
 
-	cluster, cc, err := createClusterFromCandidate(c.Repo(), proj, user, cc)
+	cluster, cc, err := createClusterFromCandidate(c.Repo(), proj, user, cc, request)
 
 	if err != nil {
 		c.HandleAPIError(w, r, apierrors.NewErrInternal(err))

+ 10 - 11
api/server/shared/apierrors/alerter/sentry.go

@@ -2,7 +2,6 @@ package alerter
 
 import (
 	"context"
-	"reflect"
 
 	"github.com/getsentry/sentry-go"
 )
@@ -32,15 +31,15 @@ func NewSentryAlerter(sentryDSN string) (*SentryAlerter, error) {
 }
 
 func (s *SentryAlerter) SendAlert(ctx context.Context, err error, data map[string]interface{}) {
-	s.client.CaptureEvent(&sentry.Event{
-		Message: err.Error(),
-		Extra:   data,
-		Exception: []sentry.Exception{
-			{
-				Value:      err.Error(),
-				Type:       reflect.TypeOf(err).String(),
-				Stacktrace: sentry.ExtractStacktrace(err),
-			},
+	scope := sentry.NewScope()
+
+	scope.SetExtras(data)
+
+	s.client.CaptureException(
+		err,
+		&sentry.EventHint{
+			Data: data,
 		},
-	}, nil, nil)
+		scope,
+	)
 }

+ 1 - 1
cli/cmd/connect/docr.go

@@ -81,7 +81,7 @@ Registry URL: `))
 func triggerDigitalOceanOAuth(client *api.Client, projectID uint) (*types.OAuthIntegration, error) {
 	var doAuth *types.OAuthIntegration
 
-	oauthURL := fmt.Sprintf("%s/oauth/projects/%d/digitalocean", client.BaseURL, projectID)
+	oauthURL := fmt.Sprintf("%s/projects/%d/oauth/digitalocean", client.BaseURL, projectID)
 
 	fmt.Printf("Please visit %s in your browser to connect to Digital Ocean (it should open automatically).", oauthURL)
 	utils.OpenBrowser(oauthURL)

+ 1 - 1
dashboard/src/components/image-selector/ImageList.tsx

@@ -182,7 +182,7 @@ export default class ImageList extends Component<PropsType, StateType> {
       let icon =
         integrationList[image.kind] && integrationList[image.kind].icon;
       if (!icon) {
-        icon = integrationList["docker"].icon;
+        icon = integrationList["dockerhub"].icon;
       }
       return (
         <ImageItem

+ 2 - 2
dashboard/src/components/image-selector/ImageSelector.tsx

@@ -56,7 +56,7 @@ export default class ImageSelector extends Component<PropsType, StateType> {
       let icon =
         integrationList[image.kind] && integrationList[image.kind].icon;
       if (!icon) {
-        icon = integrationList["docker"].icon;
+        icon = integrationList["dockerhub"].icon;
       }
       return (
         <ImageItem
@@ -85,7 +85,7 @@ export default class ImageSelector extends Component<PropsType, StateType> {
         integrationList[clickedImage.kind] &&
         integrationList[clickedImage.kind].icon;
       if (!icon) {
-        icon = integrationList["docker"].icon;
+        icon = integrationList["dockerhub"].icon;
       }
     } else if (selectedImageUrl && selectedImageUrl !== "") {
       icon = edit;

+ 1 - 1
dashboard/src/components/repo-selector/ActionDetails.tsx

@@ -70,7 +70,7 @@ export default class ActionDetails extends Component<PropsType, StateType> {
         integrationList[registry.service] &&
         integrationList[registry.service].icon;
       if (!icon) {
-        icon = integrationList["docker"].icon;
+        icon = integrationList["dockerhub"].icon;
       }
       return (
         <RegistryItem