This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add download method for updater (#20)
* add download method for updater Closes #13 In the process of adding the method also discovered and updated the potentially race-y usage of the repoManager struct. Closes #16 but full fix should come in with #22
- Loading branch information
Showing
8 changed files
with
403 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package tuf | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// Client is a TUF client. | ||
type Client struct { | ||
// Client wraps the private repoMan type which contains the actual | ||
// methods for working with TUF repositories. In the future it might | ||
// be worthwile to export the repoMan type as Client instead, but | ||
// wrapping it reduces the amount of present refactoring work. | ||
manager *repoMan | ||
} | ||
|
||
func NewClient(settings *Settings) (*Client, error) { | ||
if settings.MaxResponseSize == 0 { | ||
settings.MaxResponseSize = defaultMaxResponseSize | ||
} | ||
// check to see if Notary server is available | ||
notary, err := newNotaryRepo(settings) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "creating notary client") | ||
} | ||
err = notary.ping() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "pinging notary server failed") | ||
} | ||
localRepo, err := newLocalRepo(settings.LocalRepoPath) | ||
if err != nil { | ||
return nil, errors.New("creating local tuf role repo") | ||
} | ||
// store intermediate state until all validation succeeds, then write | ||
// changed roles to non-volitile storage | ||
manager := newRepoMan(localRepo, notary, settings, notary.client) | ||
return &Client{manager: manager}, nil | ||
} | ||
|
||
func (c *Client) Update() (files map[string]FileIntegrityMeta, latest bool, err error) { | ||
latest, err = c.manager.refresh() | ||
if err != nil { | ||
return nil, latest, errors.Wrap(err, "refreshing state") | ||
} | ||
|
||
if err := c.manager.save(getTag()); err != nil { | ||
return nil, latest, errors.Wrap(err, "unable to save tuf repo state") | ||
} | ||
|
||
files = c.manager.getLocalTargets() | ||
return files, latest, nil | ||
} | ||
|
||
func (c *Client) Download(targetName string, destination io.Writer) error { | ||
files := c.manager.getLocalTargets() | ||
fim, ok := files[targetName] | ||
if !ok { | ||
return errNoSuchTarget | ||
} | ||
if err := c.manager.downloadTarget(targetName, &fim, destination); err != nil { | ||
return errors.Wrap(err, "downloading target") | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Client) Stop() { | ||
c.manager.Stop() | ||
} |
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.