Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
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
Backend
DojoBackendAPI
Commits
7c3730f0
Commit
7c3730f0
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Inform about the DojoCLI version in responses header
parent
7c9b8604
No related branches found
No related tags found
No related merge requests found
Pipeline
#28428
passed
1 year ago
Stage: code_quality
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
ExpressAPI/src/config/Config.ts
+10
-0
10 additions, 0 deletions
ExpressAPI/src/config/Config.ts
ExpressAPI/src/express/API.ts
+8
-2
8 additions, 2 deletions
ExpressAPI/src/express/API.ts
ExpressAPI/src/helpers/DojoCliVersionHelper.ts
+33
-0
33 additions, 0 deletions
ExpressAPI/src/helpers/DojoCliVersionHelper.ts
with
51 additions
and
2 deletions
ExpressAPI/src/config/Config.ts
+
10
−
0
View file @
7c3730f0
...
...
@@ -21,6 +21,11 @@ class Config {
}
};
// { version: { CLIENT: CONDITION } }
public
readonly
dojoCLI
:
{
versionUpdatePeriodMs
:
number
repositoryId
:
number
};
public
readonly
jwtConfig
:
{
secret
:
string
;
expiresIn
:
number
;
};
...
...
@@ -64,6 +69,11 @@ class Config {
this
.
requestClientValidation
=
JSON5
.
parse
(
process
.
env
.
REQUEST_CLIENT_VALIDATION
||
'
{"version": {}}
'
);
this
.
dojoCLI
=
{
versionUpdatePeriodMs
:
Number
(
process
.
env
.
DOJO_CLI_VERSION_UPDATE_PERIOD_MS
||
3600
),
repositoryId
:
Number
(
process
.
env
.
DOJO_CLI_GITLAB_REPOSITORY_ID
||
0
)
};
this
.
jwtConfig
=
{
secret
:
process
.
env
.
JWT_SECRET_KEY
||
''
,
expiresIn
:
Number
(
process
.
env
.
SESSION_TIMEOUT
||
0
)
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/express/API.ts
+
8
−
2
View file @
7c3730f0
...
...
@@ -16,6 +16,7 @@ import compression from 'compression';
import
ClientVersionCheckerMiddleware
from
'
../middlewares/ClientVersionCheckerMiddleware
'
;
import
swaggerUi
from
'
swagger-ui-express
'
;
import
path
from
'
path
'
;
import
DojoCliVersionHelper
from
'
../helpers/DojoCliVersionHelper
'
;
class
API
implements
WorkerTask
{
...
...
@@ -25,7 +26,7 @@ class API implements WorkerTask {
constructor
()
{
this
.
backend
=
express
();
this
.
init
Swagger
();
this
.
init
OpenAPI
();
this
.
initBaseMiddlewares
();
this
.
backend
.
use
(
ClientVersionCheckerMiddleware
.
register
());
...
...
@@ -43,9 +44,14 @@ class API implements WorkerTask {
this
.
backend
.
use
(
helmet
());
//Help to secure express, https://helmetjs.github.io/
this
.
backend
.
use
(
cors
());
//Allow CORS requests
this
.
backend
.
use
(
compression
());
//Compress responses
this
.
backend
.
use
(
async
(
req
,
res
,
next
)
=>
{
res
.
header
(
'
dojocli-latest-version
'
,
await
DojoCliVersionHelper
.
getLatestVersion
());
next
();
});
}
private
init
Swagger
()
{
private
init
OpenAPI
()
{
const
options
=
{
customSiteTitle
:
'
Dojo API
'
,
explorer
:
false
,
...
...
This diff is collapsed.
Click to expand it.
ExpressAPI/src/helpers/DojoCliVersionHelper.ts
0 → 100644
+
33
−
0
View file @
7c3730f0
import
Config
from
'
../config/Config
'
;
import
GitlabRelease
from
'
../shared/types/Gitlab/GitlabRelease
'
;
import
GitlabManager
from
'
../managers/GitlabManager
'
;
class
DojoCliVersionHelper
{
private
latestUpdate
:
Date
|
undefined
;
private
latestVersion
:
string
|
undefined
;
constructor
()
{
}
private
async
updateVersion
():
Promise
<
void
>
{
const
releases
:
Array
<
GitlabRelease
>
=
await
GitlabManager
.
getRepositoryReleases
(
Config
.
dojoCLI
.
repositoryId
);
for
(
const
release
of
releases
)
{
if
(
!
isNaN
(
+
release
.
tag_name
.
replace
(
'
.
'
,
''
))
)
{
this
.
latestVersion
=
release
.
tag_name
;
this
.
latestUpdate
=
new
Date
();
return
;
}
}
}
public
async
getLatestVersion
():
Promise
<
string
>
{
if
(
!
this
.
latestVersion
||
!
this
.
latestUpdate
||
(
new
Date
()).
getTime
()
-
this
.
latestUpdate
.
getTime
()
>=
Config
.
dojoCLI
.
versionUpdatePeriodMs
)
{
await
this
.
updateVersion
();
}
return
this
.
latestVersion
!
;
}
}
export
default
new
DojoCliVersionHelper
();
\ No newline at end of file
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