-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- deletes ottca enrollment when CA is deleted - adds API tests - adds migration to remove currently orphaned ottca enrollments - migration tested on a v15 database with orphaned ottca enrollments
- Loading branch information
1 parent
2c8cd9c
commit 46166db
Showing
10 changed files
with
202 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package persistence | ||
|
||
import ( | ||
"fmt" | ||
"github.com/michaelquigley/pfxlog" | ||
"github.com/openziti/foundation/storage/ast" | ||
"github.com/openziti/foundation/storage/boltz" | ||
) | ||
|
||
func (m *Migrations) removeOrphanedOttCaEnrollments(step *boltz.MigrationStep) { | ||
|
||
var enrollmentsToDelete []string | ||
|
||
filter, err := ast.Parse(m.stores.Enrollment, "true") | ||
|
||
if err != nil { | ||
step.SetError(fmt.Errorf("could not parse query for removing orphaned ottca enrollments: %v", err)) | ||
return | ||
} | ||
|
||
for cursor := m.stores.Enrollment.IterateIds(step.Ctx.Tx(), filter); cursor.IsValid(); cursor.Next() { | ||
current := cursor.Current() | ||
currentEnrollmentId := string(current) | ||
|
||
enrollment, err := m.stores.Enrollment.LoadOneById(step.Ctx.Tx(), currentEnrollmentId) | ||
|
||
if err != nil { | ||
step.SetError(fmt.Errorf("error interating ids of enrollments, enrollment [%s]: %v", currentEnrollmentId, err)) | ||
return | ||
} | ||
|
||
if enrollment.CaId != nil && *enrollment.CaId != "" { | ||
_, err := m.stores.Ca.LoadOneById(step.Ctx.Tx(), *enrollment.CaId) | ||
|
||
if err != nil && boltz.IsErrNotFoundErr(err) { | ||
enrollmentsToDelete = append(enrollmentsToDelete, currentEnrollmentId) | ||
} | ||
} | ||
} | ||
|
||
//clear caIds that are invalid via CheckIntegrity | ||
m.stores.Enrollment.CheckIntegrity(step.Ctx.Tx(), true, func(err error, fixed bool) { | ||
if !fixed { | ||
pfxlog.Logger().Errorf("unfixable error during orphaned ottca enrollment integrity check: %v", err) | ||
} | ||
}) | ||
|
||
for _, enrollmentId := range enrollmentsToDelete { | ||
pfxlog.Logger().Infof("removing invalid ottca enrollment [%s]", enrollmentId) | ||
if err := m.stores.Enrollment.DeleteById(step.Ctx, enrollmentId); err != nil { | ||
|
||
step.SetError(fmt.Errorf("could not delete enrollment [%s] with invalid CA reference: %v", enrollmentId, err)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.