Unmarshal deserialize the passed uidmap and gidmap strings into a IDMap object. Error is returned in case of failure
(uidMap, gidMap string)
| 95 | // Unmarshal deserialize the passed uidmap and gidmap strings |
| 96 | // into a IDMap object. Error is returned in case of failure |
| 97 | func (i *IDMap) Unmarshal(uidMap, gidMap string) error { |
| 98 | unmarshal := func(str string, fn func(m specs.LinuxIDMapping)) error { |
| 99 | if len(str) == 0 { |
| 100 | return nil |
| 101 | } |
| 102 | for mapping := range strings.SplitSeq(str, ",") { |
| 103 | m, err := deserializeLinuxIDMapping(mapping) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | fn(m) |
| 108 | } |
| 109 | return nil |
| 110 | } |
| 111 | if err := unmarshal(uidMap, func(m specs.LinuxIDMapping) { |
| 112 | i.UidMap = append(i.UidMap, m) |
| 113 | }); err != nil { |
| 114 | return err |
| 115 | } |
| 116 | return unmarshal(gidMap, func(m specs.LinuxIDMapping) { |
| 117 | i.GidMap = append(i.GidMap, m) |
| 118 | }) |
| 119 | } |
| 120 | |
| 121 | // toHost takes an id mapping and a remapped ID, and translates the |
| 122 | // ID to the mapped host ID. If no map is provided, then the translation |