public static IConfigurationBuilder AddOctopus(
			this IConfigurationBuilder configuration,
			OctopusConfigurationProviderOptions options,
			string appSettingsKeyDelimiter,
			params string[] appSettingsSectionPrefixes)
		{
			if (configuration == null)
			{
				throw new ArgumentNullException(nameof(configuration));
			}

			return configuration.Add(new OctopusConfigurationProvider(options, new OctopusClientVariableDictionaryProvider(), appSettingsKeyDelimiter, appSettingsSectionPrefixes));
		}
        public VariableDictionary Get(OctopusConfigurationProviderOptions options)
        {
            var variableDictionary = new VariableDictionary();

            var endpoint   = new OctopusServerEndpoint(options.ServerAddress.ToString(), options.ApiKey);
            var repository = new OctopusRepository(endpoint);

            var project = repository.Projects.FindByName(options.ProjectName);

            if (project == null)
            {
                return(variableDictionary);
            }

            var scopes = new Dictionary <ScopeField, string>();

            if (!string.IsNullOrEmpty(options.EnvironmentName))
            {
                scopes[ScopeField.Environment] = options.EnvironmentName;
            }
            if (!string.IsNullOrEmpty(options.MachineName))
            {
                scopes[ScopeField.Machine] = options.MachineName;
            }

            var variableSetIds = new List <string> {
                project.VariableSetId
            };

            variableSetIds.AddRange(project.IncludedLibraryVariableSetIds.Select(id => repository.LibraryVariableSets.Get(id).VariableSetId));

            var variables = new Dictionary <string, SortedSet <VariableResource> >();

            foreach (var variableSetId in variableSetIds)
            {
                var variableSet = repository.VariableSets.Get(variableSetId);
                AddVariableSet(variables, variableSet, scopes);
            }

            foreach (var variableName in variables.Keys)
            {
                variableDictionary.Set(variableName, variables[variableName].First().Value);
            }

            return(variableDictionary);
        }
		public OctopusConfigurationProvider(
			OctopusConfigurationProviderOptions options,
			IVariableDictionaryProvider variableDictionaryProvider,
			string appSettingsKeyDelimiter,
			params string[] appSettingsSectionPrefixes)
		{
			if (options == null)
			{
				throw new ArgumentNullException(nameof(options));
			}
			if (variableDictionaryProvider == null)
			{
				throw new ArgumentNullException(nameof(variableDictionaryProvider));
			}

			Options = options;
			VariableDictionaryProvider = variableDictionaryProvider;
			AppSettingsKeyDelimiter = appSettingsKeyDelimiter;
			AppSettingsSectionPrefixes = appSettingsSectionPrefixes;
		}
示例#4
0
        public OctopusConfigurationProvider(
            OctopusConfigurationProviderOptions options,
            IVariableDictionaryProvider variableDictionaryProvider,
            string appSettingsKeyDelimiter,
            params string[] appSettingsSectionPrefixes)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (variableDictionaryProvider == null)
            {
                throw new ArgumentNullException(nameof(variableDictionaryProvider));
            }

            Options = options;
            VariableDictionaryProvider = variableDictionaryProvider;
            AppSettingsKeyDelimiter    = appSettingsKeyDelimiter;
            AppSettingsSectionPrefixes = appSettingsSectionPrefixes;
        }
		public VariableDictionary Get(OctopusConfigurationProviderOptions options)
		{
			var variableDictionary = new VariableDictionary();

			var endpoint = new OctopusServerEndpoint(options.ServerAddress.ToString(), options.ApiKey);
			var repository = new OctopusRepository(endpoint);

			var project = repository.Projects.FindByName(options.ProjectName);
			if (project == null)
			{
				return variableDictionary;
			}

			var scopes = new Dictionary<ScopeField, string>();
			if (!string.IsNullOrEmpty(options.EnvironmentName))
			{
				scopes[ScopeField.Environment] = options.EnvironmentName;
			}
			if (!string.IsNullOrEmpty(options.MachineName))
			{
				scopes[ScopeField.Machine] = options.MachineName;
			}

			var variableSetIds = new List<string> { project.VariableSetId };
			variableSetIds.AddRange(project.IncludedLibraryVariableSetIds.Select(id => repository.LibraryVariableSets.Get(id).VariableSetId));

			var variables = new Dictionary<string, SortedSet<VariableResource>>();
			foreach (var variableSetId in variableSetIds)
			{
				var variableSet = repository.VariableSets.Get(variableSetId);
				AddVariableSet(variables, variableSet, scopes);
			}

			foreach (var variableName in variables.Keys)
			{
				variableDictionary.Set(variableName, variables[variableName].First().Value);
			}

			return variableDictionary;
		}
		public static IConfigurationBuilder AddOctopus(this IConfigurationBuilder configuration, OctopusConfigurationProviderOptions options, string appSettingsKeyDelimiter)
			=> configuration.AddOctopus(options, appSettingsKeyDelimiter, new string[] { });
		public static IConfigurationBuilder AddOctopus(this IConfigurationBuilder configuration, OctopusConfigurationProviderOptions options)
			=> configuration.AddOctopus(options, DefaultAppSettingsKeyDelimiter);