This commit is contained in:
hananiel 2019-12-10 18:34:59 -05:00
Родитель ca4c0a9892
Коммит bf1e876292
4 изменённых файлов: 178 добавлений и 10 удалений

Просмотреть файл

@ -18,12 +18,41 @@ The Web UI allows you to quickly generate a CSharp project with your choice of d
## Curl
To get help:
```
curl https://start.steeltoe.io/
(
)\ ) ) ( )
(()/( ( /( ( ( )\ ( /( (
/(_)))\()) ))\ ))\((_))\()) ( ))\
____ (_)) (_))/ /((_)/((_)_ (_))/ )\ /((_)__ __ __
/ /\ \ / __|| |_ (_)) (_)) | || |_ ((_)(_)) \ \\ \\ \
< < > > \__ \| _|/ -_)/ -_)| || _|/ _ \/ -_) > >> >> >
\_\/_/ |___/ \__|\___|\___||_| \__|\___/\___| /_//_//_/
Dependencies:
+----------------------------------------+----------------------------------------------------------------------------------------------------+
+ Title + Description +
+----------------------------------------+----------------------------------------------------------------------------------------------------+
+ Actuators + Add management endpoints for your application +
+ Circuit Breakers + Add Circuit Breakers +
+ Cloud Foundry + Target CloudFoundry Hosting +
+ Discovery + Add Discovery Client +
+ DynamicLogger + Add Dynamic Logger +
...
```
To generate projects:
```
curl https://start.steeltoe.io/starter.zip -d dependencies=actuators,cloudfoundry -o myProject.zip
or
curl https://start.steeltoe.io/starter.zip -d dependencies=actuators,cloudfoundry -d templateShortName=react -d projectName=MyCompany.MySample -o myProject.zip
curl https://start.steeltoe.io/starter.zip -d dependencies=actuators,cloudfoundry -d templateShortName=Steeltoe-React -d projectName=MyCompany.MySample -o myProject.zip
```
To get a list of dependencies:
@ -33,7 +62,7 @@ curl https://start.steeltoe.io/api/templates/dependencies
To get a list of valid templates:
```
curl https://startsteeeltoe.cfapps.io/api/templates/templates
curl https://start.steeltoe.io/api/templates/templates
```
## Dotnet templates
Install the Steeloe Templates

Просмотреть файл

@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using Microsoft.AspNetCore.Routing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Steeltoe.Initializr.Controllers
{
public class IsCurlRequestAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action)
{
var headers = routeContext.HttpContext.Request.Headers;
return headers["User-Agent"].Any(h => h.ToLower().Contains("curl"));
}
}
}

Просмотреть файл

@ -0,0 +1,110 @@
// 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.AspNetCore.Mvc;
using Steeltoe.Initializr.Models;
using Steeltoe.Initializr.Services;
using Steeltoe.Initializr.Services.Mustache;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace Steeltoe.Initializr.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class HomeController : ControllerBase
{
private const string LOGO = @" (
)\ ) ) ( )
(()/( ( /( ( ( )\ ( /( (
/(_)))\()) ))\ ))\((_))\()) ( ))\
____ (_)) (_))/ /((_)/((_)_ (_))/ )\ /((_)__ __ __
/ /\ \ / __|| |_ (_)) (_)) | || |_ ((_)(_)) \ \\ \\ \
< < > > \__ \| _|/ -_)/ -_)| || _|/ _ \/ -_) > >> >> >
\_\/_/ |___/ \__|\___|\___||_| \__|\___/\___| /_//_//_/
";
private readonly MustacheTemplateService _templateService;
public HomeController(IEnumerable<ITemplateService> services)
{
_templateService = services.OfType<MustacheTemplateService>().FirstOrDefault();
}
[Route("/")]
[HttpGet]
[IsCurlRequest]
public ActionResult<string> CurlHelp()
{
// get dependencies
var result = new StringBuilder();
result.Append(LOGO);
result.Append(GetDependencies());
result.Append(GetExamples());
return Content(result.ToString());
}
private string GetExamples()
{
return @"
Get Dependencies:
curl https://start.steeltoe.io/api/templates/dependencies | jq .
Get Versions:
curl https://start.steeeltoe.io/api/templates/templates | jq .
Get project:
curl https://start.steeltoe.io/starter.zip -d dependencies=actuators,cloudfoundry -o myProject.zip
curl https://start.steeltoe.io/starter.zip -d dependencies=actuators,cloudfoundry -d templateShortName=Steeltoe-React -d targetFrameworkVersion=netcoreapp3.1 -d projectName=MyCompany.MySample -o myProject.zip
";
}
private string GetDependencies()
{
var result = new StringBuilder();
var dependencies = _templateService.GetDependencies(string.Empty, TemplateVersion.V3);
var fieldWidths = new int[] { 40, 100 };
result.Append("\nDependencies: \n");
result.Append(GetHorizontalBorder(fieldWidths));
result.Append(GetRow("Title", "Description", fieldWidths));
result.Append(GetHorizontalBorder(fieldWidths));
foreach (var dep in dependencies)
{
result.Append(GetRow(dep.Name, dep.Description.Replace("Steeltoe: ", ""), fieldWidths));
}
result.Append(GetHorizontalBorder(fieldWidths));
result.Append("\n");
return result.ToString();
}
private string GetRow(string title, string description, int[] fieldWidths)
{
return string.Format("+ {0}+ {1}+\n", title.PadRight(fieldWidths[0] - 1), description.PadRight(fieldWidths[1] - 1));
}
private string GetHorizontalBorder(int[] widths)
{
return "+" + new string('-', widths[0]) + "+" + new string('-', widths[1]) + "+\n";
}
}
}

Просмотреть файл

@ -16,8 +16,10 @@ using Microsoft.AspNetCore.Mvc;
using Steeltoe.Initializr.Models;
using Steeltoe.Initializr.Services;
using Steeltoe.Initializr.Services.Mustache;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http.Headers;
using System.Threading.Tasks;
@ -47,7 +49,7 @@ namespace Steeltoe.Initializr.Controllers
[HttpGet]
public Task<ActionResult> GenerateProjectGet([FromQuery] GeneratorModel model)
{
return GenerateProject(model);
return GenerateProject(model);
}
[Route("dependencies")]
@ -64,16 +66,24 @@ namespace Steeltoe.Initializr.Controllers
private async Task<ActionResult> GenerateProject(GeneratorModel model)
{
var archiveBytes = await _sttemplateService.GenerateProjectArchiveAsync(model);
var cd = new ContentDispositionHeaderValue("attachment")
try
{
FileNameStar = model.ArchiveName,
};
var archiveBytes = await _sttemplateService.GenerateProjectArchiveAsync(model);
Response.Headers.Add("Content-Disposition", cd.ToString());
var cd = new ContentDispositionHeaderValue("attachment")
{
FileNameStar = model.ArchiveName,
};
return File(archiveBytes, "application/zip");
Response.Headers.Add("Content-Disposition", cd.ToString());
return File(archiveBytes, "application/zip");
}
catch (Exception ex)
{
HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content(ex.Message);
}
}
}
}