Пример #1
0
        /// <summary>
        /// Retrieves a configuration value or resolves the settings to its corresponding object
        /// Uses an in-memory cache in which throws away content after a certain time.
        /// </summary>
        /// <param name="settingName"> The setting name to get resolved or retrieved </param>
        /// <param name="cachedExpirationTimeSpan"> The cache expiration time span </param>
        /// <returns> The retrieved or resolved setting </returns>
        public static async Task <string> GetSettingAsync(string settingName, TimeSpan?cachedExpirationTimeSpan = null)
        {
            var settingValue = GetConfigurationSetting(settingName);

            // The secret value is cached along with the secret URL as a seperate cached entry because otherwise each time the secret URL would be
            // retrieved from configuration file and if the secret value overwrites the secret URL, from different threads, the secret could be retrieved multiple times
            if (SecretIdentifier.IsSecretIdentifier(settingValue))
            {
                return(await ResolveSecretSettingAsync(settingValue, cachedExpirationTimeSpan).ConfigureAwait(false));
            }

            // this could be extended to other types of resolution

            return(settingValue);
        }
Пример #2
0
        public void SecretIdentifierTest()
        {
            string baseId      = string.Format("{0}/secrets/{1}", vault, name);
            string versionedId = string.Format("{0}/{1}", baseId, version);

            //unversioned
            var id = new SecretIdentifier(baseId);

            Assert.Equal(baseId, id.BaseIdentifier);
            Assert.Equal(baseId, id.Identifier);
            Assert.Equal(vault, id.Vault);
            Assert.Equal(name, id.Name);
            Assert.Equal(string.Empty, id.Version);
            Assert.True(SecretIdentifier.IsSecretIdentifier(baseId));

            //versioned
            id = new SecretIdentifier(versionedId);
            Assert.Equal(baseId, id.BaseIdentifier);
            Assert.Equal(versionedId, id.Identifier);
            Assert.Equal(vault, id.Vault);
            Assert.Equal(name, id.Name);
            Assert.Equal(version, id.Version);
            Assert.True(SecretIdentifier.IsSecretIdentifier(versionedId));
        }