Skip to content

Commit

Permalink
Migrate credential and parameter sets to have schemaVersion (#1218)
Browse files Browse the repository at this point in the history
* Migrate credentials

Migrate credentials during porter storage migrate:

* Track credential-set schema in schema.json under the "credentials",
e.g.   "credentials": "cnab-credentialsets-1.0.0-DRAFT-b6c701f"
* A migration will upgrade everything that is out of date, if claims
fail, it will keep migrating credentials then report all failures.
* Removed unused credential set migration from yaml to json. We haven't
used it for months and it isn't possible anymore with the filesystem
store / crud.Store interface.
* Renamed mybuns testdata to mybun for consistency and decency.
* Removed extra exclamation points in the migration logs. Now that we
are logging to a file, and using a dedicated command, grabbing people's
attention isn't as critical.
* Tweak when we log Migration Complete/Failed and the log file path so
that it is captured appropriately in the console and in the log file
without duplication.
* Aggregate errors from migration so that we continue on error but
report that an error occurred during migration.
* Implement interface methods in storage.Manager so that our custom
HandleConnect is called exactly when we want it, instead of the
HandleConnect of our datastore.

* Set schemaVersion on new credential sets

* Set schemaVersion on new parameter sets

* Migrate parameter sets during porter storage migrate

* Incorporate review feedback
  • Loading branch information
carolynvs authored Aug 24, 2020
1 parent 6054414 commit 6a47a23
Show file tree
Hide file tree
Showing 46 changed files with 864 additions and 512 deletions.
6 changes: 5 additions & 1 deletion build/testdata/schema.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{"claims":"cnab-claim-1.0.0-DRAFT+b5ed2f3","credentials":"cnab-credentials-1.0.0-DRAFT-b6c701f"}
{
"claims": "cnab-claim-1.0.0-DRAFT+b5ed2f3",
"credentials": "cnab-credentialsets-1.0.0-DRAFT+b6c701f",
"parameters": "cnab-parametersets-1.0.0-DRAFT+TODO"
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module get.porter.sh/porter
go 1.13

replace (
// https://github.com/cnabio/cnab-go/pull/229 (valueset-schema)
github.com/cnabio/cnab-go => github.com/carolynvs/cnab-go v0.13.4-0.20200820201933-d6bf372247e5

// See https://github.com/containerd/containerd/issues/3031
// When I try to just use the require, go is shortening it to v2.7.1+incompatible which then fails to build...
github.com/docker/distribution => github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible
Expand Down
8 changes: 5 additions & 3 deletions pkg/claims/claimStorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestClaimStorage_HaltOnMigrationRequired(t *testing.T) {
// Add an unmigrated claim
claimsDir := filepath.Join(home, "claims")
config.FileSystem.Mkdir(claimsDir, 0755)
config.TestContext.AddTestFile(filepath.Join("../storage/testdata", "upgraded.json"), filepath.Join(home, "claims", "mybun.json"))
config.TestContext.AddTestFile(filepath.Join("../storage/testdata/claims", "upgraded.json"), filepath.Join(home, "claims", "mybun.json"))

dataStore := filesystem.NewStore(*config.Config, hclog.NewNullLogger())
mgr := storage.NewManager(config.Config, dataStore)
Expand All @@ -31,14 +31,16 @@ func TestClaimStorage_HaltOnMigrationRequired(t *testing.T) {
var err error
t.Run("list", func(t *testing.T) {
_, err = claimStore.ListInstallations()
require.Error(t, err, "Operation should halt because a migration is required")
assert.Contains(t, err.Error(), "The schema of Porter's data is in an older format than supported by this version of Porter")
})

t.Run("read", func(t *testing.T) {
_, err = claimStore.ReadInstallation("mybun")
require.Error(t, err, "Operation should halt because a migration is required")
assert.Contains(t, err.Error(), "The schema of Porter's data is in an older format than supported by this version of Porter")
})

require.Error(t, err, "Operation should halt because a migration is required")
assert.Contains(t, err.Error(), "The schema of Porter's data is in an older format than supported by this version of Porter")
}

func TestClaimStorage_OperationAllowedWhenNoMigrationDetected(t *testing.T) {
Expand Down
22 changes: 8 additions & 14 deletions pkg/cnab/provider/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cnabprovider

import (
"testing"
"time"

"get.porter.sh/porter/pkg/secrets"
"github.com/cnabio/cnab-go/bundle"
Expand All @@ -20,20 +19,15 @@ func TestRuntime_loadCredentials(t *testing.T) {

r.TestConfig.TestContext.AddTestFile("testdata/db-creds.json", "/db-creds.json")

cs1 := credentials.CredentialSet{
Name: "mycreds",
Created: time.Now(),
Modified: time.Now(),
Credentials: []valuesource.Strategy{
{
Name: "password",
Source: valuesource.Source{
Key: secrets.SourceSecret,
Value: "password",
},
cs1 := credentials.NewCredentialSet("mycreds",
valuesource.Strategy{
Name: "password",
Source: valuesource.Source{
Key: secrets.SourceSecret,
Value: "password",
},
},
}
})

err := r.credentials.Save(cs1)
require.NoError(t, err, "Save credential set failed")

Expand Down
108 changes: 0 additions & 108 deletions pkg/credentials/credentialMigration.go

This file was deleted.

76 changes: 0 additions & 76 deletions pkg/credentials/credentialMigration_test.go

This file was deleted.

Loading

0 comments on commit 6a47a23

Please sign in to comment.