コード例 #1
0
 public static IServiceCollection AddCloudFoundry(this IServiceCollection serviceCollection,
     IConfigurationRoot configuration)
 {
     string vcapRaw = configuration.GetSection("VCAP_SERVICES").Value;
     Dictionary<String, BoundService> results = new Dictionary<string, BoundService>();
     VcapParser parser = new VcapParser();
     
     if (!string.IsNullOrEmpty(vcapRaw))
     {
         try
         {
             results = parser.ParseConfigurationForVcap(vcapRaw);
         }
         catch (Exception ex)
         {
             throw new ArgumentException("VCAP_SERVICES", "Could not parse VCAP_SERVICES environment variable or other substitute configuration. Cannot enable cloud foundry configuration.", ex);
         }
     }
    
     serviceCollection.Configure<CloudFoundryBoundServiceOptions>(options =>
     {
         options.BoundServices = results;
     });
     
     return serviceCollection;
 }
コード例 #2
0
ファイル: VcapParserTest.cs プロジェクト: chrisumbel/core
        public void TestMarketplaceServiceParsing()
        {
            var json = @"
                {'elephantsql': 
                    [
                        {
                            'name' : 'elephantsql-c6c0',
                            'label' : 'elephantsql',
                            'tags' : [ 'postgres', 'postgresql', 'relational' ],
                            'plan' : 'turtle',
                            'credentials' : {
                                'uri' : 'http://foo.bar/baz'
                            }
                        },
                        {
                            'name' : 'elephantsql-two',
                            'label' : 'elephantsql',
                            'tags' : ['postgres', 'postgresql', 'relational'],
                            'plan' : 'not-so-turtle',
                            'credentials' : {
                                'uri' : 'http://bar.baz/foo'
                            }
                        }
                    ],
                 'sendgrid' :
                    [
                        {
                            'name' : 'mysendgrid',
                            'label' : 'sendgrid',
                            'tags' : ['smtp'],
                            'plan' : 'free',
                            'credentials' : {
                                'hostname' : 'smtp.sendgrid.net',
                                'username' : 'foo',
                                'password' : 'bar'
                            }
                        }
                    ]
                }";

            VcapParser parser = new VcapParser();
            var results = parser.ParseConfigurationForVcap(json);
            Assert.NotNull(results);
            Assert.Equal(3, results.Count);
            Assert.True(results.ContainsKey("elephantsql-c6c0"));
            var elephantSql = results["elephantsql-c6c0"];

            Assert.Equal("turtle", elephantSql.Plan);
            Assert.Equal("elephantsql", elephantSql.Label);
            Assert.Equal(false, elephantSql.UserProvided);
            Assert.Equal(3, elephantSql.Tags.Count);

            Assert.Equal("http://foo.bar/baz", (string)elephantSql.Credentials["uri"]);
            Assert.Equal("smtp.sendgrid.net", results["mysendgrid"].Credentials["hostname"]);           
        }
コード例 #3
0
ファイル: VcapParserTest.cs プロジェクト: chrisumbel/core
 public void TestParserHandlesUserProvidedServices()
 {
     var vcapRaw = @"
     {      
         'user-provided' :
          [
             {
                 'name' : 'my-ups',
                 'label' : 'user-provided',
                 'tags' : [],                  
                 'credentials' : {
                     'hostname' : 'host.name',
                     'username' : 'foo',
                     'password' : 'bar',
                     'uri' : 'http://this/is/a/uri'
                 }
             } 
          ]
      }";
     VcapParser parser = new VcapParser();
     var results = parser.ParseConfigurationForVcap(vcapRaw);
     Assert.NotNull(results);
     Assert.True(results.ContainsKey("my-ups"));
     Assert.Equal(1, results.Count);
     var myUps = results["my-ups"];
     Assert.True(myUps.UserProvided);
     Assert.Equal(String.Empty, myUps.Plan);
     Assert.Equal("user-provided", myUps.Label);
     Assert.Equal("http://this/is/a/uri", (string)myUps.Credentials["uri"]);
 }
コード例 #4
0
ファイル: VcapParserTest.cs プロジェクト: chrisumbel/core
 public void TestVcapParserThrowsExceptionWithNullOrEmptyJson()
 {
     var missingJson = String.Empty;
     VcapParser parser = new VcapParser();
     Boolean caught = false;
     try
     {
         var results = parser.ParseConfigurationForVcap(missingJson);
     }
     catch (Exception ex)
     {
         caught = true;
     }
     Assert.True(caught);
 }
コード例 #5
0
ファイル: VcapParserTest.cs プロジェクト: chrisumbel/core
 public void TestVcapParserThrowsExceptionWithBadJson()
 {
     var badJson = @"{ 'this' : won't parse }";
     VcapParser parser = new VcapParser();
     Boolean caught = false;
     try {
         var results = parser.ParseConfigurationForVcap(badJson);
     } catch (Exception ex) {
         caught = true;
     }
     Assert.True(caught);            
 }