ConfigServer, Placeholder, RandomValue
This commit is contained in:
Родитель
117ac15edc
Коммит
726a553fa9
|
@ -39,12 +39,12 @@ stages:
|
|||
command: 'test'
|
||||
arguments: '--filter Category!=Integration'
|
||||
testRunTitle: 'Unit Tests'
|
||||
# - task: DotNetCoreCLI@2
|
||||
# displayName: Dotnet test (Integration Tests)
|
||||
# inputs:
|
||||
# command: 'test'
|
||||
# arguments: '--filter Category=Integration'
|
||||
# testRunTitle: 'Unit Tests'
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: Dotnet test (Integration Tests)
|
||||
inputs:
|
||||
command: 'test'
|
||||
arguments: '--filter Category=Integration'
|
||||
testRunTitle: 'Unit Tests'
|
||||
- task: DotNetCoreCLI@2
|
||||
displayName: Dotnet publish
|
||||
inputs:
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2017 the original author or authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Steeltoe.Initializr.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Steeltoe.Initializr.Services.Mustache
|
||||
{
|
||||
public class MoreThanOneExpression : IExpression
|
||||
{
|
||||
private readonly CalculatedParam _param;
|
||||
private readonly EvaluationExpression _evaluationExpression;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public MoreThanOneExpression(ILogger logger, CalculatedParam param, MustacheConfigSchema schema)
|
||||
{
|
||||
_param = param;
|
||||
_logger = logger;
|
||||
_evaluationExpression = BuildEvaluationExpression(schema);
|
||||
}
|
||||
|
||||
public EvaluationExpression BuildEvaluationExpression(MustacheConfigSchema schema)
|
||||
{
|
||||
// TODO: Add validation
|
||||
using (Timing.Over(_logger, "Build MoreThanOne Expression"))
|
||||
{
|
||||
var keys = _param.Expression.Split(',');
|
||||
return dataView =>
|
||||
{
|
||||
var moreThanOne = dataView.Count(kvp =>
|
||||
keys.Contains(kvp.Key)
|
||||
&& bool.TryParse(kvp.Value.ToString(), out var boolValue)
|
||||
&& boolValue) > 1;
|
||||
return moreThanOne.ToString();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> EvaluateExpressionAsync(Dictionary<string, string> dataView)
|
||||
{
|
||||
using (Timing.Over(_logger, "Build MoreThanOne Expression"))
|
||||
{
|
||||
return await Task.Run(() => _evaluationExpression(dataView));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,6 +50,7 @@ namespace Steeltoe.Initializr.Services.Mustache
|
|||
Case, // Given string a:x, b:y, c:z Case when key is a, then x ...
|
||||
Bool, // Boolean expression over the keys (converted to lambda)
|
||||
String, // String lambda expression over keys
|
||||
MoreThanOne, // More than one boolean is true
|
||||
}
|
||||
|
||||
public class Version
|
||||
|
|
|
@ -218,6 +218,24 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add MySQL EF6 connnectors"
|
||||
},
|
||||
"ConfigServer": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add ConfigServer Configuration Source"
|
||||
},
|
||||
"PlaceholderConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add Placeholder Configuration Source"
|
||||
},
|
||||
"RandomValueConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add RandomValue Configuration Source"
|
||||
},
|
||||
"AnyConnector": {
|
||||
"type": "computed",
|
||||
"value": "(MySql || Postgres || MySql || Redis || RabbitMQ || MongoDB || OAuthConnector)"
|
||||
|
@ -228,6 +246,10 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Supress Models generation"
|
||||
},
|
||||
"AnyConfigSource": {
|
||||
"type": "computed",
|
||||
"value": "(ConfigServer || PlaceholderConfig || RandomValueConfig)"
|
||||
},
|
||||
"ValuesControllerWithArgs": {
|
||||
"type": "computed",
|
||||
"value": "(SQLServer || MySql || Postgres || MongoDB || RabbitMQ || Redis)"
|
||||
|
|
|
@ -7,21 +7,23 @@ using Microsoft.Extensions.Logging;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
#endif
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
#if(SQLServer || MySql || Postgres || MongoDB)
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (SQLServer)
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MySql)
|
||||
using System.Data.MySqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Postgres)
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
using MongoDB.Driver;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
|
@ -32,6 +34,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
#endif
|
||||
#if (AnyConfigSource)
|
||||
using Microsoft.Extensions.Configuration;
|
||||
#endif
|
||||
namespace Company.WebApplication1.Controllers
|
||||
{
|
||||
#if (!NoAuth)
|
||||
|
@ -65,9 +70,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if (MySql)
|
||||
#elif (MySql)
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
{
|
||||
|
@ -90,8 +93,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (Postgres)
|
||||
#elif (Postgres)
|
||||
private readonly NpgsqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] NpgsqlConnection dbConnection)
|
||||
{
|
||||
|
@ -114,8 +116,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
#elif (MongoDB)
|
||||
private readonly IMongoClient _mongoClient;
|
||||
private readonly MongoUrl _mongoUrl;
|
||||
public ValuesController(IMongoClient mongoClient, MongoUrl mongoUrl)
|
||||
|
@ -130,8 +131,7 @@ namespace Company.WebApplication1.Controllers
|
|||
{
|
||||
return _mongoClient.ListDatabaseNames().ToList();
|
||||
}
|
||||
#endif
|
||||
#if (Redis)
|
||||
#elif (Redis)
|
||||
private readonly IDistributedCache _cache;
|
||||
public ValuesController(IDistributedCache cache)
|
||||
{
|
||||
|
@ -148,8 +148,7 @@ namespace Company.WebApplication1.Controllers
|
|||
string myval2 = await _cache.GetStringAsync("MyValue2");
|
||||
return new string[]{ myval1, myval2};
|
||||
}
|
||||
#endif
|
||||
#if (RabbitMQ)
|
||||
#elif (RabbitMQ)
|
||||
private readonly ILogger _logger;
|
||||
private readonly ConnectionFactory _factory;
|
||||
private const string queueName = "my-queue";
|
||||
|
@ -196,11 +195,55 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if (!ValuesControllerWithArgs)
|
||||
#elif (ConfigServer)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
|
||||
#elif (PlaceholderConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
|
||||
#elif (RandomValueConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
#else
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
|
@ -208,6 +251,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
// GET api/values/5
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult<string> Get(int id)
|
||||
|
|
|
@ -14,6 +14,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
#endif
|
||||
#if (ConfigServer)
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
#endif
|
||||
#if(PlaceholderConfig)
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
#endif
|
||||
#if(RandomValueConfig)
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
#endif
|
||||
namespace Company.WebApplication1
|
||||
{
|
||||
public class Program
|
||||
|
@ -35,6 +44,15 @@ namespace Company.WebApplication1
|
|||
#if (CloudFoundry)
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
#endif
|
||||
#if (ConfigServer)
|
||||
.AddConfigServer()
|
||||
#endif
|
||||
#if (PlaceholderConfig)
|
||||
.AddPlaceholderResolver()
|
||||
#endif
|
||||
#if (RandomValueConfig)
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
#endif
|
||||
.UseStartup<Startup>();
|
||||
#if (Actuators || DynamicLogger)
|
||||
|
|
|
@ -346,6 +346,24 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add MySQL EF6 connnectors"
|
||||
},
|
||||
"ConfigServer": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add ConfigServer Configuration Source"
|
||||
},
|
||||
"PlaceholderConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add Placeholder Configuration Source"
|
||||
},
|
||||
"RandomValueConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add RandomValue Configuration Source"
|
||||
},
|
||||
"AnyConnector": {
|
||||
"type": "computed",
|
||||
"value": "(MySql || Postgres || SQLServer || Redis || RabbitMQ || MongoDB || OAuthConnector)"
|
||||
|
@ -356,9 +374,9 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Supress Models generation"
|
||||
},
|
||||
"ValuesControllerWithArgs": {
|
||||
"AnyConfigSource": {
|
||||
"type": "computed",
|
||||
"value": "(SQLServer || MySql || Postgres || MongoDB || RabbitMQ || Redis)"
|
||||
"value": "(ConfigServer || PlaceholderConfig || RandomValueConfig)"
|
||||
},
|
||||
"CircuitBreaker": {
|
||||
"type": "parameter",
|
||||
|
|
|
@ -7,21 +7,20 @@ using Microsoft.Extensions.Logging;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
#endif
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
#if(SQLServer || MySql || Postgres || MongoDB)
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (SQLServer)
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MySql)
|
||||
using System.Data.MySqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Postgres)
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
using MongoDB.Driver;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
|
@ -32,6 +31,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
#endif
|
||||
#if (AnyConfigSource)
|
||||
using Microsoft.Extensions.Configuration;
|
||||
#endif
|
||||
namespace Company.WebApplication1.Controllers
|
||||
{
|
||||
#if (!NoAuth)
|
||||
|
@ -65,8 +67,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (MySql)
|
||||
#elif (MySql)
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
{
|
||||
|
@ -89,8 +90,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (Postgres)
|
||||
#elif (Postgres)
|
||||
private readonly NpgsqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] NpgsqlConnection dbConnection)
|
||||
{
|
||||
|
@ -113,8 +113,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
#elif (MongoDB)
|
||||
private readonly IMongoClient _mongoClient;
|
||||
private readonly MongoUrl _mongoUrl;
|
||||
public ValuesController(IMongoClient mongoClient, MongoUrl mongoUrl)
|
||||
|
@ -129,8 +128,7 @@ namespace Company.WebApplication1.Controllers
|
|||
{
|
||||
return _mongoClient.ListDatabaseNames().ToList();
|
||||
}
|
||||
#endif
|
||||
#if (Redis)
|
||||
#elif (Redis)
|
||||
private readonly IDistributedCache _cache;
|
||||
public ValuesController(IDistributedCache cache)
|
||||
{
|
||||
|
@ -147,8 +145,7 @@ namespace Company.WebApplication1.Controllers
|
|||
string myval2 = await _cache.GetStringAsync("MyValue2");
|
||||
return new string[]{ myval1, myval2};
|
||||
}
|
||||
#endif
|
||||
#if (RabbitMQ)
|
||||
#elif (RabbitMQ)
|
||||
private readonly ILogger _logger;
|
||||
private readonly ConnectionFactory _factory;
|
||||
private const string queueName = "my-queue";
|
||||
|
@ -195,12 +192,55 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#elif (ConfigServer)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
|
||||
#if (!ValuesControllerWithArgs)
|
||||
#elif (PlaceholderConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
|
||||
#elif (RandomValueConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
#else
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
|
|
|
@ -14,8 +14,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
#endif
|
||||
|
||||
|
||||
#if (ConfigServer)
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
#endif
|
||||
#if(PlaceholderConfig)
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
#endif
|
||||
#if(RandomValueConfig)
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
#endif
|
||||
namespace Company.WebApplication1
|
||||
{
|
||||
public class Program
|
||||
|
@ -37,6 +44,15 @@ namespace Company.WebApplication1
|
|||
#if (CloudFoundry)
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
#endif
|
||||
#if (ConfigServer)
|
||||
.AddConfigServer()
|
||||
#endif
|
||||
#if (PlaceholderConfig)
|
||||
.AddPlaceholderResolver()
|
||||
#endif
|
||||
#if (RandomValueConfig)
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
#endif
|
||||
.UseStartup<Startup>();
|
||||
#if (Actuators || DynamicLogger)
|
||||
|
|
|
@ -210,6 +210,24 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add MySQL EF6 connnectors"
|
||||
},
|
||||
"ConfigServer": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add ConfigServer Configuration Source"
|
||||
},
|
||||
"PlaceholderConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add Placeholder Configuration Source"
|
||||
},
|
||||
"RandomValueConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add RandomValue Configuration Source"
|
||||
},
|
||||
"AnyConnector": {
|
||||
"type": "computed",
|
||||
"value": "(MySql || Postgres || Redis || RabbitMQ || MongoDB || OAuthConnector)"
|
||||
|
@ -220,6 +238,10 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Supress Models generation"
|
||||
},
|
||||
"AnyConfigSource": {
|
||||
"type": "computed",
|
||||
"value": "(ConfigServer || PlaceholderConfig || RandomValueConfig)"
|
||||
},
|
||||
"ValuesControllerWithArgs": {
|
||||
"type": "computed",
|
||||
"value": "(SQLServer || MySql || Postgres || MongoDB || RabbitMQ || Redis)"
|
||||
|
|
|
@ -7,21 +7,23 @@ using Microsoft.Extensions.Logging;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
#endif
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
#if(SQLServer || MySql || Postgres || MongoDB)
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (SQLServer)
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MySql)
|
||||
using System.Data.MySqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Postgres)
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
using MongoDB.Driver;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
|
@ -32,6 +34,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
#endif
|
||||
#if (AnyConfigSource)
|
||||
using Microsoft.Extensions.Configuration;
|
||||
#endif
|
||||
namespace Company.WebApplication1.Controllers
|
||||
{
|
||||
#if (!NoAuth)
|
||||
|
@ -65,9 +70,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if (MySql)
|
||||
#elif (MySql)
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
{
|
||||
|
@ -90,8 +93,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (Postgres)
|
||||
#elif (Postgres)
|
||||
private readonly NpgsqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] NpgsqlConnection dbConnection)
|
||||
{
|
||||
|
@ -114,8 +116,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
#elif (MongoDB)
|
||||
private readonly IMongoClient _mongoClient;
|
||||
private readonly MongoUrl _mongoUrl;
|
||||
public ValuesController(IMongoClient mongoClient, MongoUrl mongoUrl)
|
||||
|
@ -130,8 +131,7 @@ namespace Company.WebApplication1.Controllers
|
|||
{
|
||||
return _mongoClient.ListDatabaseNames().ToList();
|
||||
}
|
||||
#endif
|
||||
#if (Redis)
|
||||
#elif (Redis)
|
||||
private readonly IDistributedCache _cache;
|
||||
public ValuesController(IDistributedCache cache)
|
||||
{
|
||||
|
@ -148,8 +148,7 @@ namespace Company.WebApplication1.Controllers
|
|||
string myval2 = await _cache.GetStringAsync("MyValue2");
|
||||
return new string[]{ myval1, myval2};
|
||||
}
|
||||
#endif
|
||||
#if (RabbitMQ)
|
||||
#elif (RabbitMQ)
|
||||
private readonly ILogger _logger;
|
||||
private readonly ConnectionFactory _factory;
|
||||
private const string queueName = "my-queue";
|
||||
|
@ -196,12 +195,56 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if (!ValuesControllerWithArgs)
|
||||
[HttpGet]
|
||||
#elif (ConfigServer)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
|
||||
#elif (PlaceholderConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
|
||||
#elif (RandomValueConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
#else
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
return "value";
|
||||
|
|
|
@ -14,6 +14,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
#endif
|
||||
#if (ConfigServer)
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
#endif
|
||||
#if(PlaceholderConfig)
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
#endif
|
||||
#if(RandomValueConfig)
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
#endif
|
||||
namespace Company.WebApplication1
|
||||
{
|
||||
public class Program
|
||||
|
@ -35,6 +44,15 @@ namespace Company.WebApplication1
|
|||
#if (CloudFoundry)
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
#endif
|
||||
#if (ConfigServer)
|
||||
.AddConfigServer()
|
||||
#endif
|
||||
#if (PlaceholderConfig)
|
||||
.AddPlaceholderResolver()
|
||||
#endif
|
||||
#if (RandomValueConfig)
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
#endif
|
||||
.UseStartup<Startup>();
|
||||
#if (Actuators || DynamicLogger)
|
||||
|
|
|
@ -330,6 +330,24 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add MySqlEF6 connnectors"
|
||||
},
|
||||
"ConfigServer": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add ConfigServer Configuration Source"
|
||||
},
|
||||
"PlaceholderConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add Placeholder Configuration Source"
|
||||
},
|
||||
"RandomValueConfig": {
|
||||
"type": "parameter",
|
||||
"datatype": "bool",
|
||||
"defaultValue": "false",
|
||||
"description": "Steeltoe: Add RandomValue Configuration Source"
|
||||
},
|
||||
"AnyConnector": {
|
||||
"type": "computed",
|
||||
"value": "(MySql || Postgres || SQLServer || Redis || RabbitMQ || MongoDB || OAuthConnector)"
|
||||
|
@ -340,6 +358,10 @@
|
|||
"defaultValue": "false",
|
||||
"description": "Supress Models generation"
|
||||
},
|
||||
"AnyConfigSource": {
|
||||
"type": "computed",
|
||||
"value": "(ConfigServer || PlaceholderConfig || RandomValueConfig)"
|
||||
},
|
||||
"ValuesControllerWithArgs": {
|
||||
"type": "computed",
|
||||
"value": "(SQLServer || MySql || Postgres || MongoDB || RabbitMQ || Redis)"
|
||||
|
|
|
@ -7,21 +7,23 @@ using Microsoft.Extensions.Logging;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
#endif
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
#if(SQLServer || MySql || Postgres || MongoDB)
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (SQLServer)
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MySql)
|
||||
using System.Data.MySqlClient;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Postgres)
|
||||
using Npgsql;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
using MongoDB.Driver;
|
||||
using System.Data;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
#endif
|
||||
#if (Redis)
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
|
@ -32,6 +34,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
#endif
|
||||
#if (AnyConfigSource)
|
||||
using Microsoft.Extensions.Configuration;
|
||||
#endif
|
||||
namespace Company.WebApplication1.Controllers
|
||||
{
|
||||
#if (!NoAuth)
|
||||
|
@ -65,9 +70,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if (MySql)
|
||||
#elif (MySql)
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
{
|
||||
|
@ -90,8 +93,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (Postgres)
|
||||
#elif (Postgres)
|
||||
private readonly NpgsqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] NpgsqlConnection dbConnection)
|
||||
{
|
||||
|
@ -114,8 +116,7 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return tables;
|
||||
}
|
||||
#endif
|
||||
#if (MongoDB)
|
||||
#elif (MongoDB)
|
||||
private readonly IMongoClient _mongoClient;
|
||||
private readonly MongoUrl _mongoUrl;
|
||||
public ValuesController(IMongoClient mongoClient, MongoUrl mongoUrl)
|
||||
|
@ -130,8 +131,7 @@ namespace Company.WebApplication1.Controllers
|
|||
{
|
||||
return _mongoClient.ListDatabaseNames().ToList();
|
||||
}
|
||||
#endif
|
||||
#if (Redis)
|
||||
#elif (Redis)
|
||||
private readonly IDistributedCache _cache;
|
||||
public ValuesController(IDistributedCache cache)
|
||||
{
|
||||
|
@ -148,8 +148,7 @@ namespace Company.WebApplication1.Controllers
|
|||
string myval2 = await _cache.GetStringAsync("MyValue2");
|
||||
return new string[]{ myval1, myval2};
|
||||
}
|
||||
#endif
|
||||
#if (RabbitMQ)
|
||||
#elif (RabbitMQ)
|
||||
private readonly ILogger _logger;
|
||||
private readonly ConnectionFactory _factory;
|
||||
private const string queueName = "my-queue";
|
||||
|
@ -196,11 +195,55 @@ namespace Company.WebApplication1.Controllers
|
|||
}
|
||||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if (!ValuesControllerWithArgs)
|
||||
#elif (ConfigServer)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
|
||||
#elif (PlaceholderConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
|
||||
#elif (RandomValueConfig)
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
#else
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
|
|
|
@ -15,7 +15,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
#endif
|
||||
|
||||
#if (ConfigServer)
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
#endif
|
||||
#if(PlaceholderConfig)
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
#endif
|
||||
#if(RandomValueConfig)
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
#endif
|
||||
|
||||
namespace Company.WebApplication1
|
||||
{
|
||||
|
@ -38,6 +46,15 @@ namespace Company.WebApplication1
|
|||
#if (CloudFoundry)
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
#endif
|
||||
#if (ConfigServer)
|
||||
.AddConfigServer()
|
||||
#endif
|
||||
#if (PlaceholderConfig)
|
||||
.AddPlaceholderResolver()
|
||||
#endif
|
||||
#if (RandomValueConfig)
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
#endif
|
||||
.UseStartup<Startup>();
|
||||
#if (Actuators || DynamicLogger)
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ConfigDataController : ControllerBase
|
||||
{
|
||||
private IOptionsSnapshot<ConfigServerData> IConfigServerData { get; set; }
|
||||
|
||||
private ConfigServerClientSettingsOptions ConfigServerClientSettingsOptions { get; set; }
|
||||
|
||||
private IConfigurationRoot Config { get; set; }
|
||||
|
||||
public ConfigDataController(IConfigurationRoot config, IOptionsSnapshot<ConfigServerData> configServerData, IOptions<ConfigServerClientSettingsOptions> confgServerSettings)
|
||||
{
|
||||
// The ASP.NET DI mechanism injects the data retrieved from the Spring Cloud Config Server
|
||||
// as an IOptionsSnapshot<ConfigServerData>. This happens because we added the call to:
|
||||
// "services.Configure<ConfigServerData>(Configuration);" in the StartUp class
|
||||
if (configServerData != null)
|
||||
IConfigServerData = configServerData;
|
||||
|
||||
// The settings used in communicating with the Spring Cloud Config Server
|
||||
if (confgServerSettings != null)
|
||||
ConfigServerClientSettingsOptions = confgServerSettings.Value;
|
||||
|
||||
Config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(CreateConfigServerData());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Reload()
|
||||
{
|
||||
if (Config != null)
|
||||
{
|
||||
Config.Reload();
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private IDictionary<string, string> CreateConfigServerData()
|
||||
{
|
||||
|
||||
var configData = new Dictionary<string, string>();
|
||||
|
||||
// IConfigServerData property is set to a IOptionsSnapshot<ConfigServerData> that has been
|
||||
// initialized with the configuration data returned from the Spring Cloud Config Server
|
||||
if (IConfigServerData != null && IConfigServerData.Value != null)
|
||||
{
|
||||
var data = IConfigServerData.Value;
|
||||
configData["Bar"] = data.Bar ?? "Not returned";
|
||||
configData["Foo"] = data.Foo ?? "Not returned";
|
||||
|
||||
configData["Info.Url"] = "Not returned";
|
||||
configData["Info.Description"] = "Not returned";
|
||||
|
||||
if (data.Info != null)
|
||||
{
|
||||
configData["Info.Url"] = data.Info.Url ?? "Not returned";
|
||||
configData["Info.Description"] = data.Info.Description ?? "Not returned";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
configData["Bar"] = "Not Available";
|
||||
configData["Foo"] = "Not Available";
|
||||
configData["Info.Url"] = "Not Available";
|
||||
configData["Info.Description"] = "Not Available";
|
||||
}
|
||||
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PlaceholderDataController : ControllerBase
|
||||
{
|
||||
IOptionsMonitor<SampleOptions> _opts;
|
||||
|
||||
private SampleOptions Options
|
||||
{
|
||||
get
|
||||
{
|
||||
return _opts.CurrentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public PlaceholderDataController(IOptionsMonitor<SampleOptions> opts)
|
||||
{
|
||||
_opts = opts;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(GetPlaceholderData());
|
||||
}
|
||||
|
||||
private IDictionary<string, string> GetPlaceholderData()
|
||||
{
|
||||
|
||||
var configData = new Dictionary<string, string>();
|
||||
configData["ResolvedPlaceholderFromEnvVariables"] = Options.ResolvedPlaceholderFromEnvVariables;
|
||||
configData["ResolvedPlaceholderFromJson"] = Options.ResolvedPlaceholderFromJson;
|
||||
configData["UnresolvedPlaceholder"] = Options.UnresolvedPlaceholder;
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class RandomValueDataController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public RandomValueDataController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(GetPlaceholderData());
|
||||
}
|
||||
|
||||
private IDictionary<string, string> GetPlaceholderData()
|
||||
{
|
||||
var configData = new Dictionary<string, string>();
|
||||
|
||||
configData["random:int"] = _config["random:int"];
|
||||
configData["random:long"] = _config["random:long"];
|
||||
configData["random:int(10)"] = _config["random:int(10)"];
|
||||
configData["random:long(100)"] = _config["random:long(100)"];
|
||||
configData["random:int(10,20)"] = _config["random:int(10,20)"];
|
||||
configData["random:long(100,200)"] = _config["random:long(100,200)"];
|
||||
configData["random:uuid"] = _config["random:uuid"];
|
||||
configData["random:string"] = _config["random:string"];
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
{{/RabbitMQ}}
|
||||
{{#AnyConfigSource}}
|
||||
using Microsoft.Extensions.Configuration;
|
||||
{{/AnyConfigSource}}
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
{{#Auth}}
|
||||
|
@ -40,7 +43,8 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
{
|
||||
{{^MoreThanOneValuesControllerWithArgs }}
|
||||
{{#SQLServer}}
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
|
@ -194,6 +198,63 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ}}
|
||||
{{#ConfigServer}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/RandomValueConfig}}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{#MoreThanOneValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{^ValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
|
|
|
@ -15,6 +15,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
{{/ RandomValueConfig}}
|
||||
namespace {{ProjectNameSpace}}
|
||||
{
|
||||
public class Program
|
||||
|
@ -33,10 +42,19 @@ namespace {{ProjectNameSpace}}
|
|||
{
|
||||
var builder = WebHost.CreateDefaultBuilder(args)
|
||||
.UseDefaultServiceProvider(configure => configure.ValidateScopes = false)
|
||||
{{#CloudFoundry}}
|
||||
{{#CloudFoundry}}
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
{{/CloudFoundry}}
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
.AddConfigServer()
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
.AddPlaceholderResolver()
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
{{/RandomValueConfig}}
|
||||
.UseStartup<Startup>();
|
||||
{{#ActuatorsOrDynamicLogger}}
|
||||
builder.ConfigureLogging((hostingContext, loggingBuilder) =>
|
||||
|
|
|
@ -82,6 +82,24 @@
|
|||
"Name": "ProjectNameSpace",
|
||||
"DefaultValue": "SteeltoeExample",
|
||||
"Description": "Change the namespace "
|
||||
},
|
||||
{
|
||||
"Name": "ConfigServer",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add ConfigServer Configuration Source",
|
||||
"friendlyName": "Config Server"
|
||||
},
|
||||
{
|
||||
"Name": "PlaceholderConfig",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add Placeholder Configuration Source",
|
||||
"friendlyName": "Placeholder Configuration Source"
|
||||
},
|
||||
{
|
||||
"Name": "RandomValueConfig",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add RandomValue Configuration Source",
|
||||
"friendlyName": "RandomValue Configuration Source"
|
||||
}
|
||||
],
|
||||
"CalculatedParams": [
|
||||
|
@ -105,11 +123,21 @@
|
|||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "MoreThanOneValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis",
|
||||
"ExpressionType": "MoreThanOne"
|
||||
},
|
||||
{
|
||||
"Name": "AnyConnector",
|
||||
"Expression": "MySql,Postgres,Redis,MongoDB,RabbitMQ,OAuthConnector",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "AnyConfigSource",
|
||||
"Expression": "ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "AspNetCoreVersion",
|
||||
"Expression": "TargetFrameworkVersion,netcoreapp2.2=2.2.0,netcoreapp2.1=2.1.1,default=False",
|
||||
|
@ -125,18 +153,6 @@
|
|||
{
|
||||
"Name": "AnyEFCore",
|
||||
"InclusionExpression": "Models/**"
|
||||
},
|
||||
{
|
||||
"Name": "ConfigServer",
|
||||
"InclusionExpression": "Models/ConfigServerData.cs;Controllers/ConfigDataController.cs"
|
||||
},
|
||||
{
|
||||
"Name": "PlaceholderConfig",
|
||||
"InclusionExpression": "SampleOptions.cs;Controllers/PlaceholderDataController.cs"
|
||||
},
|
||||
{
|
||||
"Name": "RandomValueConfig",
|
||||
"InclusionExpression": "Controllers/RandomValueDataController.cs"
|
||||
}
|
||||
],
|
||||
"Versions": [
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ConfigDataController : ControllerBase
|
||||
{
|
||||
private IOptionsSnapshot<ConfigServerData> IConfigServerData { get; set; }
|
||||
|
||||
private ConfigServerClientSettingsOptions ConfigServerClientSettingsOptions { get; set; }
|
||||
|
||||
private IConfigurationRoot Config { get; set; }
|
||||
|
||||
public ConfigDataController(IConfigurationRoot config, IOptionsSnapshot<ConfigServerData> configServerData, IOptions<ConfigServerClientSettingsOptions> confgServerSettings)
|
||||
{
|
||||
// The ASP.NET DI mechanism injects the data retrieved from the Spring Cloud Config Server
|
||||
// as an IOptionsSnapshot<ConfigServerData>. This happens because we added the call to:
|
||||
// "services.Configure<ConfigServerData>(Configuration);" in the StartUp class
|
||||
if (configServerData != null)
|
||||
IConfigServerData = configServerData;
|
||||
|
||||
// The settings used in communicating with the Spring Cloud Config Server
|
||||
if (confgServerSettings != null)
|
||||
ConfigServerClientSettingsOptions = confgServerSettings.Value;
|
||||
|
||||
Config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(CreateConfigServerData());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Reload()
|
||||
{
|
||||
if (Config != null)
|
||||
{
|
||||
Config.Reload();
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private IDictionary<string, string> CreateConfigServerData()
|
||||
{
|
||||
|
||||
var configData = new Dictionary<string, string>();
|
||||
|
||||
// IConfigServerData property is set to a IOptionsSnapshot<ConfigServerData> that has been
|
||||
// initialized with the configuration data returned from the Spring Cloud Config Server
|
||||
if (IConfigServerData != null && IConfigServerData.Value != null)
|
||||
{
|
||||
var data = IConfigServerData.Value;
|
||||
configData["Bar"] = data.Bar ?? "Not returned";
|
||||
configData["Foo"] = data.Foo ?? "Not returned";
|
||||
|
||||
configData["Info.Url"] = "Not returned";
|
||||
configData["Info.Description"] = "Not returned";
|
||||
|
||||
if (data.Info != null)
|
||||
{
|
||||
configData["Info.Url"] = data.Info.Url ?? "Not returned";
|
||||
configData["Info.Description"] = data.Info.Description ?? "Not returned";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
configData["Bar"] = "Not Available";
|
||||
configData["Foo"] = "Not Available";
|
||||
configData["Info.Url"] = "Not Available";
|
||||
configData["Info.Description"] = "Not Available";
|
||||
}
|
||||
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PlaceholderDataController : ControllerBase
|
||||
{
|
||||
IOptionsMonitor<SampleOptions> _opts;
|
||||
|
||||
private SampleOptions Options
|
||||
{
|
||||
get
|
||||
{
|
||||
return _opts.CurrentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public PlaceholderDataController(IOptionsMonitor<SampleOptions> opts)
|
||||
{
|
||||
_opts = opts;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(GetPlaceholderData());
|
||||
}
|
||||
|
||||
private IDictionary<string, string> GetPlaceholderData()
|
||||
{
|
||||
|
||||
var configData = new Dictionary<string, string>();
|
||||
configData["ResolvedPlaceholderFromEnvVariables"] = Options.ResolvedPlaceholderFromEnvVariables;
|
||||
configData["ResolvedPlaceholderFromJson"] = Options.ResolvedPlaceholderFromJson;
|
||||
configData["UnresolvedPlaceholder"] = Options.UnresolvedPlaceholder;
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class RandomValueDataController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public RandomValueDataController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(GetPlaceholderData());
|
||||
}
|
||||
|
||||
private IDictionary<string, string> GetPlaceholderData()
|
||||
{
|
||||
var configData = new Dictionary<string, string>();
|
||||
|
||||
configData["random:int"] = _config["random:int"];
|
||||
configData["random:long"] = _config["random:long"];
|
||||
configData["random:int(10)"] = _config["random:int(10)"];
|
||||
configData["random:long(100)"] = _config["random:long(100)"];
|
||||
configData["random:int(10,20)"] = _config["random:int(10,20)"];
|
||||
configData["random:long(100,200)"] = _config["random:long(100,200)"];
|
||||
configData["random:uuid"] = _config["random:uuid"];
|
||||
configData["random:string"] = _config["random:string"];
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
{{/RabbitMQ}}
|
||||
{{#AnyConfigSource}}
|
||||
using Microsoft.Extensions.Configuration;
|
||||
{{/AnyConfigSource}}
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
{{#Auth}}
|
||||
|
@ -40,7 +43,8 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
{
|
||||
{{^MoreThanOneValuesControllerWithArgs}}
|
||||
{{#SQLServer}}
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
|
@ -194,6 +198,63 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ}}
|
||||
{{#ConfigServer}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/RandomValueConfig}}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{#MoreThanOneValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{^ValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
|
|
|
@ -31,15 +31,6 @@ namespace {{ProjectNameSpace}}
|
|||
public static void Main(string[] args)
|
||||
{
|
||||
CreateWebHostBuilder(args)
|
||||
{{#ConfigServer}}
|
||||
.AddConfigServer()
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
.AddPlaceholderResolver()
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
{{/RandomValueConfig}}
|
||||
.Build()
|
||||
{{#AnyEFCore}}
|
||||
.InitializeDbContexts()
|
||||
|
@ -56,6 +47,15 @@ namespace {{ProjectNameSpace}}
|
|||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
.AddConfigServer()
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
.AddPlaceholderResolver()
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
{{/RandomValueConfig}}
|
||||
.UseStartup<Startup>();
|
||||
{{#ActuatorsOrDynamicLogger}}
|
||||
builder.ConfigureLogging((hostingContext, loggingBuilder) =>
|
||||
|
|
|
@ -61,9 +61,6 @@ using Steeltoe.CloudFoundry.Connector.OAuth;
|
|||
{{#PostgresEFCore}}
|
||||
using Steeltoe.CloudFoundry.Connector.PostgreSql.EFCore;
|
||||
{{/PostgresEFCore}}
|
||||
{{#ConfigServer}}
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
{{/ConfigServer}}
|
||||
|
||||
namespace {{ProjectNameSpace}}
|
||||
{
|
||||
|
@ -135,16 +132,6 @@ namespace {{ProjectNameSpace}}
|
|||
{{#SQLServer}}
|
||||
services.AddSqlServerConnection(Configuration);
|
||||
{{/SQLServer}}
|
||||
{{#ConfigServer}}
|
||||
// Optional: Adds ConfigServerClientOptions to service container
|
||||
services.ConfigureConfigServerClientOptions(Configuration);
|
||||
|
||||
// Optional: Adds IConfiguration and IConfigurationRoot to service container
|
||||
services.AddConfiguration(Configuration);
|
||||
|
||||
// Adds the configuration data POCO configured with data returned from the Spring Cloud Config Server
|
||||
services.Configure<ConfigServerData>(Configuration);
|
||||
{{/ConfigServer}}
|
||||
{{#TargetFrameworkVersion22}}
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
{{/TargetFrameworkVersion22}}
|
||||
|
|
|
@ -4,10 +4,4 @@
|
|||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
{{"#PlaceholderConfig"}}
|
||||
"ResolvedPlaceholderFromEnvVariables": "${PATH?NotFound}",
|
||||
"UnresolvedPlaceholder": "${SomKeyNotFound?NotFound}",
|
||||
"ResolvedPlaceholderFromJson": "${Logging:LogLevel:System?${Loggin:LogLevel:Default}}"
|
||||
{{"/PlaceholderConfig"}}
|
||||
}
|
||||
"AllowedHosts": "*"
|
||||
|
|
|
@ -120,14 +120,24 @@
|
|||
},
|
||||
{
|
||||
"Name": "ValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis,ConfigServer,RamdomValueConfig,PlaceholderConfig",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "MoreThanOneValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis,ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "MoreThanOne"
|
||||
},
|
||||
{
|
||||
"Name": "AnyConnector",
|
||||
"Expression": "MySql,Postgres,SQLServer,Redis,MongoDB,RabbitMQ,OAuthConnector",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "AnyConfigSource",
|
||||
"Expression": "ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "AspNetCoreVersion",
|
||||
"Expression": "TargetFrameworkVersion,netcoreapp2.2=2.2.0,netcoreapp2.1=2.1.1,default=False",
|
||||
|
@ -143,18 +153,6 @@
|
|||
{
|
||||
"Name": "AnyEFCore",
|
||||
"InclusionExpression": "Models/**"
|
||||
},
|
||||
{
|
||||
"Name": "ConfigServer",
|
||||
"InclusionExpression": "Models/ConfigServerData.cs;Controllers/ConfigDataController.cs"
|
||||
},
|
||||
{
|
||||
"Name": "PlaceholderConfig",
|
||||
"InclusionExpression": "SampleOptions.cs;Controllers/PlaceholderDataController.cs"
|
||||
},
|
||||
{
|
||||
"Name": "RandomValueConfig",
|
||||
"InclusionExpression": "Controllers/RandomValueDataController.cs"
|
||||
}
|
||||
],
|
||||
"Versions": [
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ConfigDataController : ControllerBase
|
||||
{
|
||||
private IOptionsSnapshot<ConfigServerData> IConfigServerData { get; set; }
|
||||
|
||||
private ConfigServerClientSettingsOptions ConfigServerClientSettingsOptions { get; set; }
|
||||
|
||||
private IConfigurationRoot Config { get; set; }
|
||||
|
||||
public ConfigDataController(IConfigurationRoot config, IOptionsSnapshot<ConfigServerData> configServerData, IOptions<ConfigServerClientSettingsOptions> confgServerSettings)
|
||||
{
|
||||
// The ASP.NET DI mechanism injects the data retrieved from the Spring Cloud Config Server
|
||||
// as an IOptionsSnapshot<ConfigServerData>. This happens because we added the call to:
|
||||
// "services.Configure<ConfigServerData>(Configuration);" in the StartUp class
|
||||
if (configServerData != null)
|
||||
IConfigServerData = configServerData;
|
||||
|
||||
// The settings used in communicating with the Spring Cloud Config Server
|
||||
if (confgServerSettings != null)
|
||||
ConfigServerClientSettingsOptions = confgServerSettings.Value;
|
||||
|
||||
Config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(CreateConfigServerData());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Reload()
|
||||
{
|
||||
if (Config != null)
|
||||
{
|
||||
Config.Reload();
|
||||
}
|
||||
return Ok();
|
||||
}
|
||||
|
||||
private IDictionary<string, string> CreateConfigServerData()
|
||||
{
|
||||
|
||||
var configData = new Dictionary<string, string>();
|
||||
|
||||
// IConfigServerData property is set to a IOptionsSnapshot<ConfigServerData> that has been
|
||||
// initialized with the configuration data returned from the Spring Cloud Config Server
|
||||
if (IConfigServerData != null && IConfigServerData.Value != null)
|
||||
{
|
||||
var data = IConfigServerData.Value;
|
||||
configData["Bar"] = data.Bar ?? "Not returned";
|
||||
configData["Foo"] = data.Foo ?? "Not returned";
|
||||
|
||||
configData["Info.Url"] = "Not returned";
|
||||
configData["Info.Description"] = "Not returned";
|
||||
|
||||
if (data.Info != null)
|
||||
{
|
||||
configData["Info.Url"] = data.Info.Url ?? "Not returned";
|
||||
configData["Info.Description"] = data.Info.Description ?? "Not returned";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
configData["Bar"] = "Not Available";
|
||||
configData["Foo"] = "Not Available";
|
||||
configData["Info.Url"] = "Not Available";
|
||||
configData["Info.Description"] = "Not Available";
|
||||
}
|
||||
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class PlaceholderDataController : ControllerBase
|
||||
{
|
||||
IOptionsMonitor<SampleOptions> _opts;
|
||||
|
||||
private SampleOptions Options
|
||||
{
|
||||
get
|
||||
{
|
||||
return _opts.CurrentValue;
|
||||
}
|
||||
}
|
||||
|
||||
public PlaceholderDataController(IOptionsMonitor<SampleOptions> opts)
|
||||
{
|
||||
_opts = opts;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(GetPlaceholderData());
|
||||
}
|
||||
|
||||
private IDictionary<string, string> GetPlaceholderData()
|
||||
{
|
||||
|
||||
var configData = new Dictionary<string, string>();
|
||||
configData["ResolvedPlaceholderFromEnvVariables"] = Options.ResolvedPlaceholderFromEnvVariables;
|
||||
configData["ResolvedPlaceholderFromJson"] = Options.ResolvedPlaceholderFromJson;
|
||||
configData["UnresolvedPlaceholder"] = Options.UnresolvedPlaceholder;
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class RandomValueDataController : ControllerBase
|
||||
{
|
||||
private readonly IConfiguration _config;
|
||||
|
||||
public RandomValueDataController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IDictionary<string, string>> Get()
|
||||
{
|
||||
return Ok(GetPlaceholderData());
|
||||
}
|
||||
|
||||
private IDictionary<string, string> GetPlaceholderData()
|
||||
{
|
||||
var configData = new Dictionary<string, string>();
|
||||
|
||||
configData["random:int"] = _config["random:int"];
|
||||
configData["random:long"] = _config["random:long"];
|
||||
configData["random:int(10)"] = _config["random:int(10)"];
|
||||
configData["random:long(100)"] = _config["random:long(100)"];
|
||||
configData["random:int(10,20)"] = _config["random:int(10,20)"];
|
||||
configData["random:long(100,200)"] = _config["random:long(100,200)"];
|
||||
configData["random:uuid"] = _config["random:uuid"];
|
||||
configData["random:string"] = _config["random:string"];
|
||||
return configData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
{{/RabbitMQ}}
|
||||
{{#AnyConfigSource}}
|
||||
using Microsoft.Extensions.Configuration;
|
||||
{{/AnyConfigSource}}
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
{{#Auth}}
|
||||
|
@ -41,6 +44,7 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
[ApiController]
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
{{^MoreThanOneValuesControllerWithArgs }}
|
||||
{{#SQLServer}}
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
|
@ -194,6 +198,63 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ}}
|
||||
{{#ConfigServer}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/RandomValueConfig}}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{#MoreThanOneValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{^ValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
|
|
|
@ -15,6 +15,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
{{/ RandomValueConfig}}
|
||||
namespace {{ProjectNameSpace}}
|
||||
{
|
||||
public class Program
|
||||
|
@ -33,10 +42,19 @@ namespace {{ProjectNameSpace}}
|
|||
{
|
||||
var builder = WebHost.CreateDefaultBuilder(args)
|
||||
.UseDefaultServiceProvider(configure => configure.ValidateScopes = false)
|
||||
{{#CloudFoundry}}
|
||||
{{#CloudFoundry}}
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
{{/CloudFoundry}}
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
.AddConfigServer()
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
.AddPlaceholderResolver()
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
{{/RandomValueConfig}}
|
||||
.UseStartup<Startup>();
|
||||
{{#ActuatorsOrDynamicLogger}}
|
||||
builder.ConfigureLogging((hostingContext, loggingBuilder) =>
|
||||
|
|
|
@ -82,6 +82,24 @@
|
|||
"Name": "ProjectNameSpace",
|
||||
"DefaultValue": "SteeltoeExample",
|
||||
"Description": "Change the namespace "
|
||||
},
|
||||
{
|
||||
"Name": "ConfigServer",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add ConfigServer Configuration Source",
|
||||
"friendlyName": "Config Server"
|
||||
},
|
||||
{
|
||||
"Name": "PlaceholderConfig",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add Placeholder Configuration Source",
|
||||
"friendlyName": "Placeholder Configuration Source"
|
||||
},
|
||||
{
|
||||
"Name": "RandomValueConfig",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add RandomValue Configuration Source",
|
||||
"friendlyName": "RandomValue Configuration Source"
|
||||
}
|
||||
],
|
||||
"CalculatedParams": [
|
||||
|
@ -100,9 +118,14 @@
|
|||
"Expression": "Actuators,DynamicLogger",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "MoreThanOneValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis,ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "MoreThanOne"
|
||||
},
|
||||
{
|
||||
"Name": "ValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis,ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
|
@ -119,24 +142,17 @@
|
|||
"Name": "TargetFrameworkVersion22",
|
||||
"Expression": "TargetFrameworkVersion,netcoreapp2.2=true,default=False",
|
||||
"ExpressionType": "Case"
|
||||
},
|
||||
{
|
||||
"Name": "AnyConfigSource",
|
||||
"Expression": "ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "Any"
|
||||
}
|
||||
],
|
||||
"ConditionalInclusions": [
|
||||
{
|
||||
"Name": "AnyEFCore",
|
||||
"InclusionExpression": "Models/**"
|
||||
},
|
||||
{
|
||||
"Name": "ConfigServer",
|
||||
"InclusionExpression": "Models/ConfigServerData.cs;Controllers/ConfigDataController.cs"
|
||||
},
|
||||
{
|
||||
"Name": "PlaceholderConfig",
|
||||
"InclusionExpression": "SampleOptions.cs;Controllers/PlaceholderDataController.cs"
|
||||
},
|
||||
{
|
||||
"Name": "RandomValueConfig",
|
||||
"InclusionExpression": "Controllers/RandomValueDataController.cs"
|
||||
}
|
||||
],
|
||||
"Versions": [
|
||||
|
|
|
@ -32,6 +32,9 @@ using RabbitMQ.Client.Events;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
{{/RabbitMQ}}
|
||||
{{#AnyConfigSource}}
|
||||
using Microsoft.Extensions.Configuration;
|
||||
{{/AnyConfigSource}}
|
||||
namespace {{ProjectNameSpace}}.Controllers
|
||||
{
|
||||
{{#Auth}}
|
||||
|
@ -40,7 +43,8 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class ValuesController : ControllerBase
|
||||
{
|
||||
{
|
||||
{{^MoreThanOneValuesControllerWithArgs }}
|
||||
{{#SQLServer}}
|
||||
private readonly SqlConnection _dbConnection;
|
||||
public ValuesController([FromServices] SqlConnection dbConnection)
|
||||
|
@ -194,6 +198,63 @@ namespace {{ProjectNameSpace}}.Controllers
|
|||
return "Wrote 5 message to the info log. Have a look!";
|
||||
}
|
||||
{{/RabbitMQ}}
|
||||
{{#ConfigServer}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["Value1"];
|
||||
var val2 = _config["Value2"];
|
||||
return new string[] { val1, val2 };
|
||||
}
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["ResolvedPlaceholderFromEnvVariables"];
|
||||
var val2 = _config["UnresolvedPlaceholder"];
|
||||
var val3 = _config["ResolvedPlaceholderFromJson"];
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
private readonly IConfiguration _config;
|
||||
public ValuesController(IConfiguration config)
|
||||
{
|
||||
_config = config;
|
||||
}
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<IEnumerable<string>> Get()
|
||||
{
|
||||
var val1 = _config["random:int"];
|
||||
var val2 = _config["random:uuid"];
|
||||
var val3 = _config["random:string"];
|
||||
|
||||
return new string[] { val1, val2, val3 };
|
||||
}
|
||||
{{/RandomValueConfig}}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{#MoreThanOneValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
{
|
||||
return "value";
|
||||
}
|
||||
{{/MoreThanOneValuesControllerWithArgs}}
|
||||
{{^ValuesControllerWithArgs}}
|
||||
[HttpGet]
|
||||
public ActionResult<string> Get()
|
||||
|
|
|
@ -15,6 +15,15 @@ using Steeltoe.Extensions.Logging;
|
|||
using Steeltoe.Extensions.Configuration;
|
||||
using Steeltoe.Extensions.Configuration.CloudFoundry;
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
using Steeltoe.Extensions.Configuration.ConfigServer;
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
using Steeltoe.Extensions.Configuration.PlaceholderCore;
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
using Steeltoe.Extensions.Configuration.RandomValue;
|
||||
{{/ RandomValueConfig}}
|
||||
namespace {{ProjectNameSpace}}
|
||||
{
|
||||
public class Program
|
||||
|
@ -34,10 +43,19 @@ namespace {{ProjectNameSpace}}
|
|||
{
|
||||
var builder = WebHost.CreateDefaultBuilder(args)
|
||||
.UseDefaultServiceProvider(configure => configure.ValidateScopes = false)
|
||||
{{#CloudFoundry}}
|
||||
{{#CloudFoundry}}
|
||||
.UseCloudFoundryHosting(5555) //Enable listening on a Env provided port
|
||||
.AddCloudFoundry() //Add cloudfoundry environment variables as a configuration source
|
||||
{{/CloudFoundry}}
|
||||
{{/CloudFoundry}}
|
||||
{{#ConfigServer}}
|
||||
.AddConfigServer()
|
||||
{{/ConfigServer}}
|
||||
{{#PlaceholderConfig}}
|
||||
.AddPlaceholderResolver()
|
||||
{{/PlaceholderConfig}}
|
||||
{{#RandomValueConfig}}
|
||||
.ConfigureAppConfiguration((b) => b.AddRandomValueSource())
|
||||
{{/RandomValueConfig}}
|
||||
.UseStartup<Startup>();
|
||||
{{#ActuatorsOrDynamicLogger}}
|
||||
builder.ConfigureLogging((hostingContext, loggingBuilder) =>
|
||||
|
|
|
@ -4,10 +4,5 @@
|
|||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
{{"#PlaceholderConfig"}}
|
||||
"ResolvedPlaceholderFromEnvVariables": "${PATH?NotFound}",
|
||||
"UnresolvedPlaceholder": "${SomKeyNotFound?NotFound}",
|
||||
"ResolvedPlaceholderFromJson": "${Logging:LogLevel:System?${Loggin:LogLevel:Default}}",
|
||||
{{"/PlaceholderConfig"}}
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
|
|
@ -82,6 +82,24 @@
|
|||
"Name": "ProjectNameSpace",
|
||||
"DefaultValue": "SteeltoeExample",
|
||||
"Description": "Change the namespace "
|
||||
},
|
||||
{
|
||||
"Name": "ConfigServer",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add ConfigServer Configuration Source",
|
||||
"friendlyName": "Config Server"
|
||||
},
|
||||
{
|
||||
"Name": "PlaceholderConfig",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add Placeholder Configuration Source",
|
||||
"friendlyName": "Placeholder Configuration Source"
|
||||
},
|
||||
{
|
||||
"Name": "RandomValueConfig",
|
||||
"DefaultValue": false,
|
||||
"Description": "Steeltoe: Add RandomValue Configuration Source",
|
||||
"friendlyName": "RandomValue Configuration Source"
|
||||
}
|
||||
],
|
||||
"CalculatedParams": [
|
||||
|
@ -100,9 +118,19 @@
|
|||
"Expression": "Actuators,DynamicLogger",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "MoreThanOneValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis,ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "MoreThanOne"
|
||||
},
|
||||
{
|
||||
"Name": "ValuesControllerWithArgs",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis",
|
||||
"Expression": "SQLServer,MySql,Postgres,MongoDB,RabbitMQ,Redis,ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
"Name": "AnyConfigSource",
|
||||
"Expression": "ConfigServer,PlaceholderConfig,RandomValueConfig",
|
||||
"ExpressionType": "Any"
|
||||
},
|
||||
{
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace Steeltoe.Initializr.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestExpressions()
|
||||
public async Task TestBoolExpressions()
|
||||
{
|
||||
var config = new MustacheConfigSchema()
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ namespace Steeltoe.Initializr.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestExpressionsActuators()
|
||||
public async Task TestBoolExpressionsActuators()
|
||||
{
|
||||
var config = new MustacheConfigSchema()
|
||||
{
|
||||
|
@ -115,7 +115,7 @@ namespace Steeltoe.Initializr.Tests
|
|||
{
|
||||
Name = "AspNetCoreVersion",
|
||||
Expression = "dataView => dataView[\"TargetFrameworkVersion\"]==\"netcoreapp2.2\"? \"2.2.0\": null",
|
||||
ExpressionType = ExpressionTypeEnum.String,
|
||||
ExpressionType = ExpressionTypeEnum.Bool,
|
||||
};
|
||||
|
||||
var expression = new StringExpression(_logger, calcParam, config);
|
||||
|
@ -123,6 +123,52 @@ namespace Steeltoe.Initializr.Tests
|
|||
Assert.Equal("2.2.0", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test_MorethanOneExpression_true()
|
||||
{
|
||||
var config = new MustacheConfigSchema();
|
||||
var dv = new Dictionary<string, string>
|
||||
{
|
||||
{ "IsMoreThanOne", "false" },
|
||||
{ "ConfigServer", "true" },
|
||||
{ "SQLServer", "true" },
|
||||
{ "Redis", "false" },
|
||||
};
|
||||
var calcParam = new CalculatedParam
|
||||
{
|
||||
Name = "IsMoreThanOne",
|
||||
Expression = "ConfigServer,SQLServer,Redis",
|
||||
ExpressionType = ExpressionTypeEnum.MoreThanOne,
|
||||
};
|
||||
|
||||
var expression = new MoreThanOneExpression(_logger, calcParam, config);
|
||||
var result = await expression.EvaluateExpressionAsync(dv);
|
||||
Assert.Equal("True", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test_MorethanOneExpression_false()
|
||||
{
|
||||
var config = new MustacheConfigSchema();
|
||||
var dv = new Dictionary<string, string>
|
||||
{
|
||||
{ "IsMoreThanOne", "false" },
|
||||
{ "ConfigServer", "false" },
|
||||
{ "SQLServer", "true" },
|
||||
{ "Redis", "false" },
|
||||
};
|
||||
var calcParam = new CalculatedParam
|
||||
{
|
||||
Name = "IsMoreThanOne",
|
||||
Expression = "ConfigServer,SQLServer,Redis",
|
||||
ExpressionType = ExpressionTypeEnum.MoreThanOne,
|
||||
};
|
||||
|
||||
var expression = new MoreThanOneExpression(_logger, calcParam, config);
|
||||
var result = await expression.EvaluateExpressionAsync(dv);
|
||||
Assert.Equal("False", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TestCaseExpression()
|
||||
{
|
||||
|
|
|
@ -211,23 +211,85 @@ namespace Steeltoe.Initializr.Tests
|
|||
Assert.Contains(@"DataTable dt = _dbConnection.GetSchema(""Databases"");", valuesController);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateTemplate_ConfigServer()
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_ConfigServer(ITemplateService templateService, string templateName, TemplateVersion version)
|
||||
{
|
||||
var configuration = TestHelper.GetConfiguration();
|
||||
var logger = new LoggerFactory().CreateLogger<MustacheTemplateService>();
|
||||
|
||||
ITemplateService templateService = new MustacheTemplateService(configuration, logger);
|
||||
var files = await templateService.GenerateProjectFiles(new Models.GeneratorModel()
|
||||
{
|
||||
Dependencies = "ConfigServer",
|
||||
TemplateShortName = "Steeltoe-WebApi",
|
||||
TemplateVersion = TemplateVersion.V2,
|
||||
TemplateShortName = templateName,
|
||||
TemplateVersion = version,
|
||||
});
|
||||
|
||||
Assert.DoesNotContain(files, file => file.Key.EndsWith("SampleData.cs"));
|
||||
Assert.Contains(files, file => file.Key.EndsWith("ConfigDataController.cs"));
|
||||
Assert.Contains(files, file => file.Key.EndsWith("ConfigServerData.cs"));
|
||||
Assert.Contains(files, file => file.Key.EndsWith("ValuesController.cs"));
|
||||
|
||||
string programContents = files.Find(x => x.Key == "Program.cs").Value;
|
||||
Assert.Contains("using Steeltoe.Extensions.Configuration.ConfigServer;", programContents);
|
||||
|
||||
string valuesController = files.Find(x => x.Key == "Controllers\\ValuesController.cs").Value;
|
||||
Assert.Contains("using Microsoft.Extensions.Configuration;", valuesController);
|
||||
|
||||
Assert.Contains(@"public ValuesController(IConfiguration config)", valuesController);
|
||||
Assert.Contains(@"_config[""Value1""];", valuesController);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_Randomvalue(ITemplateService templateService, string templateName, TemplateVersion version)
|
||||
{
|
||||
var configuration = TestHelper.GetConfiguration();
|
||||
var logger = new LoggerFactory().CreateLogger<MustacheTemplateService>();
|
||||
|
||||
var files = await templateService.GenerateProjectFiles(new Models.GeneratorModel()
|
||||
{
|
||||
Dependencies = "RandomValueConfig",
|
||||
TemplateShortName = templateName,
|
||||
TemplateVersion = version,
|
||||
});
|
||||
|
||||
Assert.DoesNotContain(files, file => file.Key.EndsWith("SampleData.cs"));
|
||||
Assert.Contains(files, file => file.Key.EndsWith("ValuesController.cs"));
|
||||
|
||||
string programContents = files.Find(x => x.Key == "Program.cs").Value;
|
||||
Assert.Contains("using Steeltoe.Extensions.Configuration.RandomValue;", programContents);
|
||||
|
||||
string valuesController = files.Find(x => x.Key == "Controllers\\ValuesController.cs").Value;
|
||||
Assert.Contains("using Microsoft.Extensions.Configuration;", valuesController);
|
||||
|
||||
Assert.Contains(@"public ValuesController(IConfiguration config)", valuesController);
|
||||
Assert.Contains(@"_config[""random:int""];", valuesController);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[ClassData(typeof(AllImplementationsAndTemplates))]
|
||||
public async Task CreateTemplate_Placeholderconfig(ITemplateService templateService, string templateName, TemplateVersion version)
|
||||
{
|
||||
var configuration = TestHelper.GetConfiguration();
|
||||
var logger = new LoggerFactory().CreateLogger<MustacheTemplateService>();
|
||||
|
||||
var files = await templateService.GenerateProjectFiles(new Models.GeneratorModel()
|
||||
{
|
||||
Dependencies = "PlaceholderConfig",
|
||||
TemplateShortName = templateName,
|
||||
TemplateVersion = version,
|
||||
});
|
||||
|
||||
Assert.DoesNotContain(files, file => file.Key.EndsWith("SampleData.cs"));
|
||||
Assert.Contains(files, file => file.Key.EndsWith("ValuesController.cs"));
|
||||
|
||||
string programContents = files.Find(x => x.Key == "Program.cs").Value;
|
||||
Assert.Contains("using Steeltoe.Extensions.Configuration.PlaceholderCore;", programContents);
|
||||
|
||||
string valuesController = files.Find(x => x.Key == "Controllers\\ValuesController.cs").Value;
|
||||
Assert.Contains("using Microsoft.Extensions.Configuration;", valuesController);
|
||||
|
||||
Assert.Contains(@"public ValuesController(IConfiguration config)", valuesController);
|
||||
Assert.Contains(@"_config[""ResolvedPlaceholderFromEnvVariables""];", valuesController);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -348,7 +410,7 @@ using System.Threading;", valuesController);
|
|||
|
||||
var files = await templateService.GenerateProjectFiles(new Models.GeneratorModel()
|
||||
{
|
||||
Dependencies = "SQLServer",
|
||||
Dependencies = "SQLServer,ConfigServer",
|
||||
ProjectName = "testProject",
|
||||
TemplateShortName = templateName,
|
||||
SteeltoeVersion = steeltoeVersion,
|
||||
|
|
Загрузка…
Ссылка в новой задаче