// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace Jupiter { // ReSharper disable once ClassNeverInstantiated.Global public class ReplicationSettings : IValidatableObject { /// /// Enable to start a replicating another Jupiter instance into this one /// public bool Enabled { get; set; } = false; /// /// The frequency at which to poll for new replication events /// [Required] [Range(15, int.MaxValue)] public int ReplicationPollFrequencySeconds { get; set; } = 60; [Required] [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "Used by serialization")] // ReSharper disable once CollectionNeverUpdated.Global public List Replicators { get; set; } = new List(); public IEnumerable Validate(ValidationContext validationContext) { List results = new List(); if (!Enabled) { return results; } Validator.TryValidateProperty(ReplicationPollFrequencySeconds, new ValidationContext(this, null, null) { MemberName = nameof(ReplicationPollFrequencySeconds) }, results); Validator.TryValidateProperty(Replicators, new ValidationContext(this, null, null) { MemberName = nameof(Replicators) }, results); return results; } } public class ReplicatorSettings { /// /// The namespace which this replicator is replicating, will be used both on the source and destination side /// [Required] public string NamespaceToReplicate { get; set; } = ""; /// /// Name of this replicator instance, should be unique within the cluster /// [Required] [Key] public string ReplicatorName { get; set; } = ""; /// /// The connection string to the remote jupiter instance which will be replicated /// [Required] [Url] public string ConnectionString { get; set; } = ""; public ReplicatorVersion Version { get; set; } = ReplicatorVersion.Refs; /// /// Max number of replications that can run in parallel, set to -1 to for it to be one per CPU (can easily be oversubscribed) /// public int MaxParallelReplications { get; set; } = 64; /// /// Do not read in old history using a snapshot, instead just start replicating the new incremental state. Means we will only have partial state but we will also get going quicker on relatively useful blobs. /// public bool SkipSnapshot { get; set; } = false; /// /// The number of records returned in a single response (page) if available, this needs to be bumped as you increase `MaxParallelReplications` /// public int PageSize { get; set; } = 1000; } public enum ReplicatorVersion { Refs, Blobs } public class ServiceCredentialSettings { /// /// The client id to use for communication with other services /// public string OAuthClientId { get; set; } = ""; /// /// The client secret to use for communication with other services /// public string OAuthClientSecret { get; set; } = ""; /// /// The url to login for a token to use to connect to the other services. Set to empty to disable login, assuming a unprotected service. /// public Uri? OAuthLoginUrl { get; set; } = null; /// /// The scope to request /// public string OAuthScope { get; set; } = "cache_access"; /// /// The authentication scheme to use for this token /// public string SchemeName { get; set; } = "Bearer"; /// /// The access token to use if not using OIDC. Can be resolved using a secret string. /// public string? AccessToken { get; set; } = null; } }