feat: se centralizan las variables de entorno y utilidades, ademas de agregar entidades para poder hacer más legible el codigo
This commit is contained in:
parent
bffcdabc0a
commit
222d5fdc08
14 changed files with 203 additions and 59 deletions
79
SHARED/Utils/EnviromentUtils.cs
Normal file
79
SHARED/Utils/EnviromentUtils.cs
Normal file
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Shared.Utils.Variables_Entorno;
|
||||
|
||||
namespace Shared.Utils
|
||||
{
|
||||
public static class EnviromentUtils
|
||||
{
|
||||
public static Dictionary<string,string> GetVarEnviromentDict(string key)
|
||||
{
|
||||
string variableEnv = Environment.GetEnvironmentVariable(key);
|
||||
if (string.IsNullOrEmpty(variableEnv))
|
||||
{
|
||||
throw new ArgumentException($"La variable de entorno '{key}' no está definida.");
|
||||
}
|
||||
var dictionary = new Dictionary<string, string>();
|
||||
var pares = variableEnv.Split(';');
|
||||
|
||||
foreach (var data in pares)
|
||||
{
|
||||
if(data == null || data.Equals("")) { continue; }
|
||||
var div = data.IndexOf('=');
|
||||
var keyValue = data.Substring(0, div).ToUpper();
|
||||
var value = data.Substring(div+1);
|
||||
if (!string.IsNullOrEmpty(keyValue) && !string.IsNullOrEmpty(value))
|
||||
{
|
||||
dictionary.Add(keyValue, value);
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static Credenciales_DGA GetEnvCredencialesDGA(string env)
|
||||
{
|
||||
Dictionary<string,string> dictEnv = GetVarEnviromentDict(env);
|
||||
return new Credenciales_DGA
|
||||
{
|
||||
RutEmpresa = dictEnv.ContainsKey("RUTEMPRESA") ? dictEnv["RUTEMPRESA"] : string.Empty,
|
||||
RutUsuario = dictEnv.ContainsKey("RUTUSUARIO") ? dictEnv["RUTUSUARIO"] : string.Empty,
|
||||
Password = dictEnv.ContainsKey("PASSWORD") ? dictEnv["PASSWORD"] : string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
public static BD_Conexion GetEnvBDConexion(string env)
|
||||
{
|
||||
|
||||
return new BD_Conexion
|
||||
{
|
||||
stringConnection = Environment.GetEnvironmentVariable(env) ?? string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
public static NexusApiUrl GetEnvNexusApiUrl(string env)
|
||||
{
|
||||
Dictionary<string, string> dictEnv = GetVarEnviromentDict(env);
|
||||
return new NexusApiUrl
|
||||
{
|
||||
ApiUrl = dictEnv.ContainsKey("URL") ? dictEnv["URL"] : string.Empty,
|
||||
ApiKey = dictEnv.ContainsKey("APIKEY") ? dictEnv["APIKEY"] : string.Empty,
|
||||
Version = dictEnv.ContainsKey("VERSION") ? dictEnv["VERSION"] : string.Empty,
|
||||
DataSource = dictEnv.ContainsKey("DATASOURCE") ? dictEnv["DATASOURCE"] : string.Empty,
|
||||
Resolution = dictEnv.ContainsKey("RESOLUTION") ? dictEnv["RESOLUTION"] : string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
public static SubterraneaApiUrl GetEnvSubterraneaApiUrl(string env)
|
||||
{
|
||||
Dictionary<string, string> dictEnv = GetVarEnviromentDict(env);
|
||||
return new SubterraneaApiUrl
|
||||
{
|
||||
BaseUrl = dictEnv.ContainsKey("URL") ? dictEnv["URL"] : string.Empty,
|
||||
EndPoint = dictEnv.ContainsKey("ENDPOINT") ? dictEnv["ENDPOINT"] : string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
13
SHARED/Utils/Variables_Entorno/BD_Conexion.cs
Normal file
13
SHARED/Utils/Variables_Entorno/BD_Conexion.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.Utils.Variables_Entorno
|
||||
{
|
||||
public class BD_Conexion
|
||||
{
|
||||
public String stringConnection { get; set; }
|
||||
}
|
||||
}
|
16
SHARED/Utils/Variables_Entorno/Credenciales_DGA.cs
Normal file
16
SHARED/Utils/Variables_Entorno/Credenciales_DGA.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.Utils.Variables_Entorno
|
||||
{
|
||||
public class Credenciales_DGA
|
||||
{
|
||||
public String RutEmpresa { get; set; }
|
||||
public String RutUsuario { get; set; }
|
||||
public String Password { get; set; }
|
||||
|
||||
}
|
||||
}
|
18
SHARED/Utils/Variables_Entorno/NexusApiUrl.cs
Normal file
18
SHARED/Utils/Variables_Entorno/NexusApiUrl.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.Utils.Variables_Entorno
|
||||
{
|
||||
public class NexusApiUrl
|
||||
{
|
||||
public String ApiUrl { get; set; }
|
||||
public String ApiKey { get; set; }
|
||||
public String Version { get; set; }
|
||||
public String DataSource { get; set; }
|
||||
public String Resolution { get; set; }
|
||||
|
||||
}
|
||||
}
|
15
SHARED/Utils/Variables_Entorno/SubterraneaApiUrl.cs
Normal file
15
SHARED/Utils/Variables_Entorno/SubterraneaApiUrl.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Shared.Utils.Variables_Entorno
|
||||
{
|
||||
public class SubterraneaApiUrl
|
||||
{
|
||||
public string BaseUrl { get; set; }
|
||||
public string EndPoint { get; set; }
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue