cambios variables de ambiente
This commit is contained in:
parent
222d5fdc08
commit
0d67a44d36
20 changed files with 261 additions and 297 deletions
|
@ -1,79 +0,0 @@
|
|||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
83
SHARED/Utils/ObtenerVariablesEntorno.cs
Normal file
83
SHARED/Utils/ObtenerVariablesEntorno.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Shared.DTO.VariablesEntorno;
|
||||
|
||||
namespace Shared.Utils
|
||||
{
|
||||
public static class ObtenerVariablesEntorno
|
||||
{
|
||||
public static Dictionary<string, string> GetVarEnviromentDict(string key)
|
||||
{
|
||||
string? variableEnv = Environment.GetEnvironmentVariable(key);
|
||||
if (string.IsNullOrWhiteSpace(variableEnv))
|
||||
throw new ArgumentException($"La variable de entorno '{key}' no está definida.");
|
||||
|
||||
var dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var data in variableEnv.Split(';', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
int div = data.IndexOf('=');
|
||||
if (div <= 0 || div >= data.Length - 1) continue; // Evita keys o values vacíos o sin '='
|
||||
|
||||
var keyValue = data[..div].Trim().ToUpperInvariant();
|
||||
var value = data[(div + 1)..].Trim();
|
||||
|
||||
if (!string.IsNullOrEmpty(keyValue) && !string.IsNullOrEmpty(value))
|
||||
dictionary[keyValue] = value;
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
public static void AmbientarCredencialesDGA(string env)
|
||||
{
|
||||
var dictEnv = GetVarEnviromentDict(env);
|
||||
|
||||
dictEnv.TryGetValue("RUTEMPRESA", out string? rutEmpresa);
|
||||
CredencialDGA.RutEmpresa = rutEmpresa ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("RUTUSUARIO", out string? rutUsuario);
|
||||
CredencialDGA.RutUsuario = rutUsuario ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("PASSWORD", out string? password);
|
||||
CredencialDGA.Password = password ?? string.Empty;
|
||||
}
|
||||
|
||||
public static void AmbientarConexionBd(string env)
|
||||
{
|
||||
BdConexion.StringConnection = Environment.GetEnvironmentVariable(env) ?? string.Empty;
|
||||
}
|
||||
|
||||
public static void AmbientarApiUrlNexus(string env)
|
||||
{
|
||||
var dictEnv = GetVarEnviromentDict(env);
|
||||
|
||||
dictEnv.TryGetValue("URL", out string? url);
|
||||
NexusApiUrl.ApiUrl = url ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("APIKEY", out string? apiKey);
|
||||
NexusApiUrl.ApiKey = apiKey ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("VERSION", out string? version);
|
||||
NexusApiUrl.Version = version ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("DATASOURCE", out string? dataSource);
|
||||
NexusApiUrl.DataSource = dataSource ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("RESOLUTION", out string? resolution);
|
||||
NexusApiUrl.Resolution = resolution ?? string.Empty;
|
||||
}
|
||||
|
||||
public static void AmbientarUrlApiSubterranea(string env)
|
||||
{
|
||||
var dictEnv = GetVarEnviromentDict(env);
|
||||
|
||||
dictEnv.TryGetValue("URL", out string? url);
|
||||
SubterraneaApiUrl.BaseUrl = url ?? string.Empty;
|
||||
|
||||
dictEnv.TryGetValue("ENDPOINT", out string? endpoint);
|
||||
SubterraneaApiUrl.EndPoint = endpoint ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
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; }
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
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; }
|
||||
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
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; }
|
||||
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
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