ApplicationInformation.cs 2.26 KB
Newer Older
Benedikt Heinrichs's avatar
Benedikt Heinrichs committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Net;

namespace Coscine.Api.Project
{
    public class ApplicationInformation
    {
        public string AppName { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
        public string AppType { get; set; } = "apis";
        public Version Version { get; set; } = ToSemanticVersion(System.Reflection.Assembly.GetEntryAssembly().GetName().Version);
        public string DomainName { get; set; } = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
        public string HostName { get; set; } = Dns.GetHostName();
        public string PathPrefix { get; set; } = $"coscine/api/{System.Reflection.Assembly.GetExecutingAssembly().GetName().Name}";
        public Tuple<int, int> PortRange = new Tuple<int, int>(6001, 6999);
        public int Port { get; set; } = 0;
        public string AppBasePath { get { return $"coscine/{AppType}/{AppName}"; } }
        public string TraefikBackendPath { get { return $"traefik/backends/{AppName}/servers/{HostName}"; } }
        public string TraefikFrontendPath { get { return $"traefik/frontends/{AppName}"; } }
        public Dictionary<string, string> AppValues
        {
            get
            {
                return new Dictionary<string, string>()
                {
                    { $"{AppBasePath}/port", $"{Port}" },
                    { $"{AppBasePath}/name", $"{AppName}" },
                    { $"{AppBasePath}/version", $"{Version}" }
                };
            }
        }
        public Dictionary<string, string> TraefikValues
        {
            get
            {
                return new Dictionary<string, string>()
                {
                    { $"{TraefikBackendPath}/url", $"http://{HostName}.{DomainName}:{Port}"},
                    { $"{TraefikBackendPath}/weight", $"{1}"},
                    { $"{TraefikFrontendPath}/backend", AppName},
                    { $"{TraefikFrontendPath}/routes/{AppName}/rule", $"Host:{HostName}.{DomainName};PathPrefix:/{PathPrefix}"}
                };
            }
        }

        private static Version ToSemanticVersion(Version version)
        {
            return new Version(version.Major, version.Minor, version.Build);
        }
    }
}