This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for retention policies on containers (#3501)
- [x] ability to specify a retention period on a container, which applies to newly-created blobs - [x] specify default retention periods in templates from CLI side There's a small breaking change to the Python JobHelper class.
- Loading branch information
Showing
19 changed files
with
393 additions
and
184 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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
using System.Xml; | ||
|
||
namespace Microsoft.OneFuzz.Service; | ||
|
||
|
||
public interface IRetentionPolicy { | ||
DateOnly GetExpiryDate(); | ||
} | ||
|
||
public class RetentionPolicyUtils { | ||
public const string EXPIRY_TAG = "Expiry"; | ||
public static KeyValuePair<string, string> CreateExpiryDateTag(DateOnly expiryDate) => | ||
new(EXPIRY_TAG, expiryDate.ToString()); | ||
|
||
public static DateOnly? GetExpiryDateTagFromTags(IDictionary<string, string>? blobTags) { | ||
if (blobTags != null && | ||
blobTags.TryGetValue(EXPIRY_TAG, out var expiryTag) && | ||
!string.IsNullOrWhiteSpace(expiryTag) && | ||
DateOnly.TryParse(expiryTag, out var expiryDate)) { | ||
return expiryDate; | ||
} | ||
return null; | ||
} | ||
|
||
public static string CreateExpiredBlobTagFilter() => $@"""{EXPIRY_TAG}"" <= '{DateOnly.FromDateTime(DateTime.UtcNow)}'"; | ||
|
||
// NB: this must match the value used on the CLI side | ||
public const string CONTAINER_RETENTION_KEY = "onefuzz_retentionperiod"; | ||
|
||
public static OneFuzzResult<TimeSpan?> GetContainerRetentionPeriodFromMetadata(IDictionary<string, string>? containerMetadata) { | ||
if (containerMetadata is not null && | ||
containerMetadata.TryGetValue(CONTAINER_RETENTION_KEY, out var retentionString) && | ||
!string.IsNullOrWhiteSpace(retentionString)) { | ||
try { | ||
return Result.Ok<TimeSpan?>(XmlConvert.ToTimeSpan(retentionString)); | ||
} catch (Exception ex) { | ||
return Error.Create(ErrorCode.INVALID_RETENTION_PERIOD, ex.Message); | ||
} | ||
} | ||
|
||
return Result.Ok<TimeSpan?>(null); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.