Skip to content

Commit

Permalink
Add validation of input arguments to clones controller
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbouetsmith committed Jun 9, 2024
1 parent 1b50fd7 commit 8983f87
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/Api/Controllers/ClonesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public Response<IEnumerable<Dataset>> ListClones()
{
DatasetTypes = DatasetTypes.Filesystem | DatasetTypes.Volume
};

if (!args.Validate(out var errors))
{
return ToErrorResponse<IEnumerable<Dataset>>(errors);
}
var datasets = _zfs.Datasets.List(args);
var clones = datasets.Where(d => d.IsClone);
return new Response<IEnumerable<Dataset>> { Data = clones };
Expand All @@ -53,6 +58,12 @@ public Response CreateClone(string dataset, string snapshot, [FromBody] CloneReq
var properties = request.Properties.Select(p => new PropertyValue { Property = p.Name, Value = p.Value }).ToList();
args.Properties = properties;
}

if (!args.Validate(out var errors))
{
return ToErrorResponse(errors);
}

_zfs.Snapshots.Clone(args);
return new Response();
}
Expand All @@ -67,6 +78,12 @@ public Response CreateClone(string dataset, string snapshot, [FromBody] CloneReq
public Response PromoteClone(string name)
{
var args = new PromoteArgs { Name = name };

if (!args.Validate(out var errors))
{
return ToErrorResponse(errors);
}

_zfs.Datasets.Promote(args);
return new Response();
}
Expand Down

0 comments on commit 8983f87

Please sign in to comment.