// Path: src/main/java/org/jenkinsci/plugins/docker/commons/credentials/KeyMaterial.java
// public abstract class KeyMaterial implements Closeable, Serializable {
// 
//     /**
//      * Standardize serialization
//      */
//     private static final long serialVersionUID = 1L;
//     
//     /**
//      * {@link KeyMaterial} that does nothing.
//      */
//     public static final KeyMaterial NULL = new NullKeyMaterial();
// 
//     /**
//      * The environment variables
//      */
//     private final EnvVars envVars;
// 
//     protected KeyMaterial(EnvVars envVars) {
//         this.envVars = envVars;
//     }
// 
//     /**
//      * Get the environment variables needed to be passed when docker runs, to access
//      * {@link DockerServerCredentials} that this object was created from.
//      */
//     public EnvVars env() {
//         return envVars;
//     }
// 
//     /**
//      * Deletes the key materials from the file system. As key materials are copied into files
//      * every time {@link KeyMaterialFactory} is created, it must be also cleaned up each time. 
//      */
//     public abstract void close() throws IOException;
//     
//     private static final class NullKeyMaterial extends KeyMaterial implements Serializable {
//         private static final long serialVersionUID = 1L;
//         protected NullKeyMaterial() {
//             super(new EnvVars());
//         }
//         @Override
//         public void close() throws IOException {            
//         }
//         private Object readResolve() {
//             return NULL;
//         }
//     }
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/docker/commons/credentials/KeyMaterialFactory.java
// public abstract class KeyMaterialFactory {
// 
//     public static final KeyMaterialFactory NULL = new NullKeyMaterialFactory();
//     
//     private /* write once */ KeyMaterialContext context;
//     
//     protected synchronized void checkContextualized() {
//         if (context == null) {
//             throw new IllegalStateException("KeyMaterialFactories must be contextualized before use");
//         }
//     }
// 
//     /**
//      * Sets the {@link KeyMaterialContext} within which this {@link KeyMaterialFactory} can {@link #materialize()}
//      * {@link KeyMaterial} instances. Can only be called once. 
//      * @param context the {@link KeyMaterialContext}.
//      * @return must return {@code this} (which is only returned to simplify use via method chaining)
//      */
//     public synchronized KeyMaterialFactory contextualize(@Nonnull KeyMaterialContext context) {
//         if (this.context != null) {
//             throw new IllegalStateException("KeyMaterialFactories cannot be re-contextualized");
//         }
//         this.context = context;
//         return this;
//     }
// 
//     @Nonnull
//     protected synchronized KeyMaterialContext getContext() {
//         checkContextualized();
//         return context;
//     }
// 
//     /**
//      * Builds the key material environment variables needed to be passed when docker runs, to access
//      * {@link DockerServerCredentials} that this object was created from.
//      * 
//      * <p>
//      * When you are done using the credentials, call {@link KeyMaterial#close()} to allow sensitive 
//      * information to be removed from the disk.
//      */
//     public abstract KeyMaterial materialize() throws IOException, InterruptedException;
// 
//     /**
//      * Creates a read-protected directory inside {@link KeyMaterialContext#getBaseDir} suitable for storing secret files.
//      * Be sure to {@link FilePath#deleteRecursive} this in {@link KeyMaterial#close}.
//      */
//     protected final FilePath createSecretsDirectory() throws IOException, InterruptedException {
//         FilePath dir = new FilePath(getContext().getBaseDir(), UUID.randomUUID().toString());
//         dir.mkdirs();
//         dir.chmod(0700);
//         return dir;
//     }
// 
//     /**
//      * Merge additional {@link KeyMaterialFactory}s into one.
//      */
//     public KeyMaterialFactory plus(@Nullable KeyMaterialFactory... factories) {
//         if (factories == null || factories.length == 0) {
//             return this;
//         }
//         List<KeyMaterialFactory> tmp = new ArrayList<KeyMaterialFactory>(factories.length + 1);
//         tmp.add(this);
//         for (KeyMaterialFactory f: factories) {
//             if (f != null) tmp.add(f);
//         }
//         return new CompositeKeyMaterialFactory(tmp.toArray(new KeyMaterialFactory[tmp.size()]));
//     }
// 
// }


import java.io.IOException;
import hudson.EnvVars;
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterial;
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterialFactory;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import javax.annotation.Nonnull;
/*
 * The MIT License
 *
 * Copyright (c) 2015, CloudBees, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.jenkinsci.plugins.docker.commons.impl;



/**
 * A {@link KeyMaterial} that maintains information about the host.
 * 
 * @author Stephen Connolly
 */
@Restricted(NoExternalUse.class)
public class ServerHostKeyMaterialFactory extends KeyMaterialFactory{

    /**
     * The host.
     */
    @Nonnull
    private final String host;

    public ServerHostKeyMaterialFactory(@Nonnull String host) {
        this.host = host;
    }

    /** {@inheritDoc} */
    @Override
// Path: src/main/java/org/jenkinsci/plugins/docker/commons/credentials/KeyMaterial.java
// public abstract class KeyMaterial implements Closeable, Serializable {
// 
//     /**
//      * Standardize serialization
//      */
//     private static final long serialVersionUID = 1L;
//     
//     /**
//      * {@link KeyMaterial} that does nothing.
//      */
//     public static final KeyMaterial NULL = new NullKeyMaterial();
// 
//     /**
//      * The environment variables
//      */
//     private final EnvVars envVars;
// 
//     protected KeyMaterial(EnvVars envVars) {
//         this.envVars = envVars;
//     }
// 
//     /**
//      * Get the environment variables needed to be passed when docker runs, to access
//      * {@link DockerServerCredentials} that this object was created from.
//      */
//     public EnvVars env() {
//         return envVars;
//     }
// 
//     /**
//      * Deletes the key materials from the file system. As key materials are copied into files
//      * every time {@link KeyMaterialFactory} is created, it must be also cleaned up each time. 
//      */
//     public abstract void close() throws IOException;
//     
//     private static final class NullKeyMaterial extends KeyMaterial implements Serializable {
//         private static final long serialVersionUID = 1L;
//         protected NullKeyMaterial() {
//             super(new EnvVars());
//         }
//         @Override
//         public void close() throws IOException {            
//         }
//         private Object readResolve() {
//             return NULL;
//         }
//     }
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/docker/commons/credentials/KeyMaterialFactory.java
// public abstract class KeyMaterialFactory {
// 
//     public static final KeyMaterialFactory NULL = new NullKeyMaterialFactory();
//     
//     private /* write once */ KeyMaterialContext context;
//     
//     protected synchronized void checkContextualized() {
//         if (context == null) {
//             throw new IllegalStateException("KeyMaterialFactories must be contextualized before use");
//         }
//     }
// 
//     /**
//      * Sets the {@link KeyMaterialContext} within which this {@link KeyMaterialFactory} can {@link #materialize()}
//      * {@link KeyMaterial} instances. Can only be called once. 
//      * @param context the {@link KeyMaterialContext}.
//      * @return must return {@code this} (which is only returned to simplify use via method chaining)
//      */
//     public synchronized KeyMaterialFactory contextualize(@Nonnull KeyMaterialContext context) {
//         if (this.context != null) {
//             throw new IllegalStateException("KeyMaterialFactories cannot be re-contextualized");
//         }
//         this.context = context;
//         return this;
//     }
// 
//     @Nonnull
//     protected synchronized KeyMaterialContext getContext() {
//         checkContextualized();
//         return context;
//     }
// 
//     /**
//      * Builds the key material environment variables needed to be passed when docker runs, to access
//      * {@link DockerServerCredentials} that this object was created from.
//      * 
//      * <p>
//      * When you are done using the credentials, call {@link KeyMaterial#close()} to allow sensitive 
//      * information to be removed from the disk.
//      */
//     public abstract KeyMaterial materialize() throws IOException, InterruptedException;
// 
//     /**
//      * Creates a read-protected directory inside {@link KeyMaterialContext#getBaseDir} suitable for storing secret files.
//      * Be sure to {@link FilePath#deleteRecursive} this in {@link KeyMaterial#close}.
//      */
//     protected final FilePath createSecretsDirectory() throws IOException, InterruptedException {
//         FilePath dir = new FilePath(getContext().getBaseDir(), UUID.randomUUID().toString());
//         dir.mkdirs();
//         dir.chmod(0700);
//         return dir;
//     }
// 
//     /**
//      * Merge additional {@link KeyMaterialFactory}s into one.
//      */
//     public KeyMaterialFactory plus(@Nullable KeyMaterialFactory... factories) {
//         if (factories == null || factories.length == 0) {
//             return this;
//         }
//         List<KeyMaterialFactory> tmp = new ArrayList<KeyMaterialFactory>(factories.length + 1);
//         tmp.add(this);
//         for (KeyMaterialFactory f: factories) {
//             if (f != null) tmp.add(f);
//         }
//         return new CompositeKeyMaterialFactory(tmp.toArray(new KeyMaterialFactory[tmp.size()]));
//     }
// 
// }


// Path: src/main/java/org/jenkinsci/plugins/docker/commons/impl/ServerHostKeyMaterialFactory.java
import java.io.IOException;
import hudson.EnvVars;
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterial;
import org.jenkinsci.plugins.docker.commons.credentials.KeyMaterialFactory;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import javax.annotation.Nonnull;

/*
 * The MIT License
 *
 * Copyright (c) 2015, CloudBees, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package org.jenkinsci.plugins.docker.commons.impl;



/**
 * A {@link KeyMaterial} that maintains information about the host.
 * 
 * @author Stephen Connolly
 */
@Restricted(NoExternalUse.class)
public class ServerHostKeyMaterialFactory extends KeyMaterialFactory{

    /**
     * The host.
     */
    @Nonnull
    private final String host;

    public ServerHostKeyMaterialFactory(@Nonnull String host) {
        this.host = host;
    }

    /** {@inheritDoc} */
    @Override
    public KeyMaterial materialize() throws IOException, InterruptedException {