All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cloudbees.sdk.commands.config.ConfigParametersList Maven / Gradle / Ivy

/*
 * Copyright 2010-2013, CloudBees Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cloudbees.sdk.commands.config;


import com.cloudbees.api.BeesClient;
import com.cloudbees.api.ConfigurationParametersResponse;
import com.cloudbees.sdk.cli.BeesCommand;
import com.cloudbees.sdk.cli.CLICommand;
import com.cloudbees.sdk.commands.config.model.ConfigParameters;

import java.io.File;
import java.io.FileWriter;

/**
 * @author Fabian Donze
 */
@BeesCommand(group="Configuration")
@CLICommand("config:list")
public class ConfigParametersList extends ConfigParametersBase {
    private String file;

    public ConfigParametersList() {
    }

    public void setFile(String file) {
        this.file = file;
    }

    @Override
    protected boolean preParseCommandLine() {
        if (super.preParseCommandLine()) {
            addOption( "fi", "file", true, "Output file name" );
            return true;
        }
        return false;
    }

    @Override
    protected boolean execute() throws Exception {
        BeesClient client = getBeesClient(BeesClient.class);

        String resourceId;
        String resourceType;
        if (isGlobal("list")) {
            resourceId = getAccount();
            resourceType = "global";
        } else {
            resourceId = getAppId();
            resourceType = "application";
        }
        ConfigurationParametersResponse res = client.configurationParameters(resourceId, resourceType);

        if (res.getConfiguration() != null && file != null) {
            File xmlFile = new File(file);
            FileWriter fos = null;
            try {
                fos = new FileWriter(xmlFile);
                fos.write(res.getConfiguration());
            } finally {
                if (fos != null)
                    fos.close();
            }

        } else {
            if (res.getConfiguration() != null) {
                ConfigParameters configParameters = ConfigParameters.parse(res.getConfiguration());
                printConfigParameters(configParameters);
            }
        }
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy