purge/triplestore: Better handle deleteing

This commit is contained in:
Tom Wiesing 2022-11-12 19:45:29 +01:00
parent cf835135a8
commit c22fd01ed5
No known key found for this signature in database
2 changed files with 13 additions and 6 deletions

View file

@ -38,6 +38,11 @@ var errPurgeNoConfirmation = exit.Error{
ExitCode: exit.ExitGeneric,
}
var errPurgeGeneric = exit.Error{
Message: "Unable to purge instance %s: %s",
ExitCode: exit.ExitGeneric,
}
func (p purge) Run(context wisski_distillery.Context) error {
dis := context.Environment
slug := p.Positionals.Slug
@ -88,7 +93,7 @@ func (p purge) Run(context wisski_distillery.Context) error {
return nil
}, context.IOStream, "Purging instance-specific resources"); err != nil {
return errProvisionGeneric.WithMessageF(slug, err)
return errPurgeGeneric.WithMessageF(slug, err)
}
// remove from bookkeeping
@ -98,7 +103,7 @@ func (p purge) Run(context wisski_distillery.Context) error {
}
// remove the filesystem
logging.LogMessage(context.IOStream, "Remove lock data", instance.FilesystemBase)
logging.LogMessage(context.IOStream, "Remove lock data")
if instance.Locker().TryUnlock() {
context.EPrintln("instance was not locked")
}

View file

@ -99,25 +99,27 @@ func (ts Triplestore) Wait() error {
}, ts.PollContext, ts.PollInterval)
}
// TriplestorePurgeUser deletes the specified user from the triplestore
// PurgeUser deletes the specified user from the triplestore.
// When the user does not exist, returns no error.
func (ts Triplestore) PurgeUser(user string) error {
res, err := ts.OpenRaw("DELETE", "/rest/security/users/"+user, nil, "", "")
if err != nil {
return err
}
if res.StatusCode != http.StatusNoContent {
if res.StatusCode != http.StatusNoContent && res.StatusCode != http.StatusNotFound {
return errors.Errorf("Delete returned code %d", res.StatusCode)
}
return nil
}
// TriplestorePurgeRepo deletes the specified repo from the triplestore
// PurgeRepo deletes the specified repo from the triplestore.
// When the repo does not exist, returns no error.
func (ts Triplestore) PurgeRepo(repo string) error {
res, err := ts.OpenRaw("DELETE", "/rest/repositories/"+repo, nil, "", "")
if err != nil {
return err
}
if res.StatusCode != http.StatusOK {
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusNotFound {
return errors.Errorf("Delete returned code %d", res.StatusCode)
}
return nil