private IBlueprintPackage GetBlueprintPackageCore(IBlueprintPackage parent, string blueprint) { if (parent == null) { foreach (var provider in _packageProviders) { var blueprintPackage = provider.TryGetBlueprintPackage(blueprint); if (blueprintPackage != null) { return(blueprintPackage); } } } else { foreach (var provider in _dependencyPackageProviders) { var blueprintPackage = provider.TryGetBlueprintPackage(parent, blueprint); if (blueprintPackage != null) { return(blueprintPackage); } } } return(null); }
public IBlueprintPackage TryGetBlueprintPackage(IBlueprintPackage parent, string blueprint) { if (parent.Exists(_fileSystem.PathCombine(blueprint, "workflow.yaml"))) { return(new DependencyBlueprintPackage(_fileSystem, parent, blueprint)); } return(null); }
public async Task <IBlueprintPackage> CreateDecorator <TInfo>(TInfo info, IBlueprintPackage package) { if (info is DependencyReference dependencyInfo) { return(await _factory.Create((dependencyInfo, package))); } return(package); }
public SwaggerBlueprintDecorator( IBlueprintPackage package, IRequestGenerator requestGenerator, IHttpClientFactory httpClientFactory, IYamlSerializers yamlSerializers) : base(package) { _requestGenerator = requestGenerator; _httpClientFactory = httpClientFactory; _yamlSerializers = yamlSerializers; }
public async Task <IBlueprintPackage> GetBlueprintPackageDependency(IBlueprintPackage parent, string blueprint) { var blueprintPackageCore = GetBlueprintPackageCore(parent, blueprint); if (blueprintPackageCore == null) { throw new Exception($"Unable to find blueprint {blueprint}"); } var blueprintPackage = await DecorateBlueprintPackage(blueprintPackageCore); return(blueprintPackage); }
public async Task <IBlueprintPackage> CreateDecorator <TInfo>(TInfo info, IBlueprintPackage package) { if (info is SwaggerReference swaggerBlueprintInfo) { var decorator = new SwaggerBlueprintDecorator( package, _requestGenerator, _httpClientFactory, _yamlSerializers); await decorator.Initialize(swaggerBlueprintInfo); return(decorator); } return(package); }
private async Task <IBlueprintPackage> DecorateBlueprintPackage(IBlueprintPackage blueprintPackageCore) { var blueprintInfo = new WorkflowInfoDocument(); var blueprintPackage = blueprintPackageCore; if (blueprintPackage.Exists("readme.md")) { var readmeText = blueprintPackageCore.OpenText("readme.md").ReadToEnd(); var readmeDoc = Markdig.Markdown.Parse(readmeText); var codeBlocks = readmeDoc.OfType <FencedCodeBlock>(); var yamlBlocks = codeBlocks.Where(cb => string.Equals(cb.Info, "yaml", StringComparison.Ordinal)); if (yamlBlocks.Any()) { var yamlLines = yamlBlocks.SelectMany(yaml => yaml.Lines.Lines); var yamlText = yamlLines.Aggregate(string.Empty, (a, b) => $"{a}{b}{Environment.NewLine}"); blueprintInfo = _yamlSerializers.YamlDeserializer.Deserialize <WorkflowInfoDocument>(yamlText); } blueprintPackage = new GeneratedReadmeBlueprintDecorator(blueprintPackage, string.Empty); } foreach (var swaggerInfo in blueprintInfo.swagger.Values) { foreach (var decoratorProvider in _decoratorProviders) { blueprintPackage = await decoratorProvider.CreateDecorator(swaggerInfo, blueprintPackage); } } foreach (var dependencyInfo in blueprintInfo.workflows.Values) { foreach (var decoratorProvider in _decoratorProviders) { blueprintPackage = await decoratorProvider.CreateDecorator(dependencyInfo, blueprintPackage); } } return(blueprintPackage); }
public GeneratedReadmeBlueprintDecorator(IBlueprintPackage package, string readmeText) : base(package) { GeneratedFiles["readme.md"] = readmeText; }
protected GeneratedFileBlueprintDecorator(IBlueprintPackage package) { _package = package; }
public DependencyBlueprintPackage(IFileSystem fileSystem, IBlueprintPackage parent, string directoryPath) { _fileSystem = fileSystem; _parent = parent; _directoryPath = directoryPath; }
public BlueprintPackageFileSystem(IBlueprintPackage blueprintPackage) { _blueprintPackage = blueprintPackage; }
public (ITemplateEngine templateEngine, WorkflowModel workflow, object effectiveValues) Load(IBlueprintPackage blueprint, object values, Action <string, Action <TextWriter> > generateOutput) { var templateEngine = _templateEngineFactory.Create(new TemplateEngineOptions { FileSystem = new BlueprintPackageFileSystem(blueprint) }); var providedValues = values; if (blueprint.Exists("values.yaml")) { using (var reader = blueprint.OpenText("values.yaml")) { var defaultValues = _serializers.YamlDeserializer.Deserialize(reader); if (values == null) { values = defaultValues; } else { values = MergeUtils.Merge(values, defaultValues); } } } var premodelValues = values; if (blueprint.Exists("model.yaml")) { var model = templateEngine.Render <object>("model.yaml", values); if (model != null) { values = MergeUtils.Merge(model, values); } } var workflowContents = new StringBuilder(); using (var workflowWriter = new StringWriter(workflowContents)) { templateEngine.Render("workflow.yaml", values, workflowWriter); } // NOTE: the workflow is rendered BEFORE writing these output files because it may contain // calls to the "secret" helper which will redact tokens that might have been provided in values // write values to output folder generateOutput("values.yaml", writer => _serializers.YamlSerializer.Serialize(writer, values)); // write workflow to output folder generateOutput("workflow.yaml", writer => writer.Write(workflowContents.ToString())); var workflow = _serializers.YamlDeserializer.Deserialize <WorkflowModel>(new StringReader(workflowContents.ToString())); foreach (var generatedFile in blueprint.GetGeneratedPaths()) { using (var generatedContent = blueprint.OpenText(generatedFile)) { generateOutput($"generated/{generatedFile}", writer => writer.Write(generatedContent.ReadToEnd())); } } return(templateEngine, workflow, values); }
public Builder UseBlueprintPackage(IBlueprintPackage blueprint) { _context.BlueprintPackage = blueprint; return(this); }
Task <IBlueprintPackage> IBlueprintManager.GetBlueprintPackageDependency(IBlueprintPackage package, string blueprint) { throw new System.NotImplementedException("This scenario should be unit tested with StubFileSystem"); }