Skip to content

Commit

Permalink
Add arg to connect to kopia repos as readonly (#2004)
Browse files Browse the repository at this point in the history
This commit adds a new field to the repository and repository server
connect arg structs to connect to a repository/server in read-only
mode. As of kopia/kopia/#2799, there are new kopia workflows which
require a read only connection.

Co-authored-by: Julio Lopez <1953782+julio-lopez@users.noreply.github.com>
Co-authored-by: Ankit Jain <ankitjain.meone@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people committed Aug 23, 2023
1 parent d36cc6b commit 4a51782
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const (
overrideUsernameFlag = "--override-username"
pointInTimeConnectionFlag = "--point-in-time"
urlFlag = "--url"
readOnlyFlag = "--readonly"
)

// List of possible modifications to a policy, expressed as the kopia flag that will modify it
Expand Down
10 changes: 10 additions & 0 deletions pkg/kopia/command/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type RepositoryCommandArgs struct {
MetadataCacheMB int
Username string
RepoPathPrefix string
ReadOnly bool
// PITFlag is only effective if set while repository connect
PITFlag strfmt.DateTime
Location map[string][]byte
Expand All @@ -43,6 +44,10 @@ func RepositoryConnectCommand(cmdArgs RepositoryCommandArgs) ([]string, error) {
args := commonArgs(cmdArgs.CommandArgs)
args = args.AppendLoggable(repositorySubCommand, connectSubCommand, noCheckForUpdatesFlag)

if cmdArgs.ReadOnly {
args = args.AppendLoggable(readOnlyFlag)
}

args = kopiaCacheArgs(args, cmdArgs.CacheDirectory, cmdArgs.ContentCacheMB, cmdArgs.MetadataCacheMB)

if cmdArgs.Hostname != "" {
Expand Down Expand Up @@ -105,6 +110,7 @@ type RepositoryServerCommandArgs struct {
ServerURL string
Fingerprint string
Username string
ReadOnly bool
ContentCacheMB int
MetadataCacheMB int
}
Expand All @@ -119,6 +125,10 @@ func RepositoryConnectServerCommand(cmdArgs RepositoryServerCommandArgs) []strin
})
args = args.AppendLoggable(repositorySubCommand, connectSubCommand, serverSubCommand, noCheckForUpdatesFlag, noGrpcFlag)

if cmdArgs.ReadOnly {
args = args.AppendLoggable(readOnlyFlag)
}

args = kopiaCacheArgs(args, cmdArgs.CacheDirectory, cmdArgs.ContentCacheMB, cmdArgs.MetadataCacheMB)

if cmdArgs.Hostname != "" {
Expand Down
4 changes: 4 additions & 0 deletions pkg/kopia/command/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (s *RepositoryUtilsSuite) TestRepositoryConnectUtil(c *check.C) {
"prefix": []byte("test-prefix"),
"type": []byte("filestore"),
},
ReadOnly: true,
},
Checker: check.IsNil,
expectedCmd: []string{"kopia",
Expand All @@ -153,6 +154,7 @@ func (s *RepositoryUtilsSuite) TestRepositoryConnectUtil(c *check.C) {
"repository",
"connect",
"--no-check-for-updates",
"--readonly",
"--cache-directory=/tmp/cache.dir",
"--content-cache-size-mb=0",
"--metadata-cache-size-mb=0",
Expand Down Expand Up @@ -182,6 +184,7 @@ func (s *RepositoryUtilsSuite) TestRepositoryConnectServerUtil(c *check.C) {
Username: "test-username",
ServerURL: "https://127.0.0.1:51515",
Fingerprint: "test-fingerprint",
ReadOnly: true,
ContentCacheMB: 0,
MetadataCacheMB: 0,
})
Expand All @@ -195,6 +198,7 @@ func (s *RepositoryUtilsSuite) TestRepositoryConnectServerUtil(c *check.C) {
"server",
"--no-check-for-updates",
"--no-grpc",
"--readonly",
"--cache-directory=/tmp/cache.dir",
"--content-cache-size-mb=0",
"--metadata-cache-size-mb=0",
Expand Down

0 comments on commit 4a51782

Please sign in to comment.