Example #1
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(ParentObjectParameterSetName, StringComparison.InvariantCulture))
            {
                ResourceGroupName = ParentObject.ResourceGroupName;
                ServiceName       = ParentObject.Name;
            }
            else if (ParameterSetName.Equals(ParentResourceIdParameterSetName, StringComparison.InvariantCulture))
            {
                var id = new ResourceIdentifier(ParentResourceId);
                ResourceGroupName = id.ResourceGroupName;
                ServiceName       = id.ResourceName;
            }

            ConfirmAction(Force.IsPresent,
                          string.Format(Resources.RegenerateAdminKeyWarning, KeyKind.ToString(), ServiceName),
                          string.Format(Resources.RegenerateAdminKey, KeyKind.ToString(), ServiceName),
                          KeyKind.ToString(),
                          () =>
            {
                CatchThrowInnerException(() =>
                {
                    var res = SearchClient.AdminKeys.RegenerateWithHttpMessagesAsync(ResourceGroupName, ServiceName, (AdminKeyKind)(KeyKind)).Result;
                    WriteAdminKey(res.Body);
                });
            }
                          );
        }
Example #2
0
 private Key(string name, KeyKind kind, List <Chord> chords)
 {
     Name    = name;
     Kind    = kind;
     Chords  = chords;
     Pitches = chords.Select(c => c.First).ToList();
 }
Example #3
0
        /// <summary>
        /// Returns the KeyKind if <paramref name="propertyInfo"/> is declared as a key in <paramref name="dataServiceKeyAttribute"/> or it follows the key naming convention.
        /// </summary>
        /// <param name="propertyInfo">Property in question.</param>
        /// <param name="dataServiceKeyAttribute">DataServiceKeyAttribute instance.</param>
        /// <returns>Returns the KeyKind if <paramref name="propertyInfo"/> is declared as a key in <paramref name="dataServiceKeyAttribute"/> or it follows the key naming convention.</returns>
        private static KeyKind IsKeyProperty(PropertyInfo propertyInfo, KeyAttribute dataServiceKeyAttribute)
        {
            Debug.Assert(propertyInfo != null, "propertyInfo != null");

            string propertyName = GetServerDefinedName(propertyInfo);

            KeyKind keyKind = KeyKind.NotKey;

            if (dataServiceKeyAttribute != null && dataServiceKeyAttribute.KeyNames.Contains(propertyName))
            {
                keyKind = KeyKind.AttributedKey;
            }
#if !PORTABLELIB
            else if (propertyInfo.GetCustomAttributes().OfType <System.ComponentModel.DataAnnotations.KeyAttribute>().Any())
            {
                keyKind = KeyKind.AttributedKey;
            }
#endif
            else if (propertyName.EndsWith("ID", StringComparison.Ordinal))
            {
                string declaringTypeName = propertyInfo.DeclaringType.Name;
                if ((propertyName.Length == (declaringTypeName.Length + 2)) && propertyName.StartsWith(declaringTypeName, StringComparison.Ordinal))
                {
                    // matched "DeclaringType.Name+ID" pattern
                    keyKind = KeyKind.TypeNameId;
                }
                else if (propertyName.Length == 2)
                {
                    // matched "ID" pattern
                    keyKind = KeyKind.Id;
                }
            }

            return(keyKind);
        }
Example #4
0
        Key InternalizeReference(Key localkey)
        {
            KeyKind triage = (localhost.GetKeyKind(localkey));

            if (triage == KeyKind.Foreign)
            {
                throw new ArgumentException("Cannot internalize foreign reference");
            }

            if (triage == KeyKind.Temporary)
            {
                Key replacement = mapper.TryGet(localkey);
                if (replacement != null)
                {
                    return(replacement);
                }
                else
                {
                    throw Error.Create(HttpStatusCode.Conflict, "This reference does not point to a resource in the server or the current transaction: {0}", localkey);
                }
            }
            else if (triage == KeyKind.Local)
            {
                return(localkey.WithoutBase());
            }
            else
            {
                return(localkey);
            }
        }
Example #5
0
        IKey GetReplacement(IKey localkey)
        {
            IKey replacement = localkey;

            //CCR: To check if this is still needed. Since we don't store the version in the mapper, do we ever need to replace the key multiple times?
            while (mapper.Exists(replacement.ResourceId))
            {
                KeyKind triage = (localhost.GetKeyKind(localkey));
                if (triage == KeyKind.Temporary)
                {
                    replacement = mapper.TryGet(replacement.ResourceId);
                }
                else
                {
                    replacement = mapper.TryGet(replacement.ToString());
                }
            }

            if (replacement != null)
            {
                return(replacement);
            }
            else
            {
                throw Error.Create(HttpStatusCode.Conflict, "This reference does not point to a resource in the server or the current transaction: {0}", localkey);
            }
        }
Example #6
0
        Key InternalizeReference(Key original)
        {
            KeyKind triage = (localhost.GetKeyKind(original));

            if (triage == KeyKind.Foreign | triage == KeyKind.Temporary)
            {
                Key replacement = mapper.TryGet(original);
                if (replacement != null)
                {
                    return(replacement);
                }
                else
                {
                    throw Error.Create(HttpStatusCode.Conflict, "This reference does not point to a resource in the server or the current transaction: {0}", original);
                }
            }
            else if (triage == KeyKind.Local)
            {
                return(original.WithoutBase());
            }
            else
            {
                return(original);
            }
        }
Example #7
0
        /// <summary>
        /// Returns the KeyKind if <paramref name="propertyInfo"/> is declared as a key in <paramref name="dataServiceKeyAttribute"/> or it follows the key naming convension.
        /// </summary>
        /// <param name="propertyInfo">Property in question.</param>
        /// <param name="dataServiceKeyAttribute">DataServiceKeyAttribute instance.</param>
        /// <returns>Returns the KeyKind if <paramref name="propertyInfo"/> is declared as a key in <paramref name="dataServiceKeyAttribute"/> or it follows the key naming convension.</returns>
        private static KeyKind IsKeyProperty(PropertyInfo propertyInfo, KeyAttribute dataServiceKeyAttribute)
        {
            Debug.Assert(propertyInfo != null, "propertyInfo != null");

            string propertyName = GetServerDefinedName(propertyInfo);

            KeyKind keyKind = KeyKind.NotKey;

            if (dataServiceKeyAttribute != null && dataServiceKeyAttribute.KeyNames.Contains(propertyName))
            {
                keyKind = KeyKind.AttributedKey;
            }
            else if (propertyName.EndsWith("ID", StringComparison.Ordinal))
            {
                string declaringTypeName = propertyInfo.DeclaringType.Name;
                if ((propertyName.Length == (declaringTypeName.Length + 2)) && propertyName.StartsWith(declaringTypeName, StringComparison.Ordinal))
                {
                    // matched "DeclaringType.Name+ID" pattern
                    keyKind = KeyKind.TypeNameId;
                }
                else if (2 == propertyName.Length)
                {
                    // matched "ID" pattern
                    keyKind = KeyKind.Id;
                }
            }

            return(keyKind);
        }
Example #8
0
 private MutableKeySet CreateNewKeySetMeta(KeyKind type, KeyPurpose purpose, string name = null)
 {
     return(new MutableKeySet(new KeyMetadata
     {
         Name = name ?? "Test",
         Purpose = purpose,
         Kind = type
     }));
 }
        /// <summary>
        /// Seeds the given database
        /// </summary>
        /// <param name="context">The database to be seeded</param>
        public static void Seed(this PocDbContext context)
        {
            context.Database.Migrate();

            if (!context.Set <Role>().Any())
            {
                context.AddRange(Role.List());
                context.AddRange(Status.List());
                context.AddRange(KeyKind.List());

                context.SaveChanges();
            }
        }
        private async Task InternalWriteKeyAsync(string id, string value, KeyKind kind)
        {
            var key = await _context.CryptoKeys.FirstOrDefaultAsync(c => c.Id == id && c.KindId == kind.Id);

            if (key == null)
            {
                var cryptoKey = new CryptoKey
                {
                    Id     = id,
                    KindId = kind.Id,
                    Value  = value
                };
                _context.Add(cryptoKey);
            }
            else
            {
                key.Value = value;
                _context.Update(key);
            }

            await _context.SaveChangesAsync();
        }
Example #11
0
        IKey InternalizeReference(IKey localkey)
        {
            KeyKind triage = (localhost.GetKeyKind(localkey));

            if (triage == KeyKind.Foreign)
            {
                throw new ArgumentException("Cannot internalize foreign reference");
            }

            if (triage == KeyKind.Temporary)
            {
                return(GetReplacement(localkey));
            }
            else if (triage == KeyKind.Local)
            {
                return(localkey.WithoutBase());
            }
            else
            {
                return(localkey);
            }
        }
Example #12
0
        private static KeyKind IsKeyProperty(PropertyInfo propertyInfo, DataServiceKeyAttribute dataServiceKeyAttribute)
        {
            string  name   = propertyInfo.Name;
            KeyKind notKey = KeyKind.NotKey;

            if ((dataServiceKeyAttribute != null) && dataServiceKeyAttribute.KeyNames.Contains(name))
            {
                return(KeyKind.AttributedKey);
            }
            if (name.EndsWith("ID", StringComparison.Ordinal))
            {
                string str2 = propertyInfo.DeclaringType.Name;
                if ((name.Length == (str2.Length + 2)) && name.StartsWith(str2, StringComparison.Ordinal))
                {
                    return(KeyKind.TypeNameId);
                }
                if (2 == name.Length)
                {
                    notKey = KeyKind.Id;
                }
            }
            return(notKey);
        }
 public DatabaseAccountRegenerateKeyContent(KeyKind keyKind)
 {
     KeyKind = keyKind;
 }
Example #14
0
        internal static PropertyInfo[] GetKeyPropertiesOnType(Type type, out bool hasProperties)
        {
            Func <string, bool> predicate = null;

            if (CommonUtil.IsUnsupportedType(type))
            {
                throw new InvalidOperationException(System.Data.Services.Client.Strings.ClientType_UnsupportedType(type));
            }
            string str = type.ToString();
            IEnumerable <object> customAttributes = type.GetCustomAttributes(true);
            bool flag = customAttributes.OfType <DataServiceEntityAttribute>().Any <DataServiceEntityAttribute>();
            DataServiceKeyAttribute dataServiceKeyAttribute = customAttributes.OfType <DataServiceKeyAttribute>().FirstOrDefault <DataServiceKeyAttribute>();
            List <PropertyInfo>     list = new List <PropertyInfo>();

            PropertyInfo[] properties = GetPropertiesOnType(type, false).ToArray <PropertyInfo>();
            hasProperties = properties.Length > 0;
            KeyKind notKey = KeyKind.NotKey;
            KeyKind kind2  = KeyKind.NotKey;

            foreach (PropertyInfo info in properties)
            {
                if ((kind2 = IsKeyProperty(info, dataServiceKeyAttribute)) != KeyKind.NotKey)
                {
                    if (kind2 > notKey)
                    {
                        list.Clear();
                        notKey = kind2;
                        list.Add(info);
                    }
                    else if (kind2 == notKey)
                    {
                        list.Add(info);
                    }
                }
            }
            Type declaringType = null;

            foreach (PropertyInfo info2 in list)
            {
                if (null == declaringType)
                {
                    declaringType = info2.DeclaringType;
                }
                else if (declaringType != info2.DeclaringType)
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_KeysOnDifferentDeclaredType(str));
                }
                if (!PrimitiveType.IsKnownType(info2.PropertyType))
                {
                    throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_KeysMustBeSimpleTypes(str));
                }
            }
            if ((kind2 == KeyKind.AttributedKey) && (list.Count != dataServiceKeyAttribute.KeyNames.Count))
            {
                if (predicate == null)
                {
                    predicate = a => null == (from b in properties
                                              where b.Name == a
                                              select b).FirstOrDefault <PropertyInfo>();
                }
                string str2 = dataServiceKeyAttribute.KeyNames.Cast <string>().Where <string>(predicate).First <string>();
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingProperty(str, str2));
            }
            if (list.Count > 0)
            {
                return(list.ToArray());
            }
            if (!flag)
            {
                return(null);
            }
            return(EmptyPropertyInfoArray);
        }
Example #15
0
 public KeySetting(KeyCode key, Action func, KeyKind kind = KeyKind.Press)
 {
     KeyValue = key;
     Func     = func;
     Kind     = kind;
 }
Example #16
0
 public InputComponent(KeyKind keyKind)
 {
     _inputStyle = keyKind;
 }
Example #17
0
 public DatabaseAccountRegenerateKeyData(KeyKind keyKind)
 {
     KeyKind = keyKind;
 }
 /// <summary>
 /// Regenerates an access key for the specified Azure Cosmos DB database
 /// account.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Name of an Azure resource group.
 /// </param>
 /// <param name='accountName'>
 /// Cosmos DB database account name.
 /// </param>
 /// <param name='keyKind'>
 /// The access key to regenerate. Possible values include: 'primary',
 /// 'secondary', 'primaryReadonly', 'secondaryReadonly'
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task BeginRegenerateKeyAsync(this IDatabaseAccountsOperations operations, string resourceGroupName, string accountName, KeyKind keyKind, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.BeginRegenerateKeyWithHttpMessagesAsync(resourceGroupName, accountName, keyKind, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
 public DatabaseAccountRegenerateKeyOptions(KeyKind keyKind)
 {
     KeyKind = keyKind;
 }
Example #20
0
 public void SetKey(KeyKind type, byte[] key)
 {
     SetKey(type, key, key.Length * 8);
 }
Example #21
0
 internal static extern int k_bcmode_set_key(UIntPtr context, [In] byte[] key, UInt32 bits, KeyKind type);
Example #22
0
        /// <summary>
        /// Returns the list of key properties defined on <paramref name="type"/>; null if <paramref name="type"/> is complex.
        /// </summary>
        /// <param name="type">Type in question.</param>
        /// <param name="hasProperties">true if <paramref name="type"/> has any (declared or inherited) properties; otherwise false.</param>
        /// <returns>Returns the list of key properties defined on <paramref name="type"/>; null if <paramref name="type"/> is complex.</returns>
        internal static PropertyInfo[] GetKeyPropertiesOnType(Type type, out bool hasProperties)
        {
            if (CommonUtil.IsUnsupportedType(type))
            {
                throw new InvalidOperationException(c.Strings.ClientType_UnsupportedType(type));
            }

            string typeName = type.ToString();
            IEnumerable <object> customAttributes       = type.GetCustomAttributes(true);
            bool                isEntity                = customAttributes.OfType <EntityTypeAttribute>().Any();
            KeyAttribute        dataServiceKeyAttribute = customAttributes.OfType <KeyAttribute>().FirstOrDefault();
            List <PropertyInfo> keyProperties           = new List <PropertyInfo>();

            PropertyInfo[] properties = ClientTypeUtil.GetPropertiesOnType(type, false /*declaredOnly*/).ToArray();

            hasProperties = properties.Length > 0;
            KeyKind currentKeyKind = KeyKind.NotKey;
            KeyKind newKeyKind     = KeyKind.NotKey;

            foreach (PropertyInfo propertyInfo in properties)
            {
                if ((newKeyKind = ClientTypeUtil.IsKeyProperty(propertyInfo, dataServiceKeyAttribute)) != KeyKind.NotKey)
                {
                    if (newKeyKind > currentKeyKind)
                    {
                        keyProperties.Clear();
                        currentKeyKind = newKeyKind;
                        keyProperties.Add(propertyInfo);
                    }
                    else if (newKeyKind == currentKeyKind)
                    {
                        keyProperties.Add(propertyInfo);
                    }
                }
            }

            Type keyPropertyDeclaringType = null;

            foreach (PropertyInfo key in keyProperties)
            {
                if (keyPropertyDeclaringType == null)
                {
                    keyPropertyDeclaringType = key.DeclaringType;
                }
                else if (keyPropertyDeclaringType != key.DeclaringType)
                {
                    throw c.Error.InvalidOperation(c.Strings.ClientType_KeysOnDifferentDeclaredType(typeName));
                }

                if (!PrimitiveType.IsKnownType(key.PropertyType) && !(key.PropertyType.GetGenericTypeDefinition() == typeof(System.Nullable <>) && key.PropertyType.GetGenericArguments().First().IsEnum()))
                {
                    throw c.Error.InvalidOperation(c.Strings.ClientType_KeysMustBeSimpleTypes(key.Name, typeName, key.PropertyType.FullName));
                }
            }

            if (newKeyKind == KeyKind.AttributedKey && keyProperties.Count != dataServiceKeyAttribute?.KeyNames.Count)
            {
                var m = (from string a in dataServiceKeyAttribute.KeyNames
                         where (from b in properties
                                where b.Name == a
                                select b).FirstOrDefault() == null
                         select a).First <string>();
                throw c.Error.InvalidOperation(c.Strings.ClientType_MissingProperty(typeName, m));
            }

            return(keyProperties.Count > 0 ? keyProperties.ToArray() : (isEntity ? ClientTypeUtil.EmptyPropertyInfoArray : null));
        }
Example #23
0
 public void SetKey(KeyKind type, byte[] key, int bits)
 {
     if (key == null)
         throw new ArgumentNullException();
     if (bits > int.MaxValue - 7)
         throw new ArgumentException();
     if (key.Length < ((bits + 7) / 8))
         throw new ArgumentOutOfRangeException();
     if (SafeNativeMethods.k_bcmode_set_key(context, key, (uint)bits, type) != 0)
         UnmanagedError.ThrowLastError();
 }
Example #24
0
 public DatabaseAccountRegenerateKeyParameters(KeyKind keyKind)
 {
     KeyKind = keyKind;
 }
Example #25
0
 private Key(string name, KeyKind kind, List <Pitch> pitches)
 {
     Name    = name;
     Kind    = kind;
     Pitches = pitches;
 }
 public async Task RegenerateKeyAsync(string groupName, string accountName, string keyKind, CancellationToken cancellationToken = default(CancellationToken))
 {
     await this.Manager.Inner.DatabaseAccounts.RegenerateKeyAsync(groupName, accountName, KeyKind.Parse(keyKind));
 }
Example #27
0
 internal HardcodedKeyType(String identifier, Type representedType, KeyKind kind) : base(identifier)
 {
     _representedType = representedType;
     _kind            = kind;
 }