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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
UI
DojoCLI
Commits
5575e4b6
Commit
5575e4b6
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Commander => Add gitlab register & test accesses
parent
3a614190
No related branches found
No related tags found
No related merge requests found
Pipeline
#25093
passed
2 years ago
Stage: build
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
NodeApp/src/commander/CommanderApp.ts
+35
-32
35 additions, 32 deletions
NodeApp/src/commander/CommanderApp.ts
NodeApp/src/managers/SessionManager.ts
+33
-5
33 additions, 5 deletions
NodeApp/src/managers/SessionManager.ts
with
68 additions
and
37 deletions
NodeApp/src/commander/CommanderApp.ts
+
35
−
32
View file @
5575e4b6
import
{
Command
}
from
'
commander
'
;
import
{
Command
}
from
'
commander
'
;
import
prompt
from
'
prompt
'
;
import
colors
from
'
@colors/colors/safe
'
;
import
SessionManager
from
'
../managers/SessionManager
'
;
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
'
;
import
Config
from
'
../Config/Config
'
;
import
GitlabManager
from
'
../managers/GitlabManager
'
;
import
chalk
from
'
chalk
'
;
import
inquirer
from
'
inquirer
'
;
class
CommanderApp
{
class
CommanderApp
{
...
@@ -29,7 +27,8 @@ class CommanderApp {
...
@@ -29,7 +27,8 @@ class CommanderApp {
});
});
this
.
loginCommand
();
this
.
loginCommand
();
this
.
testSessionCommand
();
this
.
gitlabRegisterCommand
();
this
.
testAccessesCommand
();
this
.
program
.
parse
();
this
.
program
.
parse
();
}
}
...
@@ -40,38 +39,42 @@ class CommanderApp {
...
@@ -40,38 +39,42 @@ class CommanderApp {
.
requiredOption
(
'
-u, --user <string>
'
,
'
[required] username to use when connecting to server.
'
)
.
requiredOption
(
'
-u, --user <string>
'
,
'
[required] username to use when connecting to server.
'
)
.
option
(
'
-p, --password <string>
'
,
'
password to use when connecting to server. If password is not given it
\'
s asked.
'
)
.
option
(
'
-p, --password <string>
'
,
'
password to use when connecting to server. If password is not given it
\'
s asked.
'
)
.
action
(
async
(
options
)
=>
{
.
action
(
async
(
options
)
=>
{
const
passwordPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
options
.
password
)
{
if
(
!
options
.
password
)
{
prompt
.
get
({
options
.
password
=
(
await
inquirer
.
prompt
({
properties
:
{
type
:
'
password
'
,
password
:
{
name
:
'
password
'
,
description
:
colors
.
cyan
(
'
Please enter your password
'
)
,
message
:
'
Please enter your password
'
,
required
:
true
,
mask
:
''
hidden
:
true
})).
password
;
}
}
}
},
(
err
,
result
)
=>
{
console
.
log
(
chalk
.
cyan
(
'
Please wait while we are logging in you to Dojo...
'
));
options
.
password
=
result
.
password
;
resolve
(
undefine
d
);
await
SessionManager
.
login
(
options
.
user
,
options
.
passwor
d
);
});
});
}
else
{
resolve
(
undefined
);
}
}
});
await
passwordPromise
;
gitlabRegisterCommand
()
{
this
.
program
.
command
(
'
gitlab_register
'
)
.
description
(
'
Register the gitlab token
'
)
.
argument
(
'
<token>
'
,
'
Personal access token from GitLab with api scope.
'
)
.
action
(
async
(
token
)
=>
{
console
.
log
(
chalk
.
cyan
(
'
Please wait while we are testing your Gitlab token...
'
));
SessionManager
.
login
(
options
.
user
,
options
.
password
);
GitlabManager
.
token
=
token
;
await
GitlabManager
.
testToken
();
});
});
}
}
testSessionCommand
()
{
testAccessesCommand
()
{
this
.
program
.
command
(
'
test-session
'
)
this
.
program
.
command
(
'
test_accesses
'
)
.
description
(
'
Test availability of session
'
)
.
description
(
'
Test availability of registered Dojo API and Gitlab API sessions
'
)
.
action
(
async
(
options
)
=>
{
.
action
(
async
_
=>
{
const
response
=
await
axios
.
get
(
HttpManager
.
TEST_SESSION_URL
);
console
.
log
(
chalk
.
cyan
(
'
Please wait while we are testing your Dojo accesses...
'
));
await
SessionManager
.
testSession
();
logger
.
info
(
'
Session is valid
'
);
console
.
log
(
chalk
.
cyan
(
'
Please wait while we are testing your Gitlab accesses...
'
));
await
GitlabManager
.
testToken
();
});
});
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
NodeApp/src/managers/SessionManager.ts
+
33
−
5
View file @
5575e4b6
...
@@ -3,8 +3,8 @@ import User from '../models/User';
...
@@ -3,8 +3,8 @@ import User from '../models/User';
import
LocalConfig
from
'
../Config/LocalConfig/LocalConfig
'
;
import
LocalConfig
from
'
../Config/LocalConfig/LocalConfig
'
;
import
LocalConfigKeys
from
'
../Config/LocalConfig/LocalConfigKeys
'
;
import
LocalConfigKeys
from
'
../Config/LocalConfig/LocalConfigKeys
'
;
import
axios
,
{
AxiosError
}
from
'
axios
'
;
import
axios
,
{
AxiosError
}
from
'
axios
'
;
import
logger
from
'
../shared/logging/WinstonLogger
'
;
import
HttpManager
from
'
./HttpManager
'
;
import
HttpManager
from
'
./HttpManager
'
;
import
ora
from
'
ora
'
;
class
SessionManager
{
class
SessionManager
{
...
@@ -45,6 +45,7 @@ class SessionManager {
...
@@ -45,6 +45,7 @@ class SessionManager {
}
}
async
login
(
user
:
string
,
password
:
string
)
{
async
login
(
user
:
string
,
password
:
string
)
{
const
spinner
:
ora
.
Ora
=
ora
(
'
Logging in
'
).
start
();
try
{
try
{
const
response
=
await
axios
.
post
(
HttpManager
.
LOGIN_URL
,
{
const
response
=
await
axios
.
post
(
HttpManager
.
LOGIN_URL
,
{
user
:
user
,
user
:
user
,
...
@@ -55,21 +56,48 @@ class SessionManager {
...
@@ -55,21 +56,48 @@ class SessionManager {
}
}
});
});
logger
.
info
(
'
Login successful
'
);
spinner
.
succeed
(
'
Logged in
'
);
}
catch
(
error
)
{
}
catch
(
error
)
{
if
(
error
instanceof
AxiosError
)
{
if
(
error
instanceof
AxiosError
)
{
if
(
error
.
response
)
{
if
(
error
.
response
)
{
if
(
error
.
response
.
status
===
404
)
{
if
(
error
.
response
.
status
===
404
)
{
logger
.
error
(
`
User not found or password incorrect
`
);
spinner
.
fail
(
'
User not found or password incorrect
'
);
}
else
{
}
else
{
logger
.
error
(
`Login error:
${
error
.
response
.
statusText
}
`
);
spinner
.
fail
(
`Login error:
${
error
.
response
.
statusText
}
`
);
}
}
}
}
}
else
{
}
else
{
logger
.
error
(
`Login error:
${
error
}
`
);
spinner
.
fail
(
`Login error:
${
error
}
`
);
}
}
}
}
}
}
async
testSession
(
verbose
:
boolean
=
true
):
Promise
<
boolean
>
{
HttpManager
.
handleCommandErrors
=
false
;
let
result
:
boolean
=
false
;
const
spinner
:
ora
.
Ora
=
ora
(
'
Testing Dojo session
'
);
if
(
verbose
)
{
spinner
.
start
();
}
try
{
const
response
=
await
axios
.
get
(
HttpManager
.
TEST_SESSION_URL
,
{});
result
=
true
;
if
(
verbose
)
{
spinner
.
succeed
(
'
The session is valid
'
);
}
}
catch
(
error
)
{
if
(
verbose
)
{
spinner
.
succeed
(
'
The session is invalid
'
);
}
}
return
true
;
}
}
}
...
...
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