// Path: src/main/java/com/xti/jenkins/plugin/awslambda/AWSLambdaDescriptor.java
// public abstract class AWSLambdaDescriptor<T extends Describable<T>> extends Descriptor<T> {
// 
//     //awsAccessKeyId field
//     public FormValidation doCheckAwsAccessKeyId(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Access Key Id.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //awsSecretKey field
//     public FormValidation doCheckAwsSecretKey(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Secret Id.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //awsRegion field
//     public FormValidation doCheckAwsRegion(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Region.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //functionName field
//     public FormValidation doCheckFunctionName(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Lambda function name.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //functionARN field
//     public FormValidation doCheckFunctionARN(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Lambda function ARN.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //functionAlias field
//     public FormValidation doCheckFunctionAlias(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Lambda alias name.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// }
// 
// Path: src/main/java/com/xti/jenkins/plugin/awslambda/util/JenkinsProxy.java
// public class JenkinsProxy {
//     public static ProxyConfiguration getConfig(){
//         Jenkins instance = Jenkins.getInstance();
// 
//         if (instance != null) {
//             return instance.proxy;
//         } else {
//             return null;
//         }
//     }
// }
// 
// Path: src/main/java/com/xti/jenkins/plugin/awslambda/util/LambdaClientConfig.java
// public class LambdaClientConfig implements Serializable {
//     private String region;
//     private String accessKeyId;
//     private String secretKey;
//     private Boolean useDefaultAWSCredentials;
//     private ProxyConfiguration proxyConfiguration;
// 
//     public LambdaClientConfig(String region, ProxyConfiguration proxyConfiguration){
//         this.region = region;
//         this.useDefaultAWSCredentials = true;
//         this.proxyConfiguration = proxyConfiguration;
//     }
// 
//     public LambdaClientConfig(String accessKeyId, String secretKey, String region, ProxyConfiguration proxyConfiguration) {
//         this.region = region;
//         this.accessKeyId = accessKeyId;
//         this.secretKey = secretKey;
//         this.useDefaultAWSCredentials = false;
//         this.proxyConfiguration = proxyConfiguration;
//     }
// 
//     public AWSLambdaClient getClient() {
//         if(useDefaultAWSCredentials){
//             return new AWSLambdaClient(new DefaultAWSCredentialsProviderChain(), getClientConfiguration())
//                     .withRegion(Region.getRegion(Regions.fromName(region)));
//         } else {
//             return new AWSLambdaClient(new BasicAWSCredentials(accessKeyId, secretKey), getClientConfiguration())
//                     .withRegion(Region.getRegion(Regions.fromName(region)));
//         }
//     }
// 
//     private ClientConfiguration getClientConfiguration() {
//         /*
//         Jenkins instance = Jenkins.getInstance();
// 
//         if (instance != null) {
//             ProxyConfiguration proxy = instance.proxy;
//         */
//         ClientConfiguration config = new ClientConfiguration();
// 
//         if (proxyConfiguration != null) {
//             config.setProxyHost(proxyConfiguration.name);
//             config.setProxyPort(proxyConfiguration.port);
//             if (proxyConfiguration.getUserName() != null) {
//                 config.setProxyUsername(proxyConfiguration.getUserName());
//                 config.setProxyPassword(proxyConfiguration.getPassword());
//             }
//             if (proxyConfiguration.noProxyHost != null) {
//                 config.setNonProxyHosts(proxyConfiguration.noProxyHost);
//             }
//         }
// 
//         return config;
// 
//     }
// }


import com.xti.jenkins.plugin.awslambda.AWSLambdaDescriptor;
import com.xti.jenkins.plugin.awslambda.util.ExpansionUtils;
import com.xti.jenkins.plugin.awslambda.util.JenkinsProxy;
import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig;
import hudson.EnvVars;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.util.Secret;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
    }

    public String getEventSourceArn() {
        return eventSourceArn;
    }

    public boolean getSuccessOnly() {
        return successOnly;
    }

    @DataBoundSetter
    public void setSuccessOnly(boolean successOnly) {
        this.successOnly = successOnly;
    }

    public void expandVariables(EnvVars env) {
        awsAccessKeyId = ExpansionUtils.expand(awsAccessKeyId, env);
        clearTextAwsSecretKey = ExpansionUtils.expand(Secret.toString(Secret.fromString(awsSecretKey)), env);
        awsRegion = ExpansionUtils.expand(awsRegion, env);
        functionName = ExpansionUtils.expand(functionName, env);
        functionAlias = ExpansionUtils.expand(functionAlias, env);
        eventSourceArn = ExpansionUtils.expand(eventSourceArn, env);
    }

    public EventSourceConfig getEventSourceConfig() {
        return new EventSourceConfig(functionName, functionAlias, eventSourceArn);
    }

    public LambdaClientConfig getLambdaClientConfig(){
        if(useInstanceCredentials){
// Path: src/main/java/com/xti/jenkins/plugin/awslambda/AWSLambdaDescriptor.java
// public abstract class AWSLambdaDescriptor<T extends Describable<T>> extends Descriptor<T> {
// 
//     //awsAccessKeyId field
//     public FormValidation doCheckAwsAccessKeyId(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Access Key Id.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //awsSecretKey field
//     public FormValidation doCheckAwsSecretKey(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Secret Id.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //awsRegion field
//     public FormValidation doCheckAwsRegion(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Region.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //functionName field
//     public FormValidation doCheckFunctionName(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Lambda function name.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //functionARN field
//     public FormValidation doCheckFunctionARN(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Lambda function ARN.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// 
//     //functionAlias field
//     public FormValidation doCheckFunctionAlias(@QueryParameter String value) {
//         if(StringUtils.isEmpty(value)){
//             return FormValidation.error("Please fill in AWS Lambda alias name.");
//         } else {
//             return FormValidation.ok();
//         }
//     }
// }
// 
// Path: src/main/java/com/xti/jenkins/plugin/awslambda/util/JenkinsProxy.java
// public class JenkinsProxy {
//     public static ProxyConfiguration getConfig(){
//         Jenkins instance = Jenkins.getInstance();
// 
//         if (instance != null) {
//             return instance.proxy;
//         } else {
//             return null;
//         }
//     }
// }
// 
// Path: src/main/java/com/xti/jenkins/plugin/awslambda/util/LambdaClientConfig.java
// public class LambdaClientConfig implements Serializable {
//     private String region;
//     private String accessKeyId;
//     private String secretKey;
//     private Boolean useDefaultAWSCredentials;
//     private ProxyConfiguration proxyConfiguration;
// 
//     public LambdaClientConfig(String region, ProxyConfiguration proxyConfiguration){
//         this.region = region;
//         this.useDefaultAWSCredentials = true;
//         this.proxyConfiguration = proxyConfiguration;
//     }
// 
//     public LambdaClientConfig(String accessKeyId, String secretKey, String region, ProxyConfiguration proxyConfiguration) {
//         this.region = region;
//         this.accessKeyId = accessKeyId;
//         this.secretKey = secretKey;
//         this.useDefaultAWSCredentials = false;
//         this.proxyConfiguration = proxyConfiguration;
//     }
// 
//     public AWSLambdaClient getClient() {
//         if(useDefaultAWSCredentials){
//             return new AWSLambdaClient(new DefaultAWSCredentialsProviderChain(), getClientConfiguration())
//                     .withRegion(Region.getRegion(Regions.fromName(region)));
//         } else {
//             return new AWSLambdaClient(new BasicAWSCredentials(accessKeyId, secretKey), getClientConfiguration())
//                     .withRegion(Region.getRegion(Regions.fromName(region)));
//         }
//     }
// 
//     private ClientConfiguration getClientConfiguration() {
//         /*
//         Jenkins instance = Jenkins.getInstance();
// 
//         if (instance != null) {
//             ProxyConfiguration proxy = instance.proxy;
//         */
//         ClientConfiguration config = new ClientConfiguration();
// 
//         if (proxyConfiguration != null) {
//             config.setProxyHost(proxyConfiguration.name);
//             config.setProxyPort(proxyConfiguration.port);
//             if (proxyConfiguration.getUserName() != null) {
//                 config.setProxyUsername(proxyConfiguration.getUserName());
//                 config.setProxyPassword(proxyConfiguration.getPassword());
//             }
//             if (proxyConfiguration.noProxyHost != null) {
//                 config.setNonProxyHosts(proxyConfiguration.noProxyHost);
//             }
//         }
// 
//         return config;
// 
//     }
// }


// Path: src/main/java/com/xti/jenkins/plugin/awslambda/eventsource/LambdaEventSourceVariables.java
import com.xti.jenkins.plugin.awslambda.AWSLambdaDescriptor;
import com.xti.jenkins.plugin.awslambda.util.ExpansionUtils;
import com.xti.jenkins.plugin.awslambda.util.JenkinsProxy;
import com.xti.jenkins.plugin.awslambda.util.LambdaClientConfig;
import hudson.EnvVars;
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.util.Secret;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

    }

    public String getEventSourceArn() {
        return eventSourceArn;
    }

    public boolean getSuccessOnly() {
        return successOnly;
    }

    @DataBoundSetter
    public void setSuccessOnly(boolean successOnly) {
        this.successOnly = successOnly;
    }

    public void expandVariables(EnvVars env) {
        awsAccessKeyId = ExpansionUtils.expand(awsAccessKeyId, env);
        clearTextAwsSecretKey = ExpansionUtils.expand(Secret.toString(Secret.fromString(awsSecretKey)), env);
        awsRegion = ExpansionUtils.expand(awsRegion, env);
        functionName = ExpansionUtils.expand(functionName, env);
        functionAlias = ExpansionUtils.expand(functionAlias, env);
        eventSourceArn = ExpansionUtils.expand(eventSourceArn, env);
    }

    public EventSourceConfig getEventSourceConfig() {
        return new EventSourceConfig(functionName, functionAlias, eventSourceArn);
    }

    public LambdaClientConfig getLambdaClientConfig(){
        if(useInstanceCredentials){
            return new LambdaClientConfig(awsRegion, JenkinsProxy.getConfig());