/*
 * Copyright 2016 Netflix, 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.netflix.spinnaker.clouddriver.aws.security;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSSessionCredentials;
import com.amazonaws.auth.AWSSessionCredentialsProvider;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient;

public class NetflixSTSAssumeRoleSessionCredentialsProvider implements AWSSessionCredentialsProvider {
  private final STSAssumeRoleSessionCredentialsProvider delegate;
  private final String accountId;


  public NetflixSTSAssumeRoleSessionCredentialsProvider(AWSCredentialsProvider longLivedCredentialsProvider,
                                                        String roleArn,
                                                        String roleSessionName,
                                                        String accountId) {
    this.accountId = accountId;
    AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClient.builder().withCredentials(longLivedCredentialsProvider).build();
    delegate = new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName).withStsClient(stsClient).build();
  }

  public String getAccountId() {
    return accountId;
  }

  @Override
  public AWSSessionCredentials getCredentials() {
    return delegate.getCredentials();
  }

  @Override
  public void refresh() {
    delegate.refresh();
  }
}

@@ -727,297 +727,47 @@
 uth.
-AWSSessionCredentials;%0Aimport com.amazonaws.auth.AWSSessionCredentialsProvider;%0Aimport com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;%0Aimport com.amazonaws.services.securitytoken.AWSSecurityTokenService;%0Aimport com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient
+STSAssumeRoleSessionCredentialsProvider
 ;%0A%0Ap
@@ -829,66 +829,15 @@
 der 
-implements AWSSessionCredentialsProvider %7B%0A  private final
+extends
  STS
@@ -877,17 +877,9 @@
 der 
-delegate;
+%7B
 %0A  p
@@ -910,17 +910,16 @@
 untId;%0A%0A
-%0A
   public
@@ -1255,528 +1255,161 @@
     
-this.accountId = accountId;%0A    AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClient.builder().withCredentials(longLivedCredentialsProvider).build();%0A    delegate = new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName).withStsClient(stsClient).build();%0A  %7D%0A%0A  public String getAccountId() %7B%0A    return accountId;%0A  %7D%0A%0A  @Override%0A  public AWSSessionCredentials getCredentials() %7B%0A    return delegate.getCredentials();%0A  %7D%0A%0A  @Override%0A  public void refresh() %7B%0A    delegate.refresh()
+super(longLivedCredentialsProvider, roleArn, roleSessionName);%0A    this.accountId = accountId;%0A  %7D%0A%0A  public String getAccountId() %7B%0A    return accountId
 ;%0A  

Revert " fix(provider/aws): ensure STSAssumeRoleSessionCredentialsProvider get the right endpoint (#1888)" (#1904)