@@ -18,10 +18,7 @@ const DIST_DIR = path.join(CLI_DIR, 'dist')
1818const PJSON = require ( path . join ( CLI_DIR , 'package.json' ) )
1919const NODE_VERSION = PJSON . oclif . update . node . version
2020const SHORT_VERSION = PJSON . version
21- const pathToDist = path . join (
22- DIST_DIR ,
23- `cg-v${ SHORT_VERSION } `
24- )
21+ const pathToDist = path . join ( DIST_DIR , `cg-v${ SHORT_VERSION } ` )
2522async function getText ( url ) {
2623 return new Promise ( ( resolve , reject ) => {
2724 https
@@ -70,45 +67,74 @@ async function uploadToS3(file) {
7067 console . log ( `Uploading ${ file } to S3` )
7168 await new Promise ( ( resolve , reject ) => {
7269 const pathToFile = path . join ( pathToDist , file )
73- const fileStream = fs . createReadStream ( pathToFile ) ;
74- fileStream . on ( 'error' , ( err ) => {
75- if ( err ) {
70+ const fileStream = fs . createReadStream ( pathToFile )
71+ fileStream . on ( 'error' , err => {
72+ if ( err ) {
7673 reject ( err )
7774 throw err
7875 }
79- } ) ;
76+ } )
8077 fileStream . on ( 'open' , ( ) => {
8178 const credentials = new AWS . SharedIniFileCredentials ( {
8279 profile : 'autocloud-iac' ,
83- callback : ( err ) => {
80+ callback : err => {
8481 if ( err ) {
8582 console . log ( 'No credentials found for profile autocloud-iac' )
8683 console . log ( err )
8784 }
8885 } ,
8986 } )
90- console . log ( credentials )
91- const S3 = new AWS . S3 ( { credentials : AWS . config . credentials } )
92- S3 . putObject ( {
93- Bucket : PJSON . oclif . update . s3 . bucket ,
94- Key : `cg-v${ SHORT_VERSION } /${ file } ` ,
95- Body : fileStream ,
96- ServerSideEncryption : "AES256" ,
97- ACL : "bucket-owner-full-control"
98- } , ( err ) => {
99- if ( err ) {
100- reject ( err )
101- throw err
87+ sts = new AWS . STS ( )
88+ const { roleArn } = credentials
89+ const options = {
90+ RoleSessionName : 'CloudGraph-IAC' ,
91+ RoleArn : roleArn ,
92+ }
93+ console . log ( options )
94+ sts . assumeRole ( options , ( err , data ) => {
95+ if ( err ) {
96+ console . log ( `No valid credentials found for roleARN: ${ roleArn } ` )
97+ console . log ( err )
98+ resolve ( )
99+ } else {
100+ // successful response
101+ console . log ( 'successfully got access keys from role' )
102+ const {
103+ AccessKeyId : accessKeyId ,
104+ SecretAccessKey : secretAccessKey ,
105+ SessionToken : sessionToken ,
106+ } = data . Credentials
107+ const creds = {
108+ accessKeyId,
109+ secretAccessKey,
110+ sessionToken,
111+ }
112+ const S3 = new AWS . S3 ( { credentials : creds } )
113+ S3 . putObject (
114+ {
115+ Bucket : PJSON . oclif . update . s3 . bucket ,
116+ Key : `cg-v${ SHORT_VERSION } /${ file } ` ,
117+ Body : fileStream ,
118+ ServerSideEncryption : 'AES256' ,
119+ ACL : 'bucket-owner-full-control' ,
120+ } ,
121+ err => {
122+ if ( err ) {
123+ reject ( err )
124+ throw err
125+ }
126+ }
127+ )
128+ resolve ( )
102129 }
103- } ) ;
104- resolve ( )
130+ } )
105131 } )
106132 } )
107133}
108134
109135function getFilesByOS ( os ) {
110136 const files = fs . readdirSync ( pathToDist )
111- return files . filter ( ( file ) => file . includes ( os ) && ! file . includes ( '.xz' ) )
137+ return files . filter ( file => file . includes ( os ) && ! file . includes ( '.xz' ) )
112138}
113139
114140const ROOT = path . join ( __dirname , '..' )
@@ -122,7 +148,7 @@ async function updateCgFormula(brewDir) {
122148 const template = fs . readFileSync ( templatePath ) . toString ( 'utf-8' )
123149 const files = getFilesByOS ( 'darwin-x64' )
124150 console . log ( files )
125- const zipFile = files . find ( ( file ) => file . includes ( 'tar.gz' ) )
151+ const zipFile = files . find ( file => file . includes ( 'tar.gz' ) )
126152 const pathToFile = path . join ( pathToDist , zipFile )
127153 const sha256 = calculateSHA256 ( pathToFile )
128154 const url = `${ CLI_ASSETS_URL } /cg-v${ SHORT_VERSION } /${ zipFile } `
@@ -134,7 +160,7 @@ async function updateCgFormula(brewDir) {
134160
135161 fs . writeFileSync ( path . join ( brewDir , 'cg.rb' ) , templateReplaced )
136162 if ( process . env . WRITE_TO_S3 === undefined ) {
137- files . forEach ( async ( file ) => {
163+ files . forEach ( async file => {
138164 await uploadToS3 ( file )
139165 } )
140166 }
@@ -176,7 +202,9 @@ async function updateHomebrew() {
176202
177203 // await setupGit()
178204
179- console . log ( `cloning https://github.com/cloudgraphdev/homebrew-tap to ${ homebrewDir } ` )
205+ console . log (
206+ `cloning https://github.com/cloudgraphdev/homebrew-tap to ${ homebrewDir } `
207+ )
180208 await execa ( 'git' , [
181209 'clone' ,
182210 'git@github.com:cloudgraphdev/homebrew-tap.git' ,
0 commit comments