Skip to content

Commit

Permalink
internal/remoteconfig: do not send file states on global error
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio-Guerra committed Dec 16, 2022
1 parent 793721d commit 4012444
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions internal/remoteconfig/remoteconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,22 +212,27 @@ func (c *Client) applyUpdate(pbUpdate *clientGetConfigsResponse) error {
// Check the repository state before and after the update to detect which configs are not being sent anymore.
// This is needed because some products can stop sending configurations, and we want to make sure that the subscribers
// are provided with this information in this case
stateBefore, _ := c.repository.CurrentState()
stateBefore, err := c.repository.CurrentState()
if err != nil {
return fmt.Errorf("repository current state error: %v", err)
}
products, err := c.repository.Update(rc.Update{
TUFRoots: pbUpdate.Roots,
TUFTargets: pbUpdate.Targets,
TargetFiles: fileMap,
ClientConfigs: pbUpdate.ClientConfigs,
})
if err != nil {
return fmt.Errorf("remote config: repository update error: %v", err)
return fmt.Errorf("repository update error: %v", err)
}
stateAfter, err := c.repository.CurrentState()
if err != nil {
return fmt.Errorf("repository current state error after update: %v", err)
}
stateAfter, _ := c.repository.CurrentState()

// Create a config files diff between before/after the update to see which config files are missing
mBefore := mapify(&stateBefore)
mAfter := mapify(&stateAfter)
for k := range mAfter {
for k := range mapify(&stateAfter) {
delete(mBefore, k)
}

Expand Down Expand Up @@ -291,15 +296,18 @@ func (c *Client) newUpdateRequest() (bytes.Buffer, error) {
errMsg = c.lastError.Error()
}

pbConfigState := make([]*configState, 0, len(state.Configs))
for _, f := range state.Configs {
pbConfigState = append(pbConfigState, &configState{
ID: f.ID,
Version: f.Version,
Product: f.Product,
ApplyState: f.ApplyStatus.State,
ApplyError: f.ApplyStatus.Error,
})
var pbConfigState []*configState
if !hasError {
pbConfigState = make([]*configState, 0, len(state.Configs))
for _, f := range state.Configs {
pbConfigState = append(pbConfigState, &configState{
ID: f.ID,
Version: f.Version,
Product: f.Product,
ApplyState: f.ApplyStatus.State,
ApplyError: f.ApplyStatus.Error,
})
}
}

cap := big.NewInt(0)
Expand Down

0 comments on commit 4012444

Please sign in to comment.