Support opening repository in read-only mode (#4302)

Useful for running read only operations against the repository

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [x] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Vaibhav Kamra 2023-09-19 21:05:12 -07:00 committed by GitHub
parent b44585ba1c
commit 4814154928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -184,6 +184,7 @@ func (w *conn) commonConnect(
ClientOptions: repo.ClientOptions{
Username: opts.User,
Hostname: opts.Host,
ReadOnly: opts.ReadOnly,
},
}

View File

@ -11,6 +11,7 @@ type Options struct {
// ViewTimestamp is the time at which the repo should be opened at if
// immutable backups are being used. If nil then the current time is used.
ViewTimestamp *time.Time `json:"viewTimestamp"`
ReadOnly bool `json:"readonly,omitempty"`
}
type Maintenance struct {

View File

@ -393,6 +393,31 @@ func (suite *RepositoryIntegrationSuite) TestConnect_DisableMetrics() {
assert.Equal(t, r.GetID(), r.GetID())
}
func (suite *RepositoryIntegrationSuite) TestConnect_ReadOnly() {
t := suite.T()
ctx, flush := tester.NewContext(t)
defer flush()
// need to initialize the repository before we can test connecting to it.
st := storeTD.NewPrefixedS3Storage(t)
repo, err := Initialize(
ctx,
account.Account{},
st,
control.DefaultOptions(),
ctrlRepo.Retention{})
require.NoError(t, err)
// now re-connect
r, err := Connect(ctx, account.Account{}, st, repo.GetID(), control.Options{Repo: ctrlRepo.Options{ReadOnly: true}})
assert.NoError(t, err)
// now we have repoID beforehand
assert.Equal(t, r.GetID(), r.GetID())
}
// Test_Options tests that the options are passed through to the repository
// correctly
func (suite *RepositoryIntegrationSuite) Test_Options() {