Skip to content

Commit e200776

Browse files
committed
dockerfile: split validateMount
Signed-off-by: Akihiro Suda <[email protected]>
1 parent ca432f4 commit e200776

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

frontend/dockerfile/instructions/commands_runmount.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,24 @@ func parseMount(val string, expander SingleWordExpander) (*Mount, error) {
252252
}
253253
}
254254

255+
if err = validateMount(m, roAuto); err != nil {
256+
return nil, err
257+
}
258+
return m, nil
259+
}
260+
261+
func validateMount(m *Mount, roAuto bool) error {
255262
fileInfoAllowed := m.Type == MountTypeSecret || m.Type == MountTypeSSH || m.Type == MountTypeCache
256263

257264
if !fileInfoAllowed {
258265
if m.Mode != nil {
259-
return nil, errors.Errorf("mode not allowed for %q type mounts", m.Type)
266+
return errors.Errorf("mode not allowed for %q type mounts", m.Type)
260267
}
261268
if m.UID != nil {
262-
return nil, errors.Errorf("uid not allowed for %q type mounts", m.Type)
269+
return errors.Errorf("uid not allowed for %q type mounts", m.Type)
263270
}
264271
if m.GID != nil {
265-
return nil, errors.Errorf("gid not allowed for %q type mounts", m.Type)
272+
return errors.Errorf("gid not allowed for %q type mounts", m.Type)
266273
}
267274
}
268275

@@ -276,22 +283,22 @@ func parseMount(val string, expander SingleWordExpander) (*Mount, error) {
276283

277284
if m.Type == MountTypeSecret {
278285
if m.From != "" {
279-
return nil, errors.Errorf("secret mount should not have a from")
286+
return errors.Errorf("secret mount should not have a from")
280287
}
281288
if m.CacheSharing != "" {
282-
return nil, errors.Errorf("secret mount should not define sharing")
289+
return errors.Errorf("secret mount should not define sharing")
283290
}
284291
if m.Source == "" && m.Target == "" && m.CacheID == "" {
285-
return nil, errors.Errorf("invalid secret mount. one of source, target required")
292+
return errors.Errorf("invalid secret mount. one of source, target required")
286293
}
287294
if m.Source != "" && m.CacheID != "" {
288-
return nil, errors.Errorf("both source and id can't be set")
295+
return errors.Errorf("both source and id can't be set")
289296
}
290297
}
291298

292299
if m.CacheSharing != "" && m.Type != MountTypeCache {
293-
return nil, errors.Errorf("invalid cache sharing set for %v mount", m.Type)
300+
return errors.Errorf("invalid cache sharing set for %v mount", m.Type)
294301
}
295302

296-
return m, nil
303+
return nil
297304
}

0 commit comments

Comments
 (0)