YUKI Hiroshi
null+****@clear*****
Wed Dec 5 12:58:28 JST 2012
YUKI Hiroshi 2012-12-05 12:58:28 +0900 (Wed, 05 Dec 2012) New Revision: fa07d4a6c01dce62b56d99713881a2f8d1d53c2b https://github.com/groonga/gcs/commit/fa07d4a6c01dce62b56d99713881a2f8d1d53c2b Log: Implement methods to convert arn to endpoint for Client Modified files: bin/gcs-describe-domain lib/client.js Modified: bin/gcs-describe-domain (+2 -23) =================================================================== --- bin/gcs-describe-domain 2012-12-05 12:49:17 +0900 (b608a39) +++ bin/gcs-describe-domain 2012-12-05 12:58:28 +0900 (8eacffd) @@ -16,35 +16,14 @@ commandLine var client = new Client(commandLine); -function toValidHostAndPort(hostAndPort) { - hostAndPort = hostAndPort.split(':'); - if (hostAndPort[0] == 'localhost') - hostAndPort[0] = '127.0.0.1'; - if (hostAndPort[0].match(/^\d+\.\d+\.\d+\.\d+$/)) - hostAndPort[0] += '.xip.io'; - return hostAndPort.join(':'); -} - -function arnToEndpoint(arn) { - var match = arn.match(/^arn:aws:cs:[^:]+:([^:]+):([^\/]+)\/(.+)$/); - if (!match) - client.raiseFatalError('invalid arn: ' + arn); - - var id = match[1]; - var type = match[2]; - var name = match[3]; - var hostAndPort = client.host + ':' + client.port; - return type + '-' + name + '-' + id + '.' + toValidHostAndPort(hostAndPort); -} - function reportStatus(domain, indexFields, defaultSearchField) { console.log('=== Domain Summary ==='); console.log('Domain Name: %s', domain.DomainName); console.log('Document Service endpoint: %s', - arnToEndpoint(domain.DocService.Arn, 'doc')); + client.arnToEndpoint(domain.DocService.Arn)); console.log('Search Service endpoint: %s', - arnToEndpoint(domain.SearchService.Arn, 'search')); + client.arnToEndpoint(domain.SearchService.Arn)); console.log('SearchInstanceType: %s', null); console.log('SearchPartitionCount: %s', Modified: lib/client.js (+28 -1) =================================================================== --- lib/client.js 2012-12-05 12:49:17 +0900 (dbc505d) +++ lib/client.js 2012-12-05 12:58:28 +0900 (e6e8e90) @@ -60,7 +60,7 @@ Client.prototype = { self.raiseFatalError(error); try { - var endpoint = domain.DocService.Endpoint.split(':'); + var endpoint = self.arnToEndpoint(domain.DocService.Arn).split(':'); self._documentsAPI = self.createDocumentService({ domainName: domain.DomainName, domainId: domain.DomainId.replace(new RegExp('/' + domain.DomainName + '$'), ''), @@ -326,6 +326,33 @@ Client.prototype = { error = new Error(domains.length + ' domains exist unexpectedly.'); callback(error); }); + }, + + arnToEndpoint: function(arn) { + return arnToEndpoint(arn, this.host + ':' + this.port); } }; + +function toValidHostAndPort(hostAndPort) { + hostAndPort = hostAndPort.split(':'); + if (hostAndPort[0] == 'localhost') + hostAndPort[0] = '127.0.0.1'; + if (hostAndPort[0].match(/^\d+\.\d+\.\d+\.\d+$/)) + hostAndPort[0] += '.xip.io'; + return hostAndPort.join(':'); +} +Client.toValidHostAndPort = toValidHostAndPort; + +function arnToEndpoint(arn, hostAndPort) { + var match = arn.match(/^arn:aws:cs:[^:]+:([^:]+):([^\/]+)\/(.+)$/); + if (!match) + client.raiseFatalError('invalid arn: ' + arn); + + var id = match[1]; + var type = match[2]; + var name = match[3]; + return type + '-' + name + '-' + id + '.' + toValidHostAndPort(hostAndPort); +} +Client.arnToEndpoint = arnToEndpoint; + exports.Client = Client; -------------- next part -------------- HTML����������������������������... Download