Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoCLI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
7b6ab542
Commit
7b6ab542
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Commander => Add possibility to override the API endpoint
parent
9da5fcc2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#25054
passed
2 years ago
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
NodeApp/src/Config/Config.ts
+13
-2
13 additions, 2 deletions
NodeApp/src/Config/Config.ts
NodeApp/src/commander/CommanderApp.ts
+16
-4
16 additions, 4 deletions
NodeApp/src/commander/CommanderApp.ts
NodeApp/src/managers/HttpManager.ts
+29
-13
29 additions, 13 deletions
NodeApp/src/managers/HttpManager.ts
with
58 additions
and
19 deletions
NodeApp/src/Config/Config.ts
+
13
−
2
View file @
7b6ab542
import
*
as
os
from
'
os
'
;
import
HttpManager
from
'
../managers/HttpManager
'
;
class
Config
{
private
static
_instance
:
Config
;
p
ublic
readonly
apiURL
:
string
;
p
rivate
_
apiURL
!
:
string
;
public
readonly
localConfig
:
{
folder
:
string
;
file
:
string
;
...
...
@@ -19,6 +20,16 @@ class Config {
};
}
get
apiURL
():
string
{
return
this
.
_apiURL
;
}
set
apiURL
(
url
:
string
)
{
this
.
_apiURL
=
url
;
HttpManager
.
API_BASE_URL
=
this
.
_apiURL
;
}
public
static
get
instance
():
Config
{
if
(
!
Config
.
_instance
)
{
Config
.
_instance
=
new
Config
();
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/commander/CommanderApp.ts
+
16
−
4
View file @
7b6ab542
...
...
@@ -5,6 +5,7 @@ import SessionManager from '../managers/SessionManager';
import
axios
from
'
axios
'
;
import
HttpManager
from
'
../managers/HttpManager
'
;
import
logger
from
'
../shared/logging/WinstonLogger
'
;
import
Config
from
'
../Config/Config
'
;
class
CommanderApp
{
...
...
@@ -12,9 +13,20 @@ class CommanderApp {
constructor
()
{
this
.
program
.
name
(
'
D
ojo
CLI
'
)
.
name
(
'
d
ojo
_cli
'
)
.
description
(
'
CLI for the Dojo application
'
)
.
version
(
'
1.0.0Ɑ
'
);
.
version
(
'
1.0.0Ɑ
'
)
.
showHelpAfterError
()
.
configureHelp
({
showGlobalOptions
:
true
,
sortOptions
:
true
,
sortSubcommands
:
true
})
.
option
(
'
-H, --host <string>
'
,
'
override the Dojo API endpoint.
'
,
Config
.
apiURL
);
this
.
program
.
on
(
'
option:host
'
,
()
=>
{
Config
.
apiURL
=
this
.
program
.
opts
().
host
;
});
this
.
loginCommand
();
this
.
testSessionCommand
();
...
...
@@ -25,8 +37,8 @@ class CommanderApp {
loginCommand
()
{
this
.
program
.
command
(
'
login
'
)
.
description
(
'
Login into the application
'
)
.
requiredOption
(
'
-u, --user <string>
'
,
'
[
R
equired]
U
sername to use when connecting to server.
'
)
.
option
(
'
-p, --password <string>
'
,
'
P
assword to use when connecting to server. If password is not given it
\'
s asked.
'
)
.
requiredOption
(
'
-u, --user <string>
'
,
'
[
r
equired]
u
sername to use when connecting to server.
'
)
.
option
(
'
-p, --password <string>
'
,
'
p
assword to use when connecting to server. If password is not given it
\'
s asked.
'
)
.
action
(
async
(
options
)
=>
{
const
passwordPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
options
.
password
)
{
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/managers/HttpManager.ts
+
29
−
13
View file @
7b6ab542
...
...
@@ -6,10 +6,9 @@ import logger from '../shared/logging/WinstonLogger';
class
HttpManager
{
private
readonly
API_BASE_URL
:
string
=
Config
.
apiURL
;
public
readonly
LOGIN_URL
:
string
=
`
${
this
.
API_BASE_URL
}
/login`
;
public
readonly
TEST_SESSION_URL
:
string
=
`
${
this
.
API_BASE_URL
}
/test_session`
;
private
_API_BASE_URL
!
:
string
;
public
LOGIN_URL
!
:
string
;
public
TEST_SESSION_URL
!
:
string
;
private
static
_instance
:
HttpManager
;
...
...
@@ -21,6 +20,17 @@ class HttpManager {
return
HttpManager
.
_instance
;
}
private
constructor
()
{
}
set
API_BASE_URL
(
url
:
string
)
{
this
.
_API_BASE_URL
=
url
;
this
.
LOGIN_URL
=
`
${
this
.
_API_BASE_URL
}
/login`
;
this
.
TEST_SESSION_URL
=
`
${
this
.
_API_BASE_URL
}
/test_session`
;
}
registerAxiosInterceptor
()
{
this
.
registerRequestInterceptor
();
this
.
registerResponseInterceptor
();
...
...
@@ -49,6 +59,7 @@ class HttpManager {
return
response
;
},
(
error
)
=>
{
if
(
error
.
response
)
{
switch
(
error
.
response
.
status
)
{
case
401
:
// Unauthorized
logger
.
error
(
'
Session expired or inexistent. Please login again.
'
);
...
...
@@ -59,6 +70,11 @@ class HttpManager {
process
.
exit
(
1
);
break
;
}
}
else
{
logger
.
error
(
'
Error connecting to the server.
'
);
process
.
exit
(
1
);
}
return
Promise
.
reject
(
error
);
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment