Toggle navigation
Toggle navigation
This project
Loading...
Sign in
digsig
/
digsig-services
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Stefan Huber
2017-03-27 11:48:14 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c5383c05a5e2adf456630a0778cdda5500b9dc5f
c5383c05
1 parent
326fa3ba
commit
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
8 deletions
spec/repository.ts
src/services/repository.ts
spec/repository.ts
View file @
c5383c0
...
...
@@ -4,7 +4,7 @@ describe('Repository API', () => {
let
repo
=
new
Repository
(
null
,
null
);
it
(
'parse url'
,
()
=>
{
it
(
'parse url
with user:pass
'
,
()
=>
{
let
result
=
repo
.
parseUrl
(
'https://admin1:admin2@someplace.com:6454/somedb_name'
);
expect
(
result
.
db_name
).
toEqual
(
'local_somedb_name'
);
...
...
@@ -15,4 +15,13 @@ describe('Repository API', () => {
expect
(
result
.
domain
).
toEqual
(
'someplace.com:6454'
);
});
it
(
'parse url without user:pass'
,
()
=>
{
let
result
=
repo
.
parseUrl
(
'https://someplace.com:6454/somedb_name'
);
expect
(
result
.
db_name
).
toEqual
(
'local_somedb_name'
);
expect
(
result
.
orig_db_name
).
toEqual
(
'somedb_name'
);
expect
(
result
.
protocol
).
toEqual
(
'https'
);
expect
(
result
.
domain
).
toEqual
(
'someplace.com:6454'
);
});
});
\ No newline at end of file
...
...
src/services/repository.ts
View file @
c5383c0
...
...
@@ -99,7 +99,9 @@ export class Repository {
this
.
rest
.
scanEnvironment
(
response
.
local_ips
)
.
then
(
node
=>
{
let
res
=
this
.
parseUrl
(
response
.
db_url
);
resolve
(
this
.
prepare
(
'http://'
+
node
.
ip
+
':'
+
node
.
couchPort
+
'/'
+
res
.
orig_db_name
));
let
localCouchUrl
=
'http://'
+
node
.
ip
+
':'
+
node
.
couchPort
+
'/'
+
res
.
orig_db_name
;
console
.
log
(
"prepare local couch url: "
,
localCouchUrl
);
resolve
(
this
.
prepare
(
localCouchUrl
));
}).
catch
(()
=>
{
resolve
(
this
.
prepare
(
response
.
db_url
));
});
...
...
@@ -109,9 +111,8 @@ export class Repository {
prepare
(
url
:
string
)
:
Promise
<
any
>
{
return
new
Promise
<
any
>
((
resolve
,
reject
)
=>
{
this
.
params
=
this
.
parseUrl
(
url
);
if
(
!
this
.
params
)
{
reject
();
reject
(
'params are incorrect'
);
}
if
(
this
.
db
&&
this
.
db
.
name
==
this
.
params
.
db_name
)
{
...
...
@@ -147,10 +148,11 @@ export class Repository {
});
}
parseUrl
(
url
:
string
)
{
// matches: 0:user,1:password,2:domain,3:db_name
let
exp
=
/^
(
https
?)
:
\/\/(\w
+
?)
:
(\w
+
?)
@
([
a-zA-Z0-9.
\-
_:
]
+
?)\/([
a-zA-Z0-9
\-
_
]
+
?)
$/
;
let
match
=
url
.
match
(
exp
);
parseUrl
(
url
:
string
)
:
any
{
// matches: protocol, user, password, domain, db_name
let
expWithUsers
=
/^
(
https
?)
:
\/\/(\w
+
?)
:
(\w
+
?)
@
([
a-zA-Z0-9.
\-
_:
]
+
?)\/([
a-zA-Z0-9
\-
_
]
+
?)
$/
;
let
expWithoutUsers
=
/^
(
https
?)
:
\/\/([
a-zA-Z0-9.
\-
_:
]
+
?)\/([
a-zA-Z0-9
\-
_
]
+
?)
$/
;
let
match
=
url
.
match
(
expWithUsers
);
if
(
match
)
{
return
{
...
...
@@ -164,6 +166,17 @@ export class Repository {
}
}
match
=
url
.
match
(
expWithoutUsers
);
if
(
match
)
{
return
{
url
:
match
[
0
]
,
protocol
:
match
[
1
]
,
domain
:
match
[
2
]
,
db_name
:
'local_'
+
match
[
3
]
,
orig_db_name
:
match
[
3
]
}
}
return
null
;
}
...
...
Please
register
or
login
to post a comment