-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client should fall back on cache if operating offline when updating #982
Merged
endophage
merged 2 commits into
notaryproject:hotfix/0.4.1
from
cyli:update-uses-cache-if-offline
Sep 30, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -33,6 +33,15 @@ type ErrServerUnavailable struct { | |
code int | ||
} | ||
|
||
// NetworkError represents any kind of network error when attempting to make a request | ||
type NetworkError struct { | ||
Wrapped error | ||
} | ||
|
||
func (n NetworkError) Error() string { | ||
return n.Wrapped.Error() | ||
} | ||
|
||
func (err ErrServerUnavailable) Error() string { | ||
if err.code == 401 { | ||
return fmt.Sprintf("you are not authorized to perform this operation: server returned 401.") | ||
|
@@ -152,7 +161,7 @@ func (s HTTPStore) GetSized(name string, size int64) ([]byte, error) { | |
} | ||
resp, err := s.roundTrip.RoundTrip(req) | ||
if err != nil { | ||
return nil, err | ||
return nil, NetworkError{Wrapped: err} | ||
} | ||
defer resp.Body.Close() | ||
if err := translateStatusToError(resp, name); err != nil { | ||
|
@@ -174,22 +183,9 @@ func (s HTTPStore) GetSized(name string, size int64) ([]byte, error) { | |
return body, nil | ||
} | ||
|
||
// Set uploads a piece of TUF metadata to the server | ||
// Set sends a single piece of metadata to the TUF server | ||
func (s HTTPStore) Set(name string, blob []byte) error { | ||
url, err := s.buildMetaURL("") | ||
if err != nil { | ||
return err | ||
} | ||
req, err := http.NewRequest("POST", url.String(), bytes.NewReader(blob)) | ||
if err != nil { | ||
return err | ||
} | ||
resp, err := s.roundTrip.RoundTrip(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
return translateStatusToError(resp, "POST "+name) | ||
return s.SetMulti(map[string][]byte{name: blob}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is an awesome cleanup 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh man yeah! Nice one! |
||
} | ||
|
||
// Remove always fails, because we should never be able to delete metadata | ||
|
@@ -239,7 +235,7 @@ func (s HTTPStore) SetMulti(metas map[string][]byte) error { | |
} | ||
resp, err := s.roundTrip.RoundTrip(req) | ||
if err != nil { | ||
return err | ||
return NetworkError{Wrapped: err} | ||
} | ||
defer resp.Body.Close() | ||
// if this 404's something is pretty wrong | ||
|
@@ -258,7 +254,7 @@ func (s HTTPStore) RemoveAll() error { | |
} | ||
resp, err := s.roundTrip.RoundTrip(req) | ||
if err != nil { | ||
return err | ||
return NetworkError{Wrapped: err} | ||
} | ||
defer resp.Body.Close() | ||
return translateStatusToError(resp, "DELETE metadata for GUN endpoint") | ||
|
@@ -299,7 +295,7 @@ func (s HTTPStore) GetKey(role string) ([]byte, error) { | |
} | ||
resp, err := s.roundTrip.RoundTrip(req) | ||
if err != nil { | ||
return nil, err | ||
return nil, NetworkError{Wrapped: err} | ||
} | ||
defer resp.Body.Close() | ||
if err := translateStatusToError(resp, role+" key"); err != nil { | ||
|
@@ -324,7 +320,7 @@ func (s HTTPStore) RotateKey(role string) ([]byte, error) { | |
} | ||
resp, err := s.roundTrip.RoundTrip(req) | ||
if err != nil { | ||
return nil, err | ||
return nil, NetworkError{Wrapped: err} | ||
} | ||
defer resp.Body.Close() | ||
if err := translateStatusToError(resp, role+" key"); err != nil { | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call
offlineRepo.Update(false)
and verify that it errors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yes I was intending to and just forgot. :) Thanks!