-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e1438b
commit 0611d5f
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package mapper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/rancher/norman/types" | ||
) | ||
|
||
type Copy struct { | ||
From, To string | ||
} | ||
|
||
func (c Copy) FromInternal(data map[string]interface{}) { | ||
if data == nil { | ||
return | ||
} | ||
v, ok := data[c.From] | ||
if ok { | ||
data[c.To] = v | ||
} | ||
} | ||
|
||
func (c Copy) ToInternal(data map[string]interface{}) { | ||
if data == nil { | ||
return | ||
} | ||
t, tok := data[c.To] | ||
_, fok := data[c.From] | ||
if tok && !fok { | ||
data[c.From] = t | ||
} | ||
} | ||
|
||
func (c Copy) ModifySchema(s *types.Schema, schemas *types.Schemas) error { | ||
f, ok := s.ResourceFields[c.From] | ||
if !ok { | ||
return fmt.Errorf("field %s missing on schema %s", c.From, s.ID) | ||
} | ||
|
||
s.ResourceFields[c.To] = f | ||
return nil | ||
} |