generated from Nekojimi/JavaMavenTemplate
Add object for storing API secrets.
This commit is contained in:
parent
d82b54ccf2
commit
ba9fde9cac
|
@ -0,0 +1,59 @@
|
||||||
|
package moe.nekojimi.musicsearcher;
|
||||||
|
|
||||||
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
|
import com.amihaiemil.eoyaml.YamlNode;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jim
|
||||||
|
*/
|
||||||
|
public class SecretStore
|
||||||
|
{
|
||||||
|
private static SecretStore secretStore;
|
||||||
|
|
||||||
|
public static SecretStore get()
|
||||||
|
{
|
||||||
|
if (secretStore == null)
|
||||||
|
secretStore = new SecretStore();
|
||||||
|
return secretStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String,String> secrets = new HashMap<>();
|
||||||
|
|
||||||
|
private SecretStore()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File file = new File("secrets.yml");
|
||||||
|
if (!file.exists())
|
||||||
|
{
|
||||||
|
System.out.println("WARNING: couldn't find secrets.yml. No API secrets available.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
YamlMapping yaml = Yaml.createYamlInput(file).readYamlMapping();
|
||||||
|
for (YamlNode key : yaml.keys())
|
||||||
|
secrets.put(key.asScalar().value(), yaml.string(key));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Logger.getLogger(SecretStore.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecret(String key)
|
||||||
|
{
|
||||||
|
return secrets.getOrDefault(key,"");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue