|
| 1 | +// This file is part of YamlDotNet - A .NET library for YAML. |
| 2 | +// Copyright (c) Antoine Aubry and contributors |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 5 | +// this software and associated documentation files (the "Software"), to deal in |
| 6 | +// the Software without restriction, including without limitation the rights to |
| 7 | +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 | +// of the Software, and to permit persons to whom the Software is furnished to do |
| 9 | +// so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in all |
| 12 | +// copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | +// SOFTWARE. |
| 21 | + |
| 22 | +using System; |
| 23 | +using System.Collections.Generic; |
| 24 | +using System.IO; |
| 25 | +using Xunit.Abstractions; |
| 26 | +using YamlDotNet.Samples.Helpers; |
| 27 | +using YamlDotNet.Serialization; |
| 28 | +using YamlDotNet.Serialization.NamingConventions; |
| 29 | + |
| 30 | +namespace YamlDotNet.Samples |
| 31 | +{ |
| 32 | + public class DeserializeGenericObject |
| 33 | + { |
| 34 | + private readonly ITestOutputHelper output; |
| 35 | + |
| 36 | + public DeserializeGenericObject(ITestOutputHelper output) |
| 37 | + { |
| 38 | + this.output = output; |
| 39 | + } |
| 40 | + |
| 41 | + [Sample( |
| 42 | + DisplayName = "Deserializing generic objects with basic types", |
| 43 | + Description = "Shows how to convert a YAML document to basic types such as String and Dictionary" |
| 44 | + )] |
| 45 | + public void Main() |
| 46 | + { |
| 47 | + var input = new StringReader(Document); |
| 48 | + var deserializer = new DeserializerBuilder() |
| 49 | + .WithNamingConvention(CamelCaseNamingConvention.Instance) |
| 50 | + .Build(); |
| 51 | + var doc = deserializer.Deserialize<List<object>>(input); |
| 52 | + Console.WriteLine("## Document"); |
| 53 | + foreach (Dictionary<object, object> item in doc) |
| 54 | + { |
| 55 | + Console.WriteLine("### Item"); |
| 56 | + foreach (var kvp in item) |
| 57 | + { |
| 58 | + Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value); |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + private const string Document = @"--- |
| 64 | +- name: Install certbot |
| 65 | + tags: setup |
| 66 | + community.general.snap: |
| 67 | + name: certbot |
| 68 | + classic: true |
| 69 | +- name: Create symlink for Certbot binary |
| 70 | + tags: setup |
| 71 | + ansible.builtin.file: |
| 72 | + src: /snap/bin/certbot |
| 73 | + dest: /usr/bin/certbot |
| 74 | + state: link |
| 75 | + become: true |
| 76 | +- name: Check if the certificate was already generated |
| 77 | + tags: generate_cert |
| 78 | + ansible.builtin.stat: |
| 79 | + path: ""/etc/letsencrypt/live/{{ domain }}/fullchain.pem"" |
| 80 | + register: cert_fullchain_file |
| 81 | +- name: Generate certificate manually |
| 82 | + tags: generate_cert |
| 83 | + ansible.builtin.command: |
| 84 | + cmd: ""certbot certonly --standalone --preferred-challenges http --agree-tos --email {{ email }} -d {{ domain }}"" |
| 85 | + creates: ""/etc/letsencrypt/live/{{ domain }}/fullchain.pem"" |
| 86 | + when: not cert_fullchain_file.stat.exists |
| 87 | +"; |
| 88 | + } |
| 89 | +} |
0 commit comments