2017-10-11 17:21:20 +00:00
|
|
|
package identity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2018-06-07 14:48:36 +00:00
|
|
|
proto "github.com/golang/protobuf/proto"
|
2018-04-05 15:49:21 +00:00
|
|
|
"github.com/hashicorp/errwrap"
|
2017-10-11 17:21:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (g *Group) Clone() (*Group, error) {
|
|
|
|
if g == nil {
|
|
|
|
return nil, fmt.Errorf("nil group")
|
|
|
|
}
|
|
|
|
|
|
|
|
marshaledGroup, err := proto.Marshal(g)
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to marshal group: {{err}}", err)
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var clonedGroup Group
|
|
|
|
err = proto.Unmarshal(marshaledGroup, &clonedGroup)
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to unmarshal group: {{err}}", err)
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &clonedGroup, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Entity) Clone() (*Entity, error) {
|
|
|
|
if e == nil {
|
|
|
|
return nil, fmt.Errorf("nil entity")
|
|
|
|
}
|
|
|
|
|
|
|
|
marshaledEntity, err := proto.Marshal(e)
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to marshal entity: {{err}}", err)
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var clonedEntity Entity
|
|
|
|
err = proto.Unmarshal(marshaledEntity, &clonedEntity)
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to unmarshal entity: {{err}}", err)
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &clonedEntity, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Alias) Clone() (*Alias, error) {
|
|
|
|
if p == nil {
|
|
|
|
return nil, fmt.Errorf("nil alias")
|
|
|
|
}
|
|
|
|
|
|
|
|
marshaledAlias, err := proto.Marshal(p)
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to marshal alias: {{err}}", err)
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var clonedAlias Alias
|
|
|
|
err = proto.Unmarshal(marshaledAlias, &clonedAlias)
|
|
|
|
if err != nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return nil, errwrap.Wrapf("failed to unmarshal alias: {{err}}", err)
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &clonedAlias, nil
|
|
|
|
}
|