Skip to content

Commit

Permalink
undo unintended changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen committed May 1, 2024
1 parent 87310ea commit fe70784
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 32 deletions.
3 changes: 2 additions & 1 deletion api/server/handlers/oauth_callback/digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func (p *OAuthCallbackDOHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
oauthInt.PopulateTargetMetadata()

// create the oauth integration first
oauthInt, err = p.Repo().OAuthIntegration().CreateOAuthIntegration(r.Context(), oauthInt)
oauthInt, err = p.Repo().OAuthIntegration().CreateOAuthIntegration(oauthInt)

if err != nil {
p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
return
Expand Down
4 changes: 3 additions & 1 deletion api/server/handlers/oauth_callback/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (p *OAuthCallbackGitlabHandler) ServeHTTP(w http.ResponseWriter, r *http.Re
ProjectID: projID,
}

oauthInt, err = p.Repo().OAuthIntegration().CreateOAuthIntegration(r.Context(), oauthInt)
oauthInt, err = p.Repo().OAuthIntegration().CreateOAuthIntegration(oauthInt)

if err != nil {
p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
return
Expand All @@ -107,6 +108,7 @@ func (p *OAuthCallbackGitlabHandler) ServeHTTP(w http.ResponseWriter, r *http.Re

// create the oauth integration first
_, err = p.Repo().GitlabAppOAuthIntegration().CreateGitlabAppOAuthIntegration(giOAuthInt)

if err != nil {
p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
return
Expand Down
4 changes: 2 additions & 2 deletions cmd/migrate/keyrotate/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keyrotate_test

import (
"context"
"os"
"testing"
"time"
Expand Down Expand Up @@ -81,6 +80,7 @@ func setupTestEnv(tester *tester, t *testing.T) {
&ints.RegTokenCache{},
&ints.HelmRepoTokenCache{},
)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func initOAuthIntegration(tester *tester, t *testing.T) {
UserID: tester.initUsers[0].ID,
}

oauth, err := tester.repo.OAuthIntegration().CreateOAuthIntegration(context.Background(), oauth)
oauth, err := tester.repo.OAuthIntegration().CreateOAuthIntegration(oauth)
if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down
4 changes: 1 addition & 3 deletions dashboard/src/main/home/app-dashboard/apps/Apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,7 @@ const Apps: React.FC = () => {
Delete Environment
</Button>
) : (
<PorterLink
to={`/api/projects/${currentProject?.id}/oauth/upstash`}
>
<PorterLink to="/apps/new/app">
<Button
onClick={async () => {
await updateAppStep({ step: "stack-launch-start" });
Expand Down
30 changes: 14 additions & 16 deletions internal/repository/gorm/auth.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package gorm

import (
"context"

"github.com/porter-dev/porter/internal/encryption"
"github.com/porter-dev/porter/internal/models"
"github.com/porter-dev/porter/internal/repository"
"github.com/porter-dev/porter/internal/repository/credentials"
"github.com/porter-dev/porter/internal/telemetry"
"gorm.io/gorm"

ints "github.com/porter-dev/porter/internal/models/integrations"
Expand Down Expand Up @@ -594,19 +591,11 @@ func NewOAuthIntegrationRepository(

// CreateOAuthIntegration creates a new oauth auth mechanism
func (repo *OAuthIntegrationRepository) CreateOAuthIntegration(
ctx context.Context,
am *ints.OAuthIntegration,
) (*ints.OAuthIntegration, error) {
ctx, span := telemetry.NewSpan(ctx, "create-oauth-integration")
defer span.End()

telemetry.WithAttributes(span,
telemetry.AttributeKV{Key: "project-id", Value: am.ProjectID},
)

err := repo.EncryptOAuthIntegrationData(am, repo.key)
if err != nil {
return nil, telemetry.Error(ctx, span, err, "error encrypting oauth integration data")
return nil, err
}

// if storage backend is not nil, strip out credential data, which will be stored in credential
Expand All @@ -625,23 +614,24 @@ func (repo *OAuthIntegrationRepository) CreateOAuthIntegration(
project := &models.Project{}

if err := repo.db.Where("id = ?", am.ProjectID).First(&project).Error; err != nil {
return nil, telemetry.Error(ctx, span, err, "error finding project")
return nil, err
}

assoc := repo.db.Model(&project).Association("OAuthIntegrations")

if assoc.Error != nil {
return nil, telemetry.Error(ctx, span, assoc.Error, "error associating project with oauth integration")
return nil, assoc.Error
}

if err := assoc.Append(am); err != nil {
return nil, telemetry.Error(ctx, span, err, "error appending oauth integration to project")
return nil, err
}

if repo.storageBackend != nil {
err = repo.storageBackend.WriteOAuthCredential(am, credentialData)

if err != nil {
return nil, telemetry.Error(ctx, span, err, "error writing oauth credential to storage backend")
return nil, err
}
}

Expand Down Expand Up @@ -718,12 +708,14 @@ func (repo *OAuthIntegrationRepository) UpdateOAuthIntegration(
}

err = repo.DecryptOAuthIntegrationData(am, repo.key)

if err != nil {
return nil, err
}

if repo.storageBackend != nil {
err = repo.storageBackend.WriteOAuthCredential(am, credentialData)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -858,6 +850,7 @@ func (repo *GCPIntegrationRepository) CreateGCPIntegration(

if repo.storageBackend != nil {
err = repo.storageBackend.WriteGCPCredential(am, credentialData)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1003,6 +996,7 @@ func (repo *AWSIntegrationRepository) CreateAWSIntegration(

if repo.storageBackend != nil {
err = repo.storageBackend.WriteAWSCredential(am, credentialData)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1041,6 +1035,7 @@ func (repo *AWSIntegrationRepository) OverwriteAWSIntegration(

if repo.storageBackend != nil {
err = repo.storageBackend.WriteAWSCredential(am, credentialData)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1344,6 +1339,7 @@ func (repo *AzureIntegrationRepository) CreateAzureIntegration(

if repo.storageBackend != nil {
err = repo.storageBackend.WriteAzureCredential(az, credentialData)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1382,6 +1378,7 @@ func (repo *AzureIntegrationRepository) OverwriteAzureIntegration(

if repo.storageBackend != nil {
err = repo.storageBackend.WriteAzureCredential(az, credentialData)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1579,6 +1576,7 @@ func (repo *GitlabIntegrationRepository) CreateGitlabIntegration(gi *ints.Gitlab

if repo.storageBackend != nil {
err = repo.storageBackend.WriteGitlabCredential(gi, credentialData)

if err != nil {
return nil, err
}
Expand Down
10 changes: 8 additions & 2 deletions internal/repository/gorm/auth_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gorm_test

import (
"context"
"testing"

"github.com/go-test/deep"
Expand Down Expand Up @@ -35,6 +34,7 @@ func TestCreateKubeIntegration(t *testing.T) {
}

ki, err = tester.repo.KubeIntegration().ReadKubeIntegration(tester.initProjects[0].ID, ki.Model.ID)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -121,6 +121,7 @@ func TestCreateBasicIntegration(t *testing.T) {
}

basic, err = tester.repo.BasicIntegration().ReadBasicIntegration(tester.initProjects[0].ID, basic.Model.ID)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -212,6 +213,7 @@ func TestCreateOIDCIntegration(t *testing.T) {
}

oidc, err = tester.repo.OIDCIntegration().ReadOIDCIntegration(tester.initProjects[0].ID, oidc.Model.ID)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -304,12 +306,13 @@ func TestCreateOAuthIntegration(t *testing.T) {

expOAuth := *oauth

oauth, err := tester.repo.OAuthIntegration().CreateOAuthIntegration(context.Background(), oauth)
oauth, err := tester.repo.OAuthIntegration().CreateOAuthIntegration(oauth)
if err != nil {
t.Fatalf("%v\n", err)
}

oauth, err = tester.repo.OAuthIntegration().ReadOAuthIntegration(tester.initProjects[0].ID, oauth.Model.ID)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -403,6 +406,7 @@ func TestCreateGCPIntegration(t *testing.T) {
}

gcp, err = tester.repo.GCPIntegration().ReadGCPIntegration(tester.initProjects[0].ID, gcp.Model.ID)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -492,6 +496,7 @@ func TestCreateAWSIntegration(t *testing.T) {
}

aws, err = tester.repo.AWSIntegration().ReadAWSIntegration(tester.initProjects[0].ID, aws.Model.ID)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -530,6 +535,7 @@ func TestOverwriteAWSIntegration(t *testing.T) {
aws.AWSSecretAccessKey = []byte("secret2")

aws, err = tester.repo.AWSIntegration().OverwriteAWSIntegration(aws)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down
6 changes: 4 additions & 2 deletions internal/repository/gorm/helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gorm_test

import (
"context"
"fmt"
"os"
"testing"
Expand Down Expand Up @@ -93,6 +92,7 @@ func setupTestEnv(tester *tester, t *testing.T) {
&ints.HelmRepoTokenCache{},
&ints.GithubAppInstallation{},
)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -164,6 +164,7 @@ func initMultiUser(tester *tester, t *testing.T) {
}

user, err = tester.repo.User().CreateUser(user)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -307,7 +308,7 @@ func initOAuthIntegration(tester *tester, t *testing.T) {
UserID: tester.initUsers[0].ID,
}

oauth, err := tester.repo.OAuthIntegration().CreateOAuthIntegration(context.Background(), oauth)
oauth, err := tester.repo.OAuthIntegration().CreateOAuthIntegration(oauth)
if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down Expand Up @@ -596,6 +597,7 @@ func initKubeEvents(tester *tester, t *testing.T) {
}

err = tester.repo.KubeEvent().AppendSubEvent(event, subEvent)

if err != nil {
t.Fatalf("%v\n", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/repository/gorm/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (t *GormRepository) SlackIntegration() repository.SlackIntegrationRepositor
return t.slackIntegration
}

// UpstashIntegration returns the UpstashIntegrationRepository interface implemented by gorm
func (t *GormRepository) UpstashIntegration() repository.UpstashIntegrationRepository {
return t.upstashIntegration
}
Expand Down
4 changes: 1 addition & 3 deletions internal/repository/integrations.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package repository

import (
"context"

ints "github.com/porter-dev/porter/internal/models/integrations"
)

Expand Down Expand Up @@ -34,7 +32,7 @@ type OIDCIntegrationRepository interface {
// OAuthIntegrationRepository represents the set of queries on the oauth
// mechanism
type OAuthIntegrationRepository interface {
CreateOAuthIntegration(ctx context.Context, am *ints.OAuthIntegration) (*ints.OAuthIntegration, error)
CreateOAuthIntegration(am *ints.OAuthIntegration) (*ints.OAuthIntegration, error)
ReadOAuthIntegration(projectID, id uint) (*ints.OAuthIntegration, error)
ListOAuthIntegrationsByProjectID(projectID uint) ([]*ints.OAuthIntegration, error)
UpdateOAuthIntegration(am *ints.OAuthIntegration) (*ints.OAuthIntegration, error)
Expand Down
2 changes: 0 additions & 2 deletions internal/repository/test/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test

import (
"context"
"errors"

"github.com/porter-dev/porter/internal/repository"
Expand Down Expand Up @@ -239,7 +238,6 @@ func NewOAuthIntegrationRepository(canQuery bool) repository.OAuthIntegrationRep

// CreateOAuthIntegration creates a new o auth mechanism
func (repo *OAuthIntegrationRepository) CreateOAuthIntegration(
ctx context.Context,
am *ints.OAuthIntegration,
) (*ints.OAuthIntegration, error) {
if !repo.canQuery {
Expand Down

0 comments on commit fe70784

Please sign in to comment.