Skip to content

Commit

Permalink
#461: return a generic remote when getting them individually
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlotte Godley committed Jun 20, 2018
1 parent 6a38a7d commit 32ee236
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
3 changes: 1 addition & 2 deletions cmd/dm/pkg/commands/dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ func dotSetUpstream(cmd *cobra.Command, args []string, out io.Writer) error {
if err != nil {
return err
}

remoteNamespace, remoteDot, err := remotes.ParseNamespacedVolumeWithDefault(remoteDot, remote.User)
remoteNamespace, remoteDot, err := remotes.ParseNamespacedVolumeWithDefault(remoteDot, remote.DefaultNamespace())
if err != nil {
return err
}
Expand Down
74 changes: 53 additions & 21 deletions cmd/dm/pkg/remotes/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,16 @@ type TransferRequest struct {
TargetCommit string
}

type S3TransferRequest struct {
KeyID string
SecretKey string
Direction string
LocalNamespace string
LocalName string
LocalBranchName string
RemoteName string
}

// attempt to get the latest commits in filesystemId (which may be a branch)
// from fromRemote to toRemote as a one-off.
//
Expand Down Expand Up @@ -922,7 +932,6 @@ func (dm *DotmeshAPI) RequestTransfer(

// Guess defaults for the remote filesystem
var remoteNamespace, remoteVolume string

if remoteFilesystemName == "" {
// No remote specified. Do we already have a default configured?
defaultRemoteNamespace, defaultRemoteVolume, ok := dm.Configuration.DefaultRemoteVolumeFor(peer, localNamespace, localVolume)
Expand All @@ -934,12 +943,12 @@ func (dm *DotmeshAPI) RequestTransfer(
// If not, default to the un-namespaced local filesystem name.
// This causes it to default into the user's own namespace
// when we parse the name, too.
remoteNamespace = remote.User
remoteNamespace = remote.DefaultNamespace()
remoteVolume = localVolume
}
} else {
// Default namespace for remote volume is the username on this remote
remoteNamespace, remoteVolume, err = ParseNamespacedVolumeWithDefault(remoteFilesystemName, remote.User)
remoteNamespace, remoteVolume, err = ParseNamespacedVolumeWithDefault(remoteFilesystemName, remote.DefaultNamespace())
if err != nil {
return "", err
}
Expand Down Expand Up @@ -984,26 +993,49 @@ func (dm *DotmeshAPI) RequestTransfer(
var transferId string
// TODO make ApiKey time- and domain- (filesystem?) limited
// cryptographically somehow
err = client.CallRemote(context.Background(),
"DotmeshRPC.Transfer", TransferRequest{
Peer: remote.Hostname,
User: remote.User,
Port: remote.Port,
ApiKey: remote.ApiKey,
Direction: direction,
LocalNamespace: localNamespace,
LocalName: localVolume,
LocalBranchName: deMasterify(localBranchName),
RemoteNamespace: remoteNamespace,
RemoteName: remoteVolume,
RemoteBranchName: deMasterify(remoteBranchName),
// TODO add TargetSnapshot here, to support specifying "push to a given
// snapshot" rather than just "push all snapshots up to the latest"
}, &transferId)
if err != nil {
return "", err
dmRemote, ok := remote.(DMRemote)
if ok {
err = client.CallRemote(context.Background(),
"DotmeshRPC.Transfer", TransferRequest{
Peer: dmRemote.Hostname,
User: dmRemote.User,
Port: dmRemote.Port,
ApiKey: dmRemote.ApiKey,
Direction: direction,
LocalNamespace: localNamespace,
LocalName: localVolume,
LocalBranchName: deMasterify(localBranchName),
RemoteNamespace: remoteNamespace,
RemoteName: remoteVolume,
RemoteBranchName: deMasterify(remoteBranchName),
// TODO add TargetSnapshot here, to support specifying "push to a given
// snapshot" rather than just "push all snapshots up to the latest"
}, &transferId)
if err != nil {
return "", err
}
} else {
s3Remote, ok := remote.(S3Remote)
if ok {
err = client.CallRemote(context.Background(),
"DotmeshRPC.s3Transfer", S3TransferRequest{
KeyID: s3Remote.KeyID,
SecretKey: s3Remote.SecretKey,
Direction: direction,
LocalNamespace: localNamespace,
LocalName: localVolume,
LocalBranchName: deMasterify(localBranchName),
RemoteName: remoteVolume,
// TODO add TargetSnapshot here, to support specifying "push to a given
// snapshot" rather than just "push all snapshots up to the latest"
}, &transferId)
if err != nil {
return "", err
}
}
}
return transferId, nil

}

// FIXME: Put this in a shared library, as it duplicates the copy in
Expand Down
20 changes: 17 additions & 3 deletions cmd/dm/pkg/remotes/remotes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
)

type Remote interface {
DefaultNamespace() string
}

type S3Remote struct {
Expand All @@ -58,6 +59,14 @@ type DMRemote struct {
DefaultRemoteVolumes map[string]map[string]VolumeName
}

func (remote DMRemote) DefaultNamespace() string {
return remote.User
}

func (remote S3Remote) DefaultNamespace() string {
return ""
}

func (remote DMRemote) String() string {
v := reflect.ValueOf(remote)
toString := ""
Expand Down Expand Up @@ -124,12 +133,17 @@ func (c *Configuration) save() error {
return nil
}

func (c *Configuration) GetRemote(name string) (*DMRemote, error) {
func (c *Configuration) GetRemote(name string) (Remote, error) {
c.lock.Lock()
defer c.lock.Unlock()
r, ok := c.DMRemotes[name]
var r Remote
var ok bool
r, ok = c.DMRemotes[name]
if !ok {
return nil, fmt.Errorf("Unable to find remote '%s'", name)
r, ok = c.S3Remotes[name]
if !ok {
return nil, fmt.Errorf("Unable to find remote '%s'", name)
}
}
return r, nil
}
Expand Down

0 comments on commit 32ee236

Please sign in to comment.