Skip to content

Commit

Permalink
[RCM-432] fix(remote-config): Clean remote state on error & use fixed…
Browse files Browse the repository at this point in the history
… fork of go-tuf (#13517)

* [RCM-432] fix(TUF): Clean remote state on TUF error

* fix(go-tuf): Use fork of go-tuf for the time being.

* refactor(uptane): Refactor the Update methods
  • Loading branch information
BaptisteFoy authored Sep 15, 2022
1 parent d0b11c7 commit bf8de49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ replace (
github.com/lxn/walk => github.com/lxn/walk v0.0.0-20180521183810-02935bac0ab8
github.com/mholt/archiver => github.com/mholt/archiver v2.0.1-0.20171012052341-26cf5bb32d07+incompatible
github.com/spf13/cast => github.com/DataDog/cast v1.3.1-0.20190301154711-1ee8c8bd14a3
github.com/theupdateframework/go-tuf => github.com/DataDog/go-tuf v0.3.0--fix-localmeta
github.com/ugorji/go => github.com/ugorji/go v1.1.7
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions pkg/config/remote/uptane/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewClient(cacheDB *bbolt.DB, cacheKey string, orgID int64) (*Client, error)
return c, nil
}

// Update updates the uptane client
// Update updates the uptane client and rollbacks in case of error
func (c *Client) Update(response *pbgo.LatestConfigsResponse) error {
c.Lock()
defer c.Unlock()
Expand All @@ -79,20 +79,28 @@ func (c *Client) Update(response *pbgo.LatestConfigsResponse) error {
// the defer is present to be sure a transaction is never left behind.
defer c.transactionalStore.rollback()

err := c.updateRepos(response)
err := c.update(response)
if err != nil {
c.configRemoteStore = newRemoteStoreConfig(c.targetStore)
c.directorRemoteStore = newRemoteStoreDirector(c.targetStore)
c.configTUFClient = client.NewClient(c.configLocalStore, c.configRemoteStore)
c.directorTUFClient = client.NewClient(c.directorLocalStore, c.directorRemoteStore)
return err
}
err = c.pruneTargetFiles()
return c.transactionalStore.commit()
}

// update updates the uptane client
func (c *Client) update(response *pbgo.LatestConfigsResponse) error {
err := c.updateRepos(response)
if err != nil {
return err
}
err = c.verify()
err = c.pruneTargetFiles()
if err != nil {
return err
}

return c.transactionalStore.commit()
return c.verify()
}

// TargetsCustom returns the current targets custom of this uptane client
Expand Down

0 comments on commit bf8de49

Please sign in to comment.