protected PropertyObject(ObjectIdentifier identifier, IDictionary <string, string> tags,
                                 bool?enabled, DateTime?expires, DateTime?notBefore,
                                 PropertyChangedEventHandler propertyChanged)
        {
            Identifier = identifier;
            Name       = identifier?.Name;

            Tags = new ObservableTagItemsCollection();
            if (null != tags)
            {
                foreach (var kvp in tags)
                {
                    Tags.Add(new TagItem(kvp));
                }
            }
            Tags.SetPropertyChangedEventHandler(propertyChanged);

            _enabled   = enabled;
            _expires   = expires;
            _notBefore = notBefore;

            SecretKind = new SecretKind(); // Default - Custom secret kind

            PropertyChanged += propertyChanged;
        }
Exemple #2
0
        /// <summary>
        /// New empty secret
        /// </summary>
        public SecretDialog(ISession session) : this(session, "New secret", ItemDialogBaseMode.New)
        {
            _changed = true;
            var s = new SecretBundle()
            {
                Attributes = new SecretAttributes(), ContentType = ContentTypeEnumConverter.GetDescription(ContentType.Text)
            };

            RefreshSecretObject(s);
            SecretKind defaultSK    = TryGetDefaultSecretKind();
            int        defaultIndex = uxMenuSecretKind.Items.IndexOf(defaultSK);

            uxMenuSecretKind.Items[defaultIndex].PerformClick();
        }
        private void AutoDetectSecretKind()
        {
            SecretKind autoDetectSecretKind = (SecretKind)uxMenuSecretKind.Items[0]; // Default is the first one which is always Custom

            foreach (var item in uxMenuSecretKind.Items)                             // Auto detect 'last' secret kind based on the name only
            {
                SecretKind sk = (SecretKind)item;
                autoDetectSecretKind = sk.NameRegex.IsMatch(uxTextBoxName.Text) ? sk : 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 = (SecretKind)uxMenuSecretKind.Items[0];
            }
            _certificateObj = PropertyObject.ContentType.IsCertificate() ? CertificateValueObject.FromValue(uxTextBoxValue.Text) : null;
            autoDetectSecretKind?.PerformClick();
        }
Exemple #4
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);
            }
        }
 public abstract void AddOrUpdateSecretKind(SecretKind sk);
Exemple #7
0
 public override void AddOrUpdateSecretKind(SecretKind sk)
 {
 }