public string Verify(TagItem tagItem, bool required)
        {
            if (null == tagItem)
            {
                return(required ? $"Tag {Name} is required\n" : "");
            }
            var m = ValueRegex.Match(tagItem.Value);

            return(m.Success ? "" : $"Tag {Name} value must match the following regex: {ValueRegex}\n");
        }
Esempio n. 2
0
        private void AutoDetectSecretKind()
        {
            SecretKind defaultSecretKind    = TryGetDefaultSecretKind(); // Default is the first one which is always Custom
            SecretKind autoDetectSecretKind = new SecretKind(defaultSecretKind.Alias);
            TagItem    currentSKTag         = PropertyObject.Tags.GetOrNull(new TagItem(Consts.SecretKindKey, ""));
            bool       shouldAddNew         = true;

            // Read the CustomTags and determine the SecretKind
            foreach (SecretKind sk in uxMenuSecretKind.Items) // Auto detect 'last' secret kind based on the name only
            {
                if (currentSKTag == null)
                {
                    autoDetectSecretKind = defaultSecretKind;
                    shouldAddNew         = false;
                    break;
                }

                // If the current Secret Kind is in the list of menu items,
                if (currentSKTag.Value == sk.Alias)
                {
                    autoDetectSecretKind = sk;
                    shouldAddNew         = false;
                    break;
                }
            }
            if (shouldAddNew)
            {
                autoDetectSecretKind = new SecretKind(currentSKTag.Value);
                uxMenuSecretKind.Items.Add(autoDetectSecretKind);
            }

            // Apply last found secret kind, only when both Content Type and SecretKind are certificate or both not, otherwise fallback to Custom (the first one)
            if ((!PropertyObject.ContentType.IsCertificate() || !autoDetectSecretKind.IsCertificate) &&
                (PropertyObject.ContentType.IsCertificate() || autoDetectSecretKind.IsCertificate))
            {
                autoDetectSecretKind = TryGetDefaultSecretKind();
            }
            _certificateObj = PropertyObject.ContentType.IsCertificate() ? CertificateValueObject.FromValue(uxTextBoxValue.Text) : null;
            autoDetectSecretKind?.PerformClick();
        }
        // This method updates the SecretKind tag in Custom Tags
        public override void AddOrUpdateSecretKind(SecretKind sk)
        {
            TagItem newTag = new TagItem(Consts.SecretKindKey, sk.Alias);
            TagItem oldTag = this.Tags.GetOrNull(newTag);

            // Don't add the SecretKind to a secret that doesn't have any custom tags
            if ((null == _customTags) || (_customTags.Count == 0))
            {
                return;
            }

            // Don't add the SecretKind to a secret that's defaulted to Custom
            if (sk.Alias == "Custom" && !this.Tags.Contains(newTag))
            {
                return;
            }

            // Don't add the SecretKind to a secret that is defaulted to Custom and doesn't have any custom tags.
            if (oldTag == null && newTag.Value == "Custom")
            {
                return;
            }

            if (oldTag == null) // Add the SecretKind tag
            {
                Tags.AddOrReplace(newTag);
            }
            else if (oldTag.Value != newTag.Value) // Update the SecretKind tag
            {
                Tags.AddOrReplace(newTag);
            }
            else // Leave the SecretKind tag alone
            {
                Tags.AddOrReplace(oldTag);
            }
        }
Esempio n. 4
0
 public bool Equals(TagItem ti) => (ti != null) && (0 == string.Compare(ti.Name, Name, true));