/// <summary> /// This method asynchronously saves a POCO to a Docker Secret stored as a JSON string using a /// <code>DockerSecretName</code> attribute at the class level /// </summary> /// <param name="value"></param> /// <typeparam name="TValue"></typeparam> /// <returns></returns> public static Task SetAsync <TValue>(TValue value) { // Localize our type Type type = typeof(TValue); // Localize the key attribute DockerSecretNameAttribute keyAttribute = (type.GetCustomAttributes(typeof(DockerSecretNameAttribute), true).FirstOrDefault() as DockerSecretNameAttribute); // Make sure we have a key attribute if (keyAttribute == null) { throw new System.Exception($"{typeof(TValue).Name} Does Not Contain a DockerSecretName Attribute"); } // Set the value into Docker return(SetAsync <TValue>(keyAttribute.Name, value)); }
/// <summary> /// This method asynchronously loads a POCO from a Docker Secret stored as a JSON string using a /// <code>DockerSecretName</code> attribute at the class level /// </summary> /// <typeparam name="TValue"></typeparam> /// <returns></returns> public static async Task <TValue> GetAsync <TValue>() { // Load the value's type Type type = typeof(TValue); // Localize the key attribute DockerSecretNameAttribute keyAttribute = (type.GetCustomAttributes(typeof(DockerSecretNameAttribute), true).FirstOrDefault() as DockerSecretNameAttribute); // Make sure we have a key attribute if (keyAttribute == null) { throw new Exception($"{typeof(TValue).Name} Does Not Contain a DockerSecretName Attribute"); } // Load the value from the Docker Secret TValue value = await GetAsync <TValue>(keyAttribute.Name, keyAttribute.AllowEmpty); // We're done, return the value return(value); }