open-vault/helper/identity/mfa/mfa.go
Jeff Mitchell 0a78c00c9f Sync over
2019-03-25 12:43:16 -04:00

28 lines
538 B
Go

package mfa
import (
"fmt"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/errwrap"
)
func (c *Config) Clone() (*Config, error) {
if c == nil {
return nil, fmt.Errorf("nil config")
}
marshaledConfig, err := proto.Marshal(c)
if err != nil {
return nil, errwrap.Wrapf("failed to marshal config: {{err}}", err)
}
var clonedConfig Config
err = proto.Unmarshal(marshaledConfig, &clonedConfig)
if err != nil {
return nil, errwrap.Wrapf("failed to unmarshal config: {{err}}", err)
}
return &clonedConfig, nil
}