001/*
002 * Stallion Core: A Modern Web Framework
003 *
004 * Copyright (C) 2015 - 2016 Stallion Software LLC.
005 *
006 * This program is free software: you can redistribute it and/or modify it under the terms of the
007 * GNU General Public License as published by the Free Software Foundation, either version 2 of
008 * the License, or (at your option) any later version. This program is distributed in the hope that
009 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
011 * License for more details. You should have received a copy of the GNU General Public License
012 * along with this program.  If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
013 *
014 *
015 *
016 */
017
018package io.stallion.secrets;
019
020import java.io.File;
021import java.util.List;
022import java.util.Map;
023
024import static io.stallion.utils.Literals.*;
025
026import io.stallion.boot.CommandOptionsBase;
027import io.stallion.boot.StallionRunAction;
028import io.stallion.services.Log;
029import org.apache.commons.io.FileUtils;
030
031
032public class SecretsDecryptAction implements StallionRunAction<SecretsDecryptOptions> {
033    @Override
034    public String getActionName() {
035        return "secrets-decrypt";
036    }
037
038    @Override
039    public String getHelp() {
040        return "Decrypts the file conf/secrets.json.aes to conf/secrets.json";
041    }
042
043    @Override
044    public void loadApp(SecretsDecryptOptions options) {
045
046    }
047
048
049    @Override
050    public SecretsDecryptOptions newCommandOptions() {
051        return new SecretsDecryptOptions();
052    }
053
054    @Override
055    public void execute(SecretsDecryptOptions options) throws Exception {
056
057        SecretsCommandLineManager manager = new SecretsCommandLineManager();
058        SecretsVault vault = manager.loadVault(options.getTargetPath(), null, options.getPassphrase());
059        String secretsJson = vault.secretsToJson();
060        File file = new File(options.getTargetPath() + "/conf/secrets.json");
061        FileUtils.write(file, secretsJson, UTF8);
062
063
064    }
065
066
067}