import { $q } from 'ngimport' ; import { REST } from '@spinnaker/core' ; export interface IAmazonImage { accounts : string [ ] ; amis : { [ region ] : string [ ] ; } ; attributes : { creationDate : string ; virtualizationType : string ; } ; imageName : string ; tags : { [ tag ] : string ; } ; tagsByImageId : { [ imageId ] : IAmazonImage [ 'tags' ] ; } ; } export class AwsImageReader { public findImages ( params ) { if ( ! params . q || params . q . length < 3 ) { return $q . when ( [ { message : 'Please enter at least 3 characters...' , disabled : true } ] ) as any ; } return REST ( '/images/find' ) . query ( params ) . get ( ) . catch ( ( ) => [ ] as IAmazonImage [ ] ) ; } public getImage ( amiName , region , credentials ) { return REST ( '/images' ) . path ( credentials , region , amiName ) . query ( { provider : 'aws' } ) . get ( ) . then ( ( results ) => ( results && results . length ? results [ 0 ] : null ) ) . catch ( ( ) => null as IAmazonImage ) ; } }