-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const _ = require('lodash'); | ||
const tunnel = require('tunnel-ssh'); | ||
|
||
module.exports = (api) => { | ||
return (options, callback) => { | ||
options = options || {}; | ||
|
||
if (!api.spaceGuid) { | ||
return callback(new Error('Please provide a space! \n' + JSON.stringify(options, null, 2))); | ||
} | ||
|
||
if (!options.appGuid && options.app && api.actualDeploymentConfig) { | ||
var a = _.find(api.actualDeploymentConfig.apps, { name: options.app }); | ||
if (a) { | ||
options.appGuid = a.guid; | ||
} | ||
} | ||
|
||
if (!options.appGuid) { | ||
return callback(new Error('Please provide an appGuid! \n' + JSON.stringify(options, null, 2))); | ||
} | ||
|
||
if (!options.destinationHost) { | ||
return callback(new Error('Please provide an destinationHost! \n' + JSON.stringify(options, null, 2))); | ||
} | ||
|
||
if (!options.destinationPort) { | ||
return callback(new Error('Please provide an destinationPort! \n' + JSON.stringify(options, null, 2))); | ||
} | ||
|
||
if (!api.targetInfo.app_ssh_endpoint) { | ||
return callback(new Error('No app_ssh_endpoint defined in targetInfo!')); | ||
} | ||
|
||
const sshEndpoint = api.targetInfo.app_ssh_endpoint.split(':'); | ||
const sshHost = sshEndpoint[0]; | ||
const sshPort = parseInt(sshEndpoint[1]); | ||
|
||
options.instance = options.instance || 0; | ||
|
||
api.getCode((err, code) => { | ||
if (err) return callback(err); | ||
|
||
const config = { | ||
username: `cf:${options.appGuid}/${options.instance}`, | ||
password: code, | ||
host: sshHost, | ||
port: sshPort, | ||
dstHost: options.destinationHost, | ||
dstPort: options.destinationPort, | ||
localPort: options.localPort | ||
}; | ||
|
||
tunnel(config, (err, tnl) => { | ||
if (err) return callback(err); | ||
callback(null, tnl); | ||
}); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const request = require('request'); | ||
const urlModule = require('url'); | ||
const debug = require('debug')('push2cloud-cf-adapter:getCode'); | ||
|
||
module.exports = (api) => { | ||
return (options, callback) => { | ||
if (!callback) { | ||
callback = options; | ||
options = {}; | ||
} | ||
options = options || {}; | ||
|
||
if (!api.targetInfo) { | ||
return callback(new Error('No taget information!')); | ||
} | ||
|
||
if (!api.token) { | ||
return callback(new Error('Please provide a token!')); | ||
} | ||
|
||
request({ | ||
method: 'GET', | ||
baseUrl: api.targetInfo.authorization_endpoint, | ||
uri: '/oauth/authorize', | ||
rejectUnauthorized: api.options.rejectUnauthorized, | ||
// json: true, | ||
headers: { | ||
Authorization: `${api.token.token_type} ${api.token.access_token}` | ||
}, | ||
qs: { | ||
response_type: 'code', | ||
grant_type: 'authorization_code', | ||
client_id: api.targetInfo.app_ssh_oauth_client | ||
}, | ||
followRedirect: false | ||
}, (err, response, result) => { | ||
if (err) return callback(err); | ||
|
||
if (!response || !response.headers || !response.headers.location) return callback(new Error('No code received!')); | ||
|
||
const code = urlModule.parse(response.headers.location).query.substring('code='.length); | ||
|
||
callback(null, code); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const _ = require('lodash'); | ||
|
||
module.exports = (api) => { | ||
return (options, callback) => { | ||
options = options || {}; | ||
|
||
if (!api.spaceGuid) { | ||
return callback(new Error('Please provide a space! \n' + JSON.stringify(options, null, 2))); | ||
} | ||
|
||
if (!options.appGuid && options.name && api.actualDeploymentConfig) { | ||
var a = _.find(api.actualDeploymentConfig.apps, { name: options.name }); | ||
if (a) { | ||
options.appGuid = a.guid; | ||
} | ||
} | ||
|
||
if (!options.appGuid) { | ||
return callback(new Error('Please provide an appGuid! \n' + JSON.stringify(options, null, 2))); | ||
} | ||
|
||
api.graceRequest({ | ||
method: 'GET', | ||
uri: `/v2/apps/${options.appGuid}/env` | ||
}, (err, response, result) => { | ||
if (err) return callback(err); | ||
callback(null, result); | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters