// ĠCopyright Ġ 2 0 1 9 ĠAmazon . com , ĠInc . Ġor Ġits Ġaffiliates . ĠAll ĠRights ĠReserved . Ċ // ĠSPDX - License - Identifier : ĠApache - 2 . 0 Ċ Ċ package Ġsoftware . aws . tool k its . jetbrains . core . credentials Ċ Ċ import Ġcom . intellij . openapi . components . Service Manager Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġsoftware . amazon . aw ssdk . auth . credentials . Aws Basic Credentials Ċ import Ġsoftware . amazon . aw ssdk . auth . credentials . Aws Credentials Ċ import Ġsoftware . amazon . aw ssdk . auth . credentials . Default Credentials Provider Ċ import Ġsoftware . aws . tool k its . core . credentials . Credential Provider NotFound Ċ import Ġsoftware . aws . tool k its . core . credentials . Toolkit Credentials Provider Ċ import Ġsoftware . aws . tool k its . core . region . Aws Region Ċ import Ġsoftware . aws . tool k its . jetbrains . core . credentials . Mock Project Account Settings Manager . Companion . create Dummy Provider Ċ import Ġsoftware . aws . tool k its . jetbrains . core . region . Aws Region Provider Ċ Ċ class ĠMock Project Account Settings Manager Ġ: ĠProject Account Settings Manager Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġinternal Provider : ĠToolkit Credentials Provider ? Ġ= ĠD UMMY _ PROVIDER ĊĠĠĠ Ġprivate Ġval Ġrecently Used Regions Ġ= Ġmutable ListOf < Aws Region >() ĊĠĠĠ Ġprivate Ġval Ġrecently Used Credentials Ġ= Ġmutable ListOf < Toolkit Credentials Provider >() ĊĊĠĠĠ Ġoverride Ġvar Ġactive Region Ġ= ĠAws Region Provider . getInstance (). default Region () ĊĊĠĠĠ Ġoverride Ġval Ġactive Credential Provider : ĠToolkit Credentials Provider ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġinternal Provider Ġ?: Ġthrow ĠCredential Provider NotFound (" boom ") ĊĊĠĠĠ Ġoverride Ġfun Ġrecently Used Regions (): ĠList < Aws Region > Ġ= Ġrecently Used Regions ĊĊĠĠĠ Ġoverride Ġfun Ġrecently Used Credentials (): ĠList < Toolkit Credentials Provider > Ġ= Ġrecently Used Credentials ĊĊĠĠĠ Ġoverride Ġfun Ġchange Credential Provider ( credentials Provider : ĠToolkit Credentials Provider ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġinternal Provider Ġ= Ġcredentials Provider ĊĠĠĠĠĠĠĠ Ġcredentials Provider ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrecently Used Credentials . add ( credentials Provider ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġchange Region ( region : ĠAws Region ) Ġ{ ĊĠĠĠĠĠĠĠ Ġactive Region Ġ= Ġregion ĊĠĠĠĠĠĠĠ Ġrecently Used Regions . add ( region ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġreset () Ġ{ ĊĠĠĠĠĠĠĠ Ġinternal Provider Ġ= ĠD UMMY _ PROVIDER ĊĠĠĠĠĠĠĠ Ġactive Region Ġ= ĠAws Region Provider . getInstance (). default Region () ĊĠĠĠĠĠĠĠ Ġrecently Used Regions . clear () ĊĠĠĠĠĠĠĠ Ġrecently Used Credentials . clear () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġval ĠD UMMY _ PROVIDER Ġ= Ġcreate Dummy Provider ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" Mock Credentials ", ĊĠĠĠĠĠĠĠĠĠĠĠ ĠAws Basic Credentials . create (" Foo ", Ġ" Bar ") ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġfun Ġcreate Dummy Provider ( id : ĠString , Ġaws Credentials : ĠAws Credentials ) Ġ= Ġobject Ġ: ĠToolkit Credentials Provider () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġval Ġid Ġ= Ġid ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġval ĠdisplayName Ġ= Ġid ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġresolve Credentials (): ĠAws Credentials Ġ= Ġaws Credentials ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġfun ĠgetInstance ( project : ĠProject ): ĠMock Project Account Settings Manager Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠService Manager . getService ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġproject , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠProject Account Settings Manager :: class . java ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) Ġas ĠMock Project Account Settings Manager ĊĠĠĠ Ġ} Ċ } Ċ Ċ fun Ġ< T > Ġrun Under Real Credentials ( project : ĠProject , Ġblock : Ġ() Ġ-> ĠT ): ĠT Ġ{ ĊĠĠĠ Ġval Ġcredentials Ġ= ĠDefault Credentials Provider . create (). resolve Credentials () ĊĠĠĠ Ġval Ġmanager Ġ= ĠMock Project Account Settings Manager . getInstance ( project ) ĊĠĠĠ Ġval Ġold Active Ġ= Ġmanager . active Credential Provider ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġprintln (" Running Ġusing Ġreal Ġcredentials ") ĊĠĠĠĠĠĠĠ Ġmanager . change Credential Provider ( create Dummy Provider (" Real Cred s ", Ġcredentials )) ĊĠĠĠĠĠĠĠ Ġreturn Ġblock . invoke () ĊĠĠĠ Ġ} Ġfinally Ġ{ ĊĠĠĠĠĠĠĠ Ġmanager . change Credential Provider ( old Active ) ĊĠĠĠ Ġ} Ċ } Ċ