-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discovery service based on proto endpoint #30
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
60c29ad
Add small fixes to gen-proto-code
calvellido a819d9d
Add fetch-proto script
calvellido 31bedf3
Use google-protobuf JS runtime
calvellido 0a188ff
Fix error message on gen-proto-code script
calvellido d1c1ff0
Add JS generated classes from proto descriptors
calvellido bd0c4f5
Add microservices discovery service
calvellido 9f55379
Remove invalid test assignation
calvellido 59ef685
Remove some leftover comments
calvellido File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#! /usr/bin/env node | ||
const package = require('../package.json'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const { URL } = require('url'); | ||
const axios = require('axios'); | ||
const yargs = require('yargs'); | ||
const shell = require('shelljs'); | ||
const ora = require('ora'); | ||
|
||
// Set the directory from where we will be working | ||
const workingDir = path.join(__dirname, '..'); | ||
|
||
// Default URL path from where proto file will fetched (could be changed by params) | ||
let originProtoPath = 'http://localhost:8080/proto/models/microservices'; | ||
// Fetched proto file destination (could be changed by params) | ||
let destProtoPath = path.join(workingDir, 'proto'); | ||
|
||
// Reading params | ||
const argv = yargs | ||
.usage('fetch-proto\n\nUsage: $0 [options]') | ||
.help('help').alias('help', 'h') | ||
.version(package.version).alias('version', 'v') | ||
.options({ | ||
source: { | ||
alias: ['s'], | ||
description: '<proto-file-source-url>', | ||
requiresArg: true, | ||
default: originProtoPath, | ||
string: true, | ||
coerce: arg => { | ||
try { | ||
const urlObject = new URL(arg); | ||
return urlObject; | ||
} catch (e) { | ||
// throw new Error(`Error: ${arg} is not a valid URL path`); | ||
throw e; | ||
} | ||
} | ||
}, | ||
output: { | ||
alias: 'o', | ||
description: '<output-destination-path>', | ||
requiresArg: true, | ||
default: destProtoPath, | ||
string: true, | ||
normalize: true, | ||
coerce: arg => { | ||
if (fs.existsSync(arg)) { | ||
return arg; | ||
} | ||
else { | ||
throw new Error(`Error: ${arg} is not a valid directory path`); | ||
} | ||
} | ||
} | ||
}) | ||
.fail((msg, err, yargs) => { | ||
shell.echo(msg); | ||
process.exit(1); | ||
}) | ||
.wrap(Math.min(120, yargs.terminalWidth())) | ||
.argv; | ||
|
||
originProtoPath = new URL(argv.source); | ||
destProtoPath = argv.output; | ||
|
||
|
||
function fetchProto () { | ||
const spinner = new ora({ | ||
spinner: 'dots3', | ||
interval: 60, | ||
color: 'magenta', | ||
text: `${originProtoPath} fetching...` | ||
}).start(); | ||
// GET request for remote proto | ||
return axios({ | ||
method: 'GET', | ||
url: originProtoPath.href, | ||
headers: { 'Accept': 'text/plain'}, | ||
responseType: 'text', | ||
timeout: 5000 | ||
}) | ||
.then((response) => { | ||
const protoFilename = `${originProtoPath.pathname.match(/([^\/]*)\/*$/)[1]}.proto`; | ||
fs.writeFileSync(path.join(destProtoPath, `${protoFilename}`), response.data); | ||
const successMessage = `${protoFilename} fetched`; | ||
spinner.succeed(successMessage); | ||
return successMessage; | ||
}) | ||
.catch((error) => { | ||
spinner.fail(`Error connecting to: ${error.config.url}`); | ||
// shell.echo(`Error connecting to: ${error.config.url}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adressed on 59ef685 |
||
if (error.response) { | ||
// The request was made and the server responded with a status code out of range 2xx | ||
shell.echo(`${error.response.status} - ${error.response.statusText}`); | ||
shell.echo(error.response.data); | ||
} | ||
else if (error.request) { | ||
// The request was made but no response was received | ||
// `error.request` is an instance of http.ClientRequest | ||
shell.echo(`Destination can’t be reached`); | ||
} | ||
else { | ||
// Something happened in setting up the request that triggered an Error | ||
shell.echo(error.message); | ||
} | ||
throw error; | ||
}); | ||
} | ||
|
||
try { | ||
fetchProto(); | ||
} catch (e) {} | ||
|
||
module.exports.fetchProto = fetchProto; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adressed on 59ef685