ソースを参照

fix more merge conflicts, compile issues

Alexander Belanger 4 年 前
コミット
d19e330d9f

+ 4 - 0
api/server/shared/config/config.go

@@ -5,6 +5,7 @@ import (
 	"github.com/gorilla/websocket"
 	"github.com/porter-dev/porter/api/server/shared/apierrors/alerter"
 	"github.com/porter-dev/porter/api/server/shared/config/env"
+	"github.com/porter-dev/porter/internal/analytics"
 	"github.com/porter-dev/porter/internal/auth/token"
 	"github.com/porter-dev/porter/internal/helm/urlcache"
 	"github.com/porter-dev/porter/internal/kubernetes"
@@ -81,6 +82,9 @@ type Config struct {
 
 	// DB is the gorm DB instance
 	DB *gorm.DB
+
+	// AnalyticsClient if Segment analytics reporting is enabled on the API instance
+	AnalyticsClient analytics.AnalyticsSegmentClient
 }
 
 type ConfigLoader interface {

+ 3 - 0
api/server/shared/config/loader/loader.go

@@ -10,6 +10,7 @@ import (
 	"github.com/porter-dev/porter/api/server/shared/config"
 	"github.com/porter-dev/porter/api/server/shared/config/env"
 	"github.com/porter-dev/porter/internal/adapter"
+	"github.com/porter-dev/porter/internal/analytics"
 	"github.com/porter-dev/porter/internal/auth/sessionstore"
 	"github.com/porter-dev/porter/internal/auth/token"
 	"github.com/porter-dev/porter/internal/helm/urlcache"
@@ -190,6 +191,8 @@ func (e *EnvConfigLoader) LoadConfig() (res *config.Config, err error) {
 
 	res.IngressAgent = ingressAgent
 
+	res.AnalyticsClient = analytics.InitializeAnalyticsSegmentClient(sc.SegmentClientKey, res.Logger)
+
 	return res, nil
 }
 

+ 6 - 4
cmd/app/main.go

@@ -9,6 +9,8 @@ import (
 
 	"github.com/porter-dev/porter/api/server/router"
 	"github.com/porter-dev/porter/api/server/shared/config/loader"
+	"github.com/porter-dev/porter/internal/adapter"
+	"github.com/porter-dev/porter/internal/kubernetes/provisioner"
 )
 
 // Version will be linked by an ldflag during build
@@ -34,18 +36,18 @@ func main() {
 	}
 
 	if config.RedisConf.Enabled {
-		redis, err := adapter.NewRedisClient(&appConf.Redis)
+		redis, err := adapter.NewRedisClient(config.RedisConf)
 
 		if err != nil {
-			logger.Fatal().Err(err).Msg("")
+			log.Fatal("Redis connection failed: ", err)
 			return
 		}
 
-		prov.InitGlobalStream(redis)
+		provisioner.InitGlobalStream(redis)
 
 		errorChan := make(chan error)
 
-		go prov.GlobalStreamListener(redis, *repo, a.AnalyticsClient, errorChan)
+		go provisioner.GlobalStreamListener(redis, config.Repo, config.AnalyticsClient, errorChan)
 	}
 
 	appRouter := router.NewAPIRouter(config)

+ 7 - 7
internal/analytics/tracks.go

@@ -1,7 +1,7 @@
 package analytics
 
 import (
-	"github.com/porter-dev/porter/internal/models"
+	"github.com/porter-dev/porter/api/types"
 	segment "gopkg.in/segmentio/analytics-go.v3"
 )
 
@@ -133,7 +133,7 @@ type ClusterProvisioningStartTrackOpts struct {
 	// note that this is a project-scoped track, since the cluster has not been created yet
 	*ProjectScopedTrackOpts
 
-	ClusterType models.InfraKind
+	ClusterType types.InfraKind
 	InfraID     uint
 }
 
@@ -156,7 +156,7 @@ type ClusterProvisioningErrorTrackOpts struct {
 	// note that this is a project-scoped track, since the cluster has not been created yet
 	*ProjectScopedTrackOpts
 
-	ClusterType models.InfraKind
+	ClusterType types.InfraKind
 	InfraID     uint
 }
 
@@ -178,7 +178,7 @@ func ClusterProvisioningErrorTrack(opts *ClusterProvisioningErrorTrackOpts) segm
 type ClusterProvisioningSuccessTrackOpts struct {
 	*ClusterScopedTrackOpts
 
-	ClusterType models.InfraKind
+	ClusterType types.InfraKind
 	InfraID     uint
 }
 
@@ -381,7 +381,7 @@ type RegistryProvisioningStartTrackOpts struct {
 	// note that this is a project-scoped track, since the registry has not been created yet
 	*ProjectScopedTrackOpts
 
-	RegistryType models.InfraKind
+	RegistryType types.InfraKind
 	InfraID      uint
 }
 
@@ -404,7 +404,7 @@ type RegistryProvisioningErrorTrackOpts struct {
 	// note that this is a project-scoped track, since the registry has not been created yet
 	*ProjectScopedTrackOpts
 
-	RegistryType models.InfraKind
+	RegistryType types.InfraKind
 	InfraID      uint
 }
 
@@ -426,7 +426,7 @@ func RegistryProvisioningErrorTrack(opts *RegistryProvisioningErrorTrackOpts) se
 type RegistryProvisioningSuccessTrackOpts struct {
 	*RegistryScopedTrackOpts
 
-	RegistryType models.InfraKind
+	RegistryType types.InfraKind
 	InfraID      uint
 }
 

+ 0 - 6
internal/helm/agent.go

@@ -4,13 +4,7 @@ import (
 	"fmt"
 
 	"github.com/pkg/errors"
-<<<<<<< HEAD
-=======
 	"github.com/porter-dev/porter/internal/helm/loader"
-	"github.com/porter-dev/porter/internal/kubernetes"
-	"github.com/porter-dev/porter/internal/models"
-	"github.com/porter-dev/porter/internal/repository"
->>>>>>> master
 	"golang.org/x/oauth2"
 	"helm.sh/helm/v3/pkg/action"
 	"helm.sh/helm/v3/pkg/chart"

+ 2 - 2
internal/helm/agent_test.go

@@ -224,7 +224,7 @@ func TestGetReleases(t *testing.T) {
 		// namespace, so we have to reset the namespace of the storage driver
 		agent.ActionConfig.Releases.Driver.(*driver.Memory).SetNamespace(tc.namespace)
 
-		rel, err := agent.GetRelease(tc.getName, tc.getVersion)
+		rel, err := agent.GetRelease(tc.getName, tc.getVersion, false)
 
 		if err != nil {
 			t.Errorf("%v", err)
@@ -334,7 +334,7 @@ func TestRollbackRelease(t *testing.T) {
 			t.Errorf("%v", err)
 		}
 
-		rel, err := agent.GetRelease(tc.getName, tc.getVersion)
+		rel, err := agent.GetRelease(tc.getName, tc.getVersion, false)
 
 		if err != nil {
 			t.Errorf("%v", err)

+ 7 - 8
internal/kubernetes/provisioner/global_stream.go

@@ -10,7 +10,6 @@ import (
 
 	"github.com/aws/aws-sdk-go/service/ecr"
 	"github.com/porter-dev/porter/internal/analytics"
-	"github.com/porter-dev/porter/internal/repository"
 
 	redis "github.com/go-redis/redis/v8"
 
@@ -175,7 +174,7 @@ func GlobalStreamListener(
 							InfraID:                 infra.ID,
 						},
 					))
-				} else if kind == string(models.InfraEKS) {
+				} else if kind == string(types.InfraEKS) {
 					cluster := &models.Cluster{
 						AuthMechanism:    models.AWS,
 						ProjectID:        projID,
@@ -217,7 +216,7 @@ func GlobalStreamListener(
 							InfraID:                infra.ID,
 						},
 					))
-				} else if kind == string(models.InfraGCR) {
+				} else if kind == string(types.InfraGCR) {
 					reg := &models.Registry{
 						ProjectID:        projID,
 						GCPIntegrationID: infra.GCPIntegrationID,
@@ -245,7 +244,7 @@ func GlobalStreamListener(
 							InfraID:                 infra.ID,
 						},
 					))
-				} else if kind == string(models.InfraGKE) {
+				} else if kind == string(types.InfraGKE) {
 					cluster := &models.Cluster{
 						AuthMechanism:    models.GCP,
 						ProjectID:        projID,
@@ -287,7 +286,7 @@ func GlobalStreamListener(
 							InfraID:                infra.ID,
 						},
 					))
-				} else if kind == string(models.InfraDOCR) {
+				} else if kind == string(types.InfraDOCR) {
 					reg := &models.Registry{
 						ProjectID:       projID,
 						DOIntegrationID: infra.DOIntegrationID,
@@ -314,7 +313,7 @@ func GlobalStreamListener(
 							InfraID:                 infra.ID,
 						},
 					))
-				} else if kind == string(models.InfraDOKS) {
+				} else if kind == string(types.InfraDOKS) {
 					cluster := &models.Cluster{
 						AuthMechanism:   models.DO,
 						ProjectID:       projID,
@@ -372,7 +371,7 @@ func GlobalStreamListener(
 					continue
 				}
 
-				if infra.Kind == models.InfraDOKS || infra.Kind == models.InfraGKE || infra.Kind == models.InfraEKS {
+				if infra.Kind == types.InfraDOKS || infra.Kind == types.InfraGKE || infra.Kind == types.InfraEKS {
 					analyticsClient.Track(analytics.ClusterProvisioningErrorTrack(
 						&analytics.ClusterProvisioningErrorTrackOpts{
 							ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(infra.CreatedByUserID, infra.ProjectID),
@@ -380,7 +379,7 @@ func GlobalStreamListener(
 							InfraID:                infra.ID,
 						},
 					))
-				} else if infra.Kind == models.InfraDOCR || infra.Kind == models.InfraGCR || infra.Kind == models.InfraECR {
+				} else if infra.Kind == types.InfraDOCR || infra.Kind == types.InfraGCR || infra.Kind == types.InfraECR {
 					analyticsClient.Track(analytics.RegistryProvisioningErrorTrack(
 						&analytics.RegistryProvisioningErrorTrackOpts{
 							ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(infra.CreatedByUserID, infra.ProjectID),

+ 6 - 32
internal/repository/gorm/repository.go

@@ -5,7 +5,6 @@ import (
 	"gorm.io/gorm"
 )
 
-<<<<<<< HEAD
 type GormRepository struct {
 	user                      repository.UserRepository
 	session                   repository.SessionRepository
@@ -31,6 +30,7 @@ type GormRepository struct {
 	githubAppOAuthIntegration repository.GithubAppOAuthIntegrationRepository
 	slackIntegration          repository.SlackIntegrationRepository
 	notificationConfig        repository.NotificationConfigRepository
+	event                     repository.EventRepository
 }
 
 func (t *GormRepository) User() repository.UserRepository {
@@ -129,6 +129,10 @@ func (t *GormRepository) NotificationConfig() repository.NotificationConfigRepos
 	return t.notificationConfig
 }
 
+func (t *GormRepository) Event() repository.EventRepository {
+	return t.event
+}
+
 // NewRepository returns a Repository which persists users in memory
 // and accepts a parameter that can trigger read/write errors
 func NewRepository(db *gorm.DB, key *[32]byte) repository.Repository {
@@ -157,36 +161,6 @@ func NewRepository(db *gorm.DB, key *[32]byte) repository.Repository {
 		githubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(db),
 		slackIntegration:          NewSlackIntegrationRepository(db, key),
 		notificationConfig:        NewNotificationConfigRepository(db),
-=======
-// NewRepository returns a Repository which uses
-// gorm.DB for querying the database
-func NewRepository(db *gorm.DB, key *[32]byte) *repository.Repository {
-	return &repository.Repository{
-		User:                      NewUserRepository(db),
-		Session:                   NewSessionRepository(db),
-		Project:                   NewProjectRepository(db),
-		Release:                   NewReleaseRepository(db),
-		GitRepo:                   NewGitRepoRepository(db, key),
-		Cluster:                   NewClusterRepository(db, key),
-		HelmRepo:                  NewHelmRepoRepository(db, key),
-		Registry:                  NewRegistryRepository(db, key),
-		Infra:                     NewInfraRepository(db, key),
-		GitActionConfig:           NewGitActionConfigRepository(db),
-		Invite:                    NewInviteRepository(db),
-		AuthCode:                  NewAuthCodeRepository(db),
-		DNSRecord:                 NewDNSRecordRepository(db),
-		PWResetToken:              NewPWResetTokenRepository(db),
-		KubeIntegration:           NewKubeIntegrationRepository(db, key),
-		BasicIntegration:          NewBasicIntegrationRepository(db, key),
-		OIDCIntegration:           NewOIDCIntegrationRepository(db, key),
-		OAuthIntegration:          NewOAuthIntegrationRepository(db, key),
-		GCPIntegration:            NewGCPIntegrationRepository(db, key),
-		AWSIntegration:            NewAWSIntegrationRepository(db, key),
-		GithubAppInstallation:     NewGithubAppInstallationRepository(db),
-		GithubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(db),
-		SlackIntegration:          NewSlackIntegrationRepository(db, key),
-		NotificationConfig:        NewNotificationConfigRepository(db),
-		Event:                     NewEventRepository(db),
->>>>>>> master
+		event:                     NewEventRepository(db),
 	}
 }

+ 36 - 0
internal/repository/test/event.go

@@ -0,0 +1,36 @@
+package test
+
+import (
+	"github.com/porter-dev/porter/internal/models"
+	"github.com/porter-dev/porter/internal/repository"
+)
+
+type EventRepository struct{}
+
+func NewEventRepository(canQuery bool) repository.EventRepository {
+	return &EventRepository{}
+}
+
+func (n *EventRepository) CreateEventContainer(am *models.EventContainer) (*models.EventContainer, error) {
+	panic("not implemented") // TODO: Implement
+}
+
+func (n *EventRepository) CreateSubEvent(am *models.SubEvent) (*models.SubEvent, error) {
+	panic("not implemented") // TODO: Implement
+}
+
+func (n *EventRepository) ReadEventsByContainerID(id uint) ([]*models.SubEvent, error) {
+	panic("not implemented") // TODO: Implement
+}
+
+func (n *EventRepository) ReadEventContainer(id uint) (*models.EventContainer, error) {
+	panic("not implemented") // TODO: Implement
+}
+
+func (n *EventRepository) ReadSubEvent(id uint) (*models.SubEvent, error) {
+	panic("not implemented") // TODO: Implement
+}
+
+func (n *EventRepository) AppendEvent(container *models.EventContainer, event *models.SubEvent) error {
+	panic("not implemented") // TODO: Implement
+}

+ 6 - 0
internal/repository/test/repository.go

@@ -29,6 +29,7 @@ type TestRepository struct {
 	githubAppOAuthIntegration repository.GithubAppOAuthIntegrationRepository
 	slackIntegration          repository.SlackIntegrationRepository
 	notificationConfig        repository.NotificationConfigRepository
+	event                     repository.EventRepository
 }
 
 func (t *TestRepository) User() repository.UserRepository {
@@ -127,6 +128,10 @@ func (t *TestRepository) NotificationConfig() repository.NotificationConfigRepos
 	return t.notificationConfig
 }
 
+func (t *TestRepository) Event() repository.EventRepository {
+	return t.event
+}
+
 // NewRepository returns a Repository which persists users in memory
 // and accepts a parameter that can trigger read/write errors
 func NewRepository(canQuery bool, failingMethods ...string) repository.Repository {
@@ -155,5 +160,6 @@ func NewRepository(canQuery bool, failingMethods ...string) repository.Repositor
 		githubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(canQuery),
 		slackIntegration:          NewSlackIntegrationRepository(canQuery),
 		notificationConfig:        NewNotificationConfigRepository(canQuery),
+		event:                     NewEventRepository(canQuery),
 	}
 }