private void BuildServiceInfos()
        {
            _serviceInfos.Clear();

            CloudFoundryApplicationOptions appOpts = new CloudFoundryApplicationOptions();

            _config.Bind(appOpts);
            ApplicationInstanceInfo appInfo = new ApplicationInstanceInfo(appOpts);

            CloudFoundryServicesOptions serviceOpts = new CloudFoundryServicesOptions();

            _config.Bind(serviceOpts);

            foreach (Service s in serviceOpts.Services)
            {
                IServiceInfoFactory factory = FindFactory(s);
                if (factory != null)
                {
                    var info = factory.Create(s) as ServiceInfo;
                    if (info != null)
                    {
                        info.ApplicationInfo = appInfo;
                        _serviceInfos.Add(info);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public FooService(ILoggerFactory loggerFactory, IOptions <CloudFoundryApplicationOptions> appInfo,
                   IOptions <CloudFoundryServicesOptions> serviceInfo)
 {
     _logger      = loggerFactory.CreateLogger <FooService>();
     _appInfo     = appInfo.Value;
     _serviceInfo = serviceInfo.Value;
 }
Ejemplo n.º 3
0
 public OptionsController(
     IOptions <CloudFoundryApplicationOptions> appOptions,
     IOptions <CloudFoundryServicesOptions> serviceOptions)
 {
     this.appOptions     = appOptions.Value;
     this.serviceOptions = serviceOptions.Value;
 }
Ejemplo n.º 4
0
        private void BuildServiceInfos()
        {
            _serviceInfos.Clear();

            CloudFoundryApplicationOptions appOpts = new CloudFoundryApplicationOptions();
            var aopSection = _config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX);

            aopSection.Bind(appOpts);

            ApplicationInstanceInfo appInfo = new ApplicationInstanceInfo(appOpts);
            var serviceSection = _config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);
            CloudFoundryServicesOptions serviceOpts = new CloudFoundryServicesOptions();

            serviceSection.Bind(serviceOpts);

            foreach (KeyValuePair <string, Service[]> serviceopt in serviceOpts.Services)
            {
                foreach (Service s in serviceopt.Value)
                {
                    IServiceInfoFactory factory = FindFactory(s);
                    if (factory != null)
                    {
                        if (factory.Create(s) is ServiceInfo info)
                        {
                            info.ApplicationInfo = appInfo;
                            _serviceInfos.Add(info);
                        }
                    }
                }
            }
        }
        private static string GetRedisConnectionString()
        {
            CloudFoundryServicesOptions services = ServerConfig.CloudFoundryServices;

            foreach (Service s in services.Services)
            {
                Nlog.Trace("Found service {0}: {1} ", s.Name, s);
            }
            Nlog.Trace("Looking for certstore service");
            Service certstore = services.Services.Where(s => s.Name == "certstore").FirstOrDefault();

            if (certstore != null)
            {
                Nlog.Trace("Found certstore!  Creating connection string.");
                String connectionString = String.Format("{0}:{1}",
                                                        certstore.Credentials["host"].Value,
                                                        certstore.Credentials["port"].Value);
                String password = certstore.Credentials["password"].Value;
                if (password != null)
                {
                    connectionString = String.Format(connectionString + ",password={0}", password);
                }
                return(connectionString);
            }

            return(null);
        }
 public CloudFoundryViewModel(CloudFoundryApplicationOptions appOptions, CloudFoundryServicesOptions servOptions, ConfigServerData configData, Dictionary <string, string> connectionStrings)
 {
     CloudFoundryServices    = servOptions;
     CloudFoundryApplication = appOptions;
     ConfigData        = configData;
     ConnectionStrings = connectionStrings;
 }
        public void Constructor_WithSingleServiceConfiguration()
        {
            // Arrange
            var configJson = @"
{ 'vcap': {
    'services' : {
            'p-config-server': [
            {
            'credentials': {
                'access_token_uri': 'https://p-spring-cloud-services.uaa.wise.com/oauth/token',
                'client_id': 'p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef',
                'client_secret': 'e8KF1hXvAnGd',
                'uri': 'http://localhost:8888'
            },
            'label': 'p-config-server',
            'name': 'My Config Server',
            'plan': 'standard',
            'tags': [
                'configuration',
                'spring-cloud'
                ]
            }
            ]
        }
    }
}";
            var memStream  = CloudFoundryConfigurationProvider.GetMemoryStream(configJson);
            var jsonSource = new JsonStreamConfigurationSource(memStream);
            var builder    = new ConfigurationBuilder().Add(jsonSource);
            var config     = builder.Build();

            var options     = new CloudFoundryServicesOptions();
            var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);

            servSection.Bind(options);

            Assert.NotNull(options.Services);
            Assert.Single(options.Services);

            Assert.NotNull(options.Services["p-config-server"]);
            Assert.Single(options.Services["p-config-server"]);

            Assert.Equal("p-config-server", options.ServicesList[0].Label);
            Assert.Equal("My Config Server", options.ServicesList[0].Name);
            Assert.Equal("standard", options.ServicesList[0].Plan);

            Assert.NotNull(options.ServicesList[0].Tags);
            Assert.Equal(2, options.ServicesList[0].Tags.Length);
            Assert.Equal("configuration", options.ServicesList[0].Tags[0]);
            Assert.Equal("spring-cloud", options.ServicesList[0].Tags[1]);

            Assert.NotNull(options.ServicesList[0].Credentials);
            Assert.Equal(4, options.ServicesList[0].Credentials.Count);
            Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", options.ServicesList[0].Credentials["access_token_uri"].Value);
            Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", options.ServicesList[0].Credentials["client_id"].Value);
            Assert.Equal("e8KF1hXvAnGd", options.ServicesList[0].Credentials["client_secret"].Value);
            Assert.Equal("http://localhost:8888", options.ServicesList[0].Credentials["uri"].Value);
        }
Ejemplo n.º 8
0
        public void Constructor_WithIConfigurationRootBinds()
        {
            // Arrange
            var configJson = @"
{
    ""vcap"": {
        ""services"" : {
            ""p-config-server"": [{
                ""credentials"": {
                    ""access_token_uri"": ""https://p-spring-cloud-services.uaa.wise.com/oauth/token"",
                    ""client_id"": ""p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef"",
                    ""client_secret"": ""e8KF1hXvAnGd"",
                    ""uri"": ""http://localhost:8888""
                },
                ""label"": ""p-config-server"",
                ""name"": ""My Config Server"",
                ""plan"": ""standard"",
                ""tags"": [
                    ""configuration"",
                    ""spring-cloud""
                ]
            }]
        }
    }
}";
            var memStream  = CloudFoundryConfigurationProvider.GetMemoryStream(configJson);
            var jsonSource = new JsonStreamConfigurationSource(memStream);
            var builder    = new ConfigurationBuilder().Add(jsonSource);
            var config     = builder.Build();

            var options = new CloudFoundryServicesOptions(config);

            Assert.NotNull(options.Services);
            Assert.Single(options.Services);

            Assert.NotNull(options.Services["p-config-server"]);
            Assert.Single(options.Services["p-config-server"]);

            var firstService = options.GetServicesList().First();

            Assert.Equal("p-config-server", firstService.Label);
            Assert.Equal("My Config Server", firstService.Name);
            Assert.Equal("standard", firstService.Plan);

            Assert.NotNull(firstService.Tags);
            Assert.Equal(2, firstService.Tags.Count());
            Assert.Contains("configuration", firstService.Tags);
            Assert.Contains("spring-cloud", firstService.Tags);

            Assert.NotNull(firstService.Credentials);
            Assert.Equal(4, firstService.Credentials.Count);
            Assert.Equal("https://p-spring-cloud-services.uaa.wise.com/oauth/token", firstService.Credentials["access_token_uri"].Value);
            Assert.Equal("p-config-server-a74fc0a3-a7c3-43b6-81f9-9eb6586dd3ef", firstService.Credentials["client_id"].Value);
            Assert.Equal("e8KF1hXvAnGd", firstService.Credentials["client_secret"].Value);
            Assert.Equal("http://localhost:8888", firstService.Credentials["uri"].Value);
        }
 public ServicesViewModel(CloudFoundryApplicationOptions appOptions, CloudFoundryServicesOptions servOptions, ConfigServerData configData, IDiscoveryClient client, SortedList <int, int> appCounts, SortedList <int, int> srvCounts, List <string> fortunes)
 {
     CloudFoundryServices    = servOptions;
     CloudFoundryApplication = appOptions;
     ConfigData            = configData;
     discoveryClient       = client;
     ServiceInstanceCounts = srvCounts;
     FortuneHistory        = fortunes;
     AppInstanceCounts     = appCounts;
 }
Ejemplo n.º 10
0
        public OptionsController(
            IOptions <CloudFoundryApplicationOptions> appOptions,
            IOptions <CloudFoundryServicesOptions> serviceOptions,
            IOptionsSnapshot <CupsOptions> cupsOptions)
        {
            this.appOptions     = appOptions.Value;
            this.serviceOptions = serviceOptions.Value;

            this.cupsOptions = cupsOptions.Get("tas-cups-database");
        }
 public CredhubController(
     ILogger <CredhubController> logger,
     IConfiguration configuration,
     IOptions <CloudFoundryApplicationOptions> appOptions,
     IOptions <CloudFoundryServicesOptions> serviceOptions)
 {
     _logger         = logger;
     _configuration  = configuration;
     _appOptions     = appOptions.Value;
     _serviceOptions = serviceOptions.Value;
 }
Ejemplo n.º 12
0
 public HomeController(ILogger <HomeController> logger,
                       IOptionsSnapshot <CredHubServiceOption> credHubServiceOption,
                       IOptions <CloudFoundryServicesOptions> servicesOptions,
                       IConfiguration config)
 {
     _logger = logger;
     _credHubServiceOption1 = credHubServiceOption.Get("showme-creds");
     _credHubServiceOption2 = credHubServiceOption.Get("showme-creds2");
     CloudFoundryServices   = servicesOptions.Value;
     _config = config;
 }
Ejemplo n.º 13
0
        public void Constructor_WithNoVcapServicesConfiguration()
        {
            var builder = new ConfigurationBuilder();
            var config  = builder.Build();

            var options = new CloudFoundryServicesOptions(config);

            Assert.NotNull(options);
            Assert.NotNull(options.Services);
            Assert.Empty(options.Services);
            Assert.Empty(options.GetServicesList());
        }
 public LoanApplicationController(IOptions <CloudFoundryApplicationOptions> appOptions,
                                  IOptions <CloudFoundryServicesOptions> serviceOptions,
                                  ILogger <LoanApplicationController> logger,
                                  Models.ILoanApplicationRepository loans,
                                  Services.ILoanCheckerService loanCheckerService,
                                  IHostingEnvironment env)
 {
     _appOptions         = appOptions.Value;
     _serviceOptions     = serviceOptions.Value;
     _logger             = logger;
     _loans              = loans;
     _loanCheckerservice = loanCheckerService;
     _env = env;
 }
        public void Constructor_WithNoVcapServicesConfiguration()
        {
            // Arrange
            var builder = new ConfigurationBuilder();
            var config  = builder.Build();

            var options     = new CloudFoundryServicesOptions();
            var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);

            servSection.Bind(options);

            Assert.NotNull(options);
            Assert.NotNull(options.Services);
            Assert.Empty(options.Services);
            Assert.Empty(options.ServicesList);
        }
        public ValuesController()
        {
            _appOptions     = ApplicationConfig.CloudFoundryApplication;
            _serviceOptions = ApplicationConfig.CloudFoundryServices;
            _logger         = LoggingConfig.LoggerFactory.CreateLogger <ValuesController>();

            _logger.LogInformation("Hi there, this is a {LogLevel} log", LogLevel.Information.ToString());

            /*
             * _logger.LogTrace("This is a {LogLevel} log", LogLevel.Trace.ToString());
             * _logger.LogDebug("This is a {LogLevel} log", LogLevel.Debug.ToString());
             * _logger.LogInformation("This is a {LogLevel} log", LogLevel.Information.ToString());
             * _logger.LogWarning("This is a {LogLevel} log", LogLevel.Warning.ToString());
             * _logger.LogError("This is a {LogLevel} log", LogLevel.Error.ToString());
             * _logger.LogCritical("This is a {LogLevel} log", LogLevel.Critical.ToString());
             */
        }
Ejemplo n.º 17
0
        public ValuesController(IOptions <CloudFoundryApplicationOptions> appOptions,
                                IOptions <CloudFoundryServicesOptions> serviceOptions,
                                ILogger <ValuesController> logger)
        {
            _appOptions     = appOptions.Value;
            _serviceOptions = serviceOptions.Value;
            _logger         = logger;

            _logger.LogInformation("Hi There");

            /*
             * _logger.LogCritical("Test Critical message");
             * _logger.LogError("Test Error message");
             * _logger.LogWarning("Test Warning message");
             * _logger.LogInformation("Test Informational message");
             * _logger.LogDebug("Test Debug message");
             * _logger.LogTrace("Test Trace message");
             */
        }
        public MailController_Test()
        {
            IConfiguration configuration = CreateConfiguration();
            CloudFoundryServicesOptions cfServiceOptions = new CloudFoundryServicesOptions(configuration);

            cfOptions = Options.Create <CloudFoundryServicesOptions>(cfServiceOptions);
            SMTPServiceConfiguration smtpConfig = new SMTPServiceConfiguration
            {
                ServiceBindingName = "smtp-service"
            };

            smptOptions   = Options.Create <SMTPServiceConfiguration>(smtpConfig);
            loggerFactory = new LoggerFactory();
            mockSMPTPLib  = new Mock <ISmtpLibrary>();
            mockSMPTPLib.Setup(method => method.Send(It.IsAny <MailModel>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                                     It.IsAny <int>()));
            mockSMPTPLib.Setup(method => method.SendAsync(It.IsAny <MailModel>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(),
                                                          It.IsAny <int>())).Returns(Task.FromResult(0)).Verifiable();
        }
Ejemplo n.º 19
0
        private static bool IsConfigServerBound()
        {
            var configuration = new ConfigurationBuilder()
                                .AddCloudFoundry()
                                .Build();

            var cfServicesOptions = new CloudFoundryServicesOptions(configuration);

            foreach (var service in cfServicesOptions.ServicesList)
            {
                if (service.Label == "p-config-server" ||
                    service.Label == "p.config-server" ||
                    (service.Tags != null && (service.Tags.Contains("spring-cloud") && service.Tags.Contains("configuration"))))
                {
                    return(true);
                }
            }

            return(false);
        }
        private void BuildServiceInfos()
        {
            ServiceInfos.Clear();

            var appInfo     = new CloudFoundryApplicationOptions(_config);
            var serviceOpts = new CloudFoundryServicesOptions(_config);

            foreach (var serviceopt in serviceOpts.Services)
            {
                foreach (var s in serviceopt.Value)
                {
                    var factory = FindFactory(s);
                    if (factory != null && factory.Create(s) is ServiceInfo info)
                    {
                        info.ApplicationInfo = appInfo;
                        ServiceInfos.Add(info);
                    }
                }
            }
        }
Ejemplo n.º 21
0
        public CloudFoundryForwarderOptions(IConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var section = config.GetSection(CONFIG_PREFIX);

            if (section != null)
            {
                section.Bind(this);
            }

            section = config.GetSection(CloudFoundryApplicationOptions.CONFIGURATION_PREFIX);
            if (section != null)
            {
                CloudFoundryApplicationOptions appOptions = new CloudFoundryApplicationOptions(section);
                if (string.IsNullOrEmpty(ApplicationId))
                {
                    ApplicationId = appOptions.ApplicationId;
                }

                if (string.IsNullOrEmpty(InstanceId))
                {
                    InstanceId = appOptions.InstanceId;
                }

                if (string.IsNullOrEmpty(InstanceIndex))
                {
                    InstanceIndex = appOptions.InstanceIndex.ToString();
                }
            }

            section = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);
            if (section != null)
            {
                CloudFoundryServicesOptions servOptions = new CloudFoundryServicesOptions(section);
                if (servOptions.Services.TryGetValue(FORWARDER_NAME, out Service[] services))
Ejemplo n.º 22
0
        public ActionResult Index()
        {
            CloudFoundryApplicationOptions applicationOptions = ProviderConfig.ApplicationOptions;
            CloudFoundryServicesOptions    servicesOptions    = ProviderConfig.ServicesOptions;

            ViewData["ApplicationName"] = applicationOptions.ApplicationName;
            ViewData["ApplicationUris"] = applicationOptions.ApplicationUris == null ? "" : String.Join(", ", applicationOptions.ApplicationUris);
            ViewData["InstanceIndex"]   = applicationOptions.InstanceIndex;
            ViewData["InstanceId"]      = applicationOptions.InstanceId;

            string serviceList = "";

            foreach (var service in servicesOptions.Services)
            {
                if (serviceList.Length > 0)
                {
                    serviceList += ", ";
                }
                serviceList += service.Name;
            }
            ViewData["BoundServices"] = serviceList;

            return(View());
        }
        private static Service CreateRabbitMQService()
        {
            var environment = @"
                {
                    ""p-rabbitmq"": [{
                        ""credentials"": {
                            ""http_api_uris"": [""https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/""],
                            ""ssl"": false,
                            ""dashboard_url"": ""https://pivotal-rabbitmq.system.testcloud.com/#/login/03c7a684-6ff1-4bd0-ad45-d10374ffb2af/l5oq2q0unl35s6urfsuib0jvpo"",
                            ""password"": ""l5oq2q0unl35s6urfsuib0jvpo"",
                            ""protocols"": {
                                ""management"": {
                                    ""path"": ""/api/"",
                                    ""ssl"": false,
                                    ""hosts"": [""192.168.0.81""],
                                    ""password"": ""l5oq2q0unl35s6urfsuib0jvpo"",
                                    ""username"": ""03c7a684-6ff1-4bd0-ad45-d10374ffb2af"",
                                    ""port"": 15672,
                                    ""host"": ""192.168.0.81"",
                                    ""uri"": ""https://*****:*****@192.168.0.81:15672/api/"",
                                    ""uris"": [""https://*****:*****@192.168.0.81:15672/api/""]
                                },
                                ""amqp"": {
                                    ""vhost"": ""fb03d693-91fe-4dc5-8203-ff7a6390df66"",
                                    ""username"": ""03c7a684-6ff1-4bd0-ad45-d10374ffb2af"",
                                    ""password"": ""l5oq2q0unl35s6urfsuib0jvpo"",
                                    ""port"": 5672,
                                    ""host"": ""192.168.0.81"",
                                    ""hosts"": [""192.168.0.81""],
                                    ""ssl"": false,
                                    ""uri"": ""amqp://*****:*****@192.168.0.81:5672/fb03d693-91fe-4dc5-8203-ff7a6390df66"",
                                    ""uris"": [""amqp://*****:*****@192.168.0.81:5672/fb03d693-91fe-4dc5-8203-ff7a6390df66""]
                                }
                            },
                            ""username"": ""03c7a684-6ff1-4bd0-ad45-d10374ffb2af"",
                            ""hostname"": ""192.168.0.81"",
                            ""hostnames"": [""192.168.0.81""],
                            ""vhost"": ""fb03d693-91fe-4dc5-8203-ff7a6390df66"",
                            ""http_api_uri"": ""https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/"",
                            ""uri"": ""amqp://*****:*****@192.168.0.81/fb03d693-91fe-4dc5-8203-ff7a6390df66"",
                            ""uris"": [""amqp://*****:*****@192.168.0.81/fb03d693-91fe-4dc5-8203-ff7a6390df66""]
                        },
                        ""syslog_drain_url"": null,
                        ""label"": ""p-rabbitmq"",
                        ""provider"": null,
                        ""plan"": ""standard"",
                        ""name"": ""spring-cloud-broker-rmq"",
                        ""tags"": [
                            ""rabbitmq"",
                            ""messaging"",
                            ""message-queue"",
                            ""amqp"",
                            ""stomp"",
                            ""mqtt"",
                            ""pivotal""
                        ]
                    }]
                }";

            Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);

            var builder = new ConfigurationBuilder();

            builder.AddCloudFoundry();
            var config  = builder.Build();
            var opt     = new CloudFoundryServicesOptions(config);
            var section = config.GetSection(CloudFoundryServicesOptions.ServicesConfigRoot);

            section.Bind(opt);
            Assert.Single(opt.Services);

            return(opt.Services.First().Value.First());
        }
 public CloudFoundryViewModel(CloudFoundryApplicationOptions appOptions, CloudFoundryServicesOptions servOptions)
 {
     CloudFoundryServices = servOptions;
     CloudFoundryApplication = appOptions;
 }
Ejemplo n.º 25
0
 public CloudFoundryViewModel(CloudFoundryApplicationOptions appOptions, CloudFoundryServicesOptions servOptions)
 {
     CloudFoundryServices    = servOptions;
     CloudFoundryApplication = appOptions;
 }
Ejemplo n.º 26
0
        public ActionResult <String> GetServices()
        {
            CloudFoundryServicesOptions services = CloudFoundryServices == null ? new CloudFoundryServicesOptions() : CloudFoundryServices;

            return("the value of workshop_secret is: " + services.Services["credhub"][0].Credentials["workshop_secret"].Value);
        }
        private static Service CreateHystrixService()
        {
            var environment = @"
{
 'p-circuit-breaker-dashboard': [
    {
        'credentials': {
            'stream': 'https://turbine-5ac7e504-3ca5-4f02-9302-d5554c059043.apps.testcloud.com',
        'amqp': {
            'http_api_uris': [
                'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/'
            ],
        'ssl': false,
        'dashboard_url': 'https://pivotal-rabbitmq.system.testcloud.com/#/login/a0f39f25-28a2-438e-a0e7-6c09d6d34dbd/1clgf5ipeop36437dmr2em4duk',
        'password': '******',
        'protocols': {
            'amqp': {
                'vhost': '06f0b204-9f95-4829-a662-844d3c3d6120',
                'username': '******',
                'password': '******',
                'port': 5672,
                'host': '192.168.1.55',
                'hosts': [
                '192.168.1.55'
                ],
                'ssl': false,
                'uri': 'amqp://*****:*****@192.168.1.55:5672/06f0b204-9f95-4829-a662-844d3c3d6120',
                'uris': [
                'amqp://*****:*****@192.168.1.55:5672/06f0b204-9f95-4829-a662-844d3c3d6120'
                ]
            },
        'management': {
            'path': '/api/',
            'ssl': false,
            'hosts': [
            '192.168.1.55'
            ],
            'password': '******',
            'username': '******',
            'port': 15672,
            'host': '192.168.1.55',
            'uri': 'https://*****:*****@192.168.1.55:15672/api/',
            'uris': [
            'https://*****:*****@192.168.1.55:15672/api/'
            ]
            }
            },
        'username': '******',
        'hostname': '192.168.1.55',
        'hostnames': [
                '192.168.1.55'
            ],
              'vhost': '06f0b204-9f95-4829-a662-844d3c3d6120',
              'http_api_uri': 'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/',
              'uri': 'amqp://*****:*****@192.168.1.55/06f0b204-9f95-4829-a662-844d3c3d6120',
              'uris': [
                'amqp://*****:*****@192.168.1.55/06f0b204-9f95-4829-a662-844d3c3d6120'
              ]
            },
            'dashboard': 'https://hystrix-5ac7e504-3ca5-4f02-9302-d5554c059043.apps.testcloud.com'
          },
          'syslog_drain_url': null,
          'volume_mounts': [],
          'label': 'p-circuit-breaker-dashboard',
          'provider': null,
          'plan': 'standard',
          'name': 'myHystrixService',
          'tags': [
            'circuit-breaker',
            'hystrix-amqp',
            'spring-cloud'
          ]
        }
      ]
    }
  }";

            Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddCloudFoundry();
            var config  = builder.Build();
            var opt     = new CloudFoundryServicesOptions();
            var section = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);

            section.Bind(opt);
            Assert.Single(opt.Services);

            return(opt.Services.First().Value[0]);
        }
 /// <summary>
 /// Constructor for the Environment Controller
 /// </summary>
 /// <param name="applicationOptions">The CF application options</param>
 /// <param name="servicesOptions">The CF services options </param>
 public EnvironmentController(IOptions <CloudFoundryApplicationOptions> applicationOptions,
                              IOptions <CloudFoundryServicesOptions> servicesOptions)
 {
     ApplicationOptions = applicationOptions.Value;
     ServicesOptions    = servicesOptions.Value;
 }
Ejemplo n.º 29
0
        public static Service CreateRabbitService()
        {
            var environment = @"
{
      'p-rabbitmq': [
        {
          'credentials': {
            'http_api_uris': [
              'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/'
            ],
            'ssl': false,
            'dashboard_url': 'https://pivotal-rabbitmq.system.testcloud.com/#/login/03c7a684-6ff1-4bd0-ad45-d10374ffb2af/l5oq2q0unl35s6urfsuib0jvpo',
            'password': '******',
            'protocols': {
              'management': {
                'path': '/api/',
                'ssl': false,
                'hosts': [
                  '192.168.0.81'
                ],
                'password': '******',
                'username': '******',
                'port': 15672,
                'host': '192.168.0.81',
                'uri': 'http://*****:*****@192.168.0.81:15672/api/',
                'uris': [
                  'http://*****:*****@192.168.0.81:15672/api/'
                ]
              },
              'amqp': {
                'vhost': 'fb03d693-91fe-4dc5-8203-ff7a6390df66',
                'username': '******',
                'password': '******',
                'port': 5672,
                'host': '192.168.0.81',
                'hosts': [
                  '192.168.0.81'
                ],
                'ssl': false,
                'uri': 'amqp://*****:*****@192.168.0.81:5672/fb03d693-91fe-4dc5-8203-ff7a6390df66',
                'uris': [
                  'amqp://*****:*****@192.168.0.81:5672/fb03d693-91fe-4dc5-8203-ff7a6390df66'
                ]
              }
            },
            'username': '******',
            'hostname': '192.168.0.81',
            'hostnames': [
              '192.168.0.81'
            ],
            'vhost': 'fb03d693-91fe-4dc5-8203-ff7a6390df66',
            'http_api_uri': 'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/',
            'uri': 'amqp://*****:*****@192.168.0.81/fb03d693-91fe-4dc5-8203-ff7a6390df66',
            'uris': [
              'amqp://*****:*****@192.168.0.81/fb03d693-91fe-4dc5-8203-ff7a6390df66'
            ]
          },
          'syslog_drain_url': null,
          'label': 'p-rabbitmq',
          'provider': null,
          'plan': 'standard',
          'name': 'spring-cloud-broker-rmq',
          'tags': [
            'rabbitmq',
            'messaging',
            'message-queue',
            'amqp',
            'stomp',
            'mqtt',
            'pivotal'
          ]
        }
      ]
    }
  }";

            Environment.SetEnvironmentVariable("VCAP_SERVICES", environment);

            ConfigurationBuilder builder = new ConfigurationBuilder();

            builder.AddCloudFoundry();
            var config = builder.Build();
            var opt    = new CloudFoundryServicesOptions();

            config.Bind(opt);
            Assert.Equal(1, opt.Services.Count);

            return(opt.Services[0]);
        }
        public void Constructor_WithComplexSingleServiceConfiguration()
        {
            // Arrange
            var configJson = @"
{ 'vcap': {
    'services' : {
            'p-rabbitmq': [
            {
            'name': 'rabbitmq',
            'label': 'p-rabbitmq',
            'tags': [
                'rabbitmq',
                'messaging',
                'message-queue',
                'amqp',
                'stomp',
                'mqtt',
                'pivotal'
                ],
            'plan': 'standard',
            'credentials': {
                'http_api_uris': [
                    'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/'
                ],
                'ssl': false,
                'dashboard_url': 'https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4',
                'password': '******',
                'protocols': {
                    'management': {
                        'path': '/api/',
                        'ssl': false,
                        'hosts': [
                            '192.168.0.97'
                            ],
                        'password': '******',
                        'username': '******',
                        'port': 15672,
                        'host': '192.168.0.97',
                        'uri': 'http://*****:*****@192.168.0.97:15672/api/',
                        'uris': [
                            'http://*****:*****@192.168.0.97:15672/api/'
                            ]
                    },
                    'amqp': {
                        'vhost': '2260a117-cf28-4725-86dd-37b3b8971052',
                        'username': '******',
                        'password': '******',
                        'port': 5672,
                        'host': '192.168.0.97',
                        'hosts': [
                            '192.168.0.97'
                            ],
                        'ssl': false,
                        'uri': 'amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052',
                        'uris': [
                            'amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052'
                            ]
                    }
                },
                'username': '******',
                'hostname': '192.168.0.97',
                'hostnames': [
                    '192.168.0.97'
                    ],
                'vhost': '2260a117-cf28-4725-86dd-37b3b8971052',
                'http_api_uri': 'https://*****:*****@pivotal-rabbitmq.system.testcloud.com/api/',
                'uri': 'amqp://*****:*****@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052',
                'uris': [
                    'amqp://*****:*****@192.168.0.97/2260a117-cf28-4725-86dd-37b3b8971052'
                    ]
            }
            }
            ]
        }
    }
}";
            var memStream  = CloudFoundryConfigurationProvider.GetMemoryStream(configJson);
            var jsonSource = new JsonStreamConfigurationSource(memStream);
            var builder    = new ConfigurationBuilder().Add(jsonSource);
            var config     = builder.Build();

            var options     = new CloudFoundryServicesOptions();
            var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);

            servSection.Bind(options);

            Assert.NotNull(options.Services);
            Assert.Single(options.Services);
            Assert.Equal("p-rabbitmq", options.ServicesList[0].Label);
            Assert.Equal("rabbitmq", options.ServicesList[0].Name);
            Assert.Equal("standard", options.ServicesList[0].Plan);

            Assert.NotNull(options.ServicesList[0].Tags);
            Assert.Equal(7, options.ServicesList[0].Tags.Length);
            Assert.Equal("rabbitmq", options.ServicesList[0].Tags[0]);
            Assert.Equal("pivotal", options.ServicesList[0].Tags[6]);

            Assert.NotNull(options.ServicesList[0].Credentials);
            Assert.Equal(12, options.ServicesList[0].Credentials.Count);
            Assert.Equal("https://pivotal-rabbitmq.system.testcloud.com/#/login/268371bd-07e5-46f3-aec7-d1633ae20bbb/3fnpvbqm0djq5jl9fp6fc697f4", options.ServicesList[0].Credentials["dashboard_url"].Value);
            Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", options.ServicesList[0].Credentials["username"].Value);
            Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", options.ServicesList[0].Credentials["password"].Value);
            Assert.Equal("268371bd-07e5-46f3-aec7-d1633ae20bbb", options.ServicesList[0].Credentials["protocols"]["amqp"]["username"].Value);
            Assert.Equal("3fnpvbqm0djq5jl9fp6fc697f4", options.ServicesList[0].Credentials["protocols"]["amqp"]["password"].Value);
            Assert.Equal(
                "amqp://*****:*****@192.168.0.97:5672/2260a117-cf28-4725-86dd-37b3b8971052",
                options.ServicesList[0].Credentials["protocols"]["amqp"]["uris"]["0"].Value);
        }
        public void Constructor_WithMultipleSameServicesConfiguration()
        {
            // Arrange
            var configJson = @"
{ 'vcap': {
    'services' : {
            'p-mysql': [
            {
                'name': 'mySql1',
                'label': 'p-mysql',
                'tags': [
                'mysql',
                'relational'
                ],
                'plan': '100mb-dev',
                'credentials': {
                    'hostname': '192.168.0.97',
                    'port': 3306,
                    'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31',
                    'username': '******',
                    'password': '******',
                    'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true',
                    'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst'
                }
            },
            {
                'name': 'mySql2',
                'label': 'p-mysql',
                'tags': [
                'mysql',
                'relational'
                ],
                'plan': '100mb-dev',
                'credentials': {
                    'hostname': '192.168.0.97',
                    'port': 3306,
                    'name': 'cf_0f5dda44_e678_4727_993f_30e6d455cc31',
                    'username': '******',
                    'password': '******',
                    'uri': 'mysql://*****:*****@192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?reconnect=true',
                    'jdbcUrl': 'jdbc:mysql://192.168.0.97:3306/cf_0f5dda44_e678_4727_993f_30e6d455cc31?user=9vD0Mtk3wFFuaaaY&password=Cjn4HsAiKV8sImst'
                }
            }
            ]
        }
    }
}";
            var memStream  = CloudFoundryConfigurationProvider.GetMemoryStream(configJson);
            var jsonSource = new JsonStreamConfigurationSource(memStream);
            var builder    = new ConfigurationBuilder().Add(jsonSource);
            var config     = builder.Build();

            var options     = new CloudFoundryServicesOptions();
            var servSection = config.GetSection(CloudFoundryServicesOptions.CONFIGURATION_PREFIX);

            servSection.Bind(options);

            Assert.NotNull(options.Services);
            Assert.Single(options.Services);
            Assert.NotNull(options.Services["p-mysql"]);

            Assert.Equal(2, options.ServicesList.Count);

            Assert.Equal("p-mysql", options.ServicesList[0].Label);
            Assert.Equal("p-mysql", options.ServicesList[1].Label);

            Assert.True(options.ServicesList[0].Name.Equals("mySql1") || options.ServicesList[0].Name.Equals("mySql2"));
            Assert.True(options.ServicesList[1].Name.Equals("mySql1") || options.ServicesList[1].Name.Equals("mySql2"));

            Assert.Equal("192.168.0.97", options.ServicesList[0].Credentials["hostname"].Value);
            Assert.Equal("192.168.0.97", options.ServicesList[1].Credentials["hostname"].Value);
            Assert.Equal("3306", options.ServicesList[0].Credentials["port"].Value);
            Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", options.ServicesList[0].Credentials["name"].Value);
            Assert.Equal("cf_0f5dda44_e678_4727_993f_30e6d455cc31", options.ServicesList[1].Credentials["name"].Value);
        }