mirror of
https://github.com/kopia/kopia.git
synced 2026-03-27 10:32:08 -04:00
- `repo.Repository` is now read-only and only has methods that can be supported over kopia server
- `repo.RepositoryWriter` has read-write methods that can be supported over kopia server
- `repo.DirectRepository` is read-only and contains all methods of `repo.Repository` plus some low-level methods for data inspection
- `repo.DirectRepositoryWriter` contains write methods for `repo.DirectRepository`
- `repo.Reader` removed and merged with `repo.Repository`
- `repo.Writer` became `repo.RepositoryWriter`
- `*repo.DirectRepository` struct became `repo.DirectRepository`
interface
Getting `{Direct}RepositoryWriter` requires using `NewWriter()` or `NewDirectWriter()` on a read-only repository and multiple simultaneous writers are supported at the same time, each writing to their own indexes and pack blobs.
`repo.Open` returns `repo.Repository` (which is also `repo.RepositoryWriter`).
* content: removed implicit flush on content manager close
* repo: added tests for WriteSession() and implicit flush behavior
* invalidate manifest manager after write session
* cli: disable maintenance in 'kopia server start'
Server will close the repository before completing.
* repo: unconditionally close RepositoryWriter in {Direct,}WriteSession
* repo: added panic in case somebody tries to create RepositoryWriter after closing repository
- used atomic to manage SharedManager.closed
* removed stale example
* linter: fixed spurious failures
Co-authored-by: Julio López <julio+gh@kasten.io>
54 lines
1.3 KiB
Go
54 lines
1.3 KiB
Go
package repo
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo/blob"
|
|
)
|
|
|
|
type tokenInfo struct {
|
|
Version string `json:"version"`
|
|
Storage blob.ConnectionInfo `json:"storage"`
|
|
Password string `json:"password,omitempty"`
|
|
}
|
|
|
|
// Token returns an opaque token that contains repository connection information
|
|
// and optionally the provided password.
|
|
func (r *directRepository) Token(password string) (string, error) {
|
|
ti := &tokenInfo{
|
|
Version: "1",
|
|
Storage: r.blobs.ConnectionInfo(),
|
|
Password: password,
|
|
}
|
|
|
|
v, err := json.Marshal(ti)
|
|
if err != nil {
|
|
return "", errors.Wrap(err, "marshal token")
|
|
}
|
|
|
|
return base64.RawURLEncoding.EncodeToString(v), nil
|
|
}
|
|
|
|
// DecodeToken decodes the provided token and returns connection info and password if persisted.
|
|
func DecodeToken(token string) (blob.ConnectionInfo, string, error) {
|
|
t := &tokenInfo{}
|
|
|
|
v, err := base64.RawURLEncoding.DecodeString(token)
|
|
if err != nil {
|
|
return blob.ConnectionInfo{}, "", errors.New("unable to decode token")
|
|
}
|
|
|
|
if err := json.Unmarshal(v, t); err != nil {
|
|
return blob.ConnectionInfo{}, "", errors.New("unable to decode token")
|
|
}
|
|
|
|
if t.Version != "1" {
|
|
return blob.ConnectionInfo{}, "", errors.New("unsupported token version")
|
|
}
|
|
|
|
return t.Storage, t.Password, nil
|
|
}
|