Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
templateService
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bazarbay Tulenov
templateService
Commits
6c420f34
Commit
6c420f34
authored
Jan 19, 2024
by
George Novikov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into custom-logger
parents
ba072b9e
a69c6683
Pipeline
#371
failed with stage
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
22 deletions
+51
-22
docker-compose.yaml
docker-compose.yaml
+3
-1
src/main/java/kz/project/printedFormsService/config/SecurityContextUtils.java
...ject/printedFormsService/config/SecurityContextUtils.java
+15
-0
src/main/java/kz/project/printedFormsService/converter/JwtAuthConverter.java
...oject/printedFormsService/converter/JwtAuthConverter.java
+7
-3
src/main/java/kz/project/printedFormsService/service/GitlabClient.java
.../kz/project/printedFormsService/service/GitlabClient.java
+3
-3
src/main/java/kz/project/printedFormsService/service/impl/GitlabClientImpl.java
...ct/printedFormsService/service/impl/GitlabClientImpl.java
+6
-6
src/main/java/kz/project/printedFormsService/service/impl/GitlabTemplateServiceImpl.java
...dFormsService/service/impl/GitlabTemplateServiceImpl.java
+15
-6
src/main/resources/application.yml
src/main/resources/application.yml
+2
-3
No files found.
docker-compose.yaml
View file @
6c420f34
...
...
@@ -29,8 +29,10 @@ services:
-
SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/template_db
-
KEYCLOAK_URI=https://idp.applatform.qaztech.gov.kz
-
KEYCLOAK_CLIENT_SECRET=1NYLMNlWXpPDW3QKeZ4VjlY76DuzNtaB
-
GITLAB_BASE_PATH=http://gitlab.lan.arta.kz
-
GITLAB_TOKEN=zif-LhgdzuLtpNW7uxYs
networks
:
printform
:
external
:
true
name
:
printform
\ No newline at end of file
name
:
printform
src/main/java/kz/project/printedFormsService/config/SecurityContextUtils.java
View file @
6c420f34
package
kz.project.printedFormsService.config
;
import
kz.project.printedFormsService.exception.ValidationException
;
import
lombok.experimental.UtilityClass
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.context.SecurityContextHolder
;
...
...
@@ -45,4 +46,18 @@ public class SecurityContextUtils {
)
);
}
public
static
String
getGitlabProjectBranchFromRole
()
throws
ValidationException
{
return
SecurityContextHolder
.
getContext
()
.
getAuthentication
()
.
getAuthorities
()
.
stream
()
.
map
(
GrantedAuthority:
:
getAuthority
)
.
filter
(
role
->
role
.
contains
(
"gitlab"
))
.
map
(
role
->
role
.
replace
(
"ROLE_gitlab_"
,
""
))
.
findFirst
()
.
orElseThrow
(()
->
new
ValidationException
(
"Не указана роль для доступа к gitlab"
));
}
}
src/main/java/kz/project/printedFormsService/converter/JwtAuthConverter.java
View file @
6c420f34
...
...
@@ -42,15 +42,19 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo
private
Collection
<
GrantedAuthority
>
extractAuthorities
(
Jwt
jwt
)
{
if
(
jwt
.
getClaim
(
"resource_access"
)
!=
null
)
{
Map
<
String
,
Map
<
String
,
Object
>>
resourceAccess
=
jwt
.
getClaim
(
"resource_access"
);
if
(
resourceAccess
.
containsKey
(
"print_form"
)){
Map
<
String
,
Map
<
String
,
Object
>>
resourceAccess
=
jwt
.
getClaim
(
"resource_access"
);
if
(
resourceAccess
.
containsKey
(
"print_form"
))
{
ObjectMapper
mapper
=
new
ObjectMapper
();
List
<
String
>
roles
=
mapper
.
convertValue
(
resourceAccess
.
get
(
"print_form"
).
get
(
"roles"
),
new
TypeReference
<>()
{
});
Set
<
GrantedAuthority
>
authorities
=
new
HashSet
<>();
for
(
String
role
:
roles
)
{
authorities
.
add
(
new
SimpleGrantedAuthority
(
"ROLE_"
+
role
.
substring
(
role
.
lastIndexOf
(
'_'
)+
1
)));
if
(
role
.
contains
(
"gitlab"
))
{
authorities
.
add
(
new
SimpleGrantedAuthority
(
"ROLE_"
+
role
));
}
else
{
authorities
.
add
(
new
SimpleGrantedAuthority
(
"ROLE_"
+
role
.
substring
(
role
.
lastIndexOf
(
'_'
)
+
1
)));
}
}
return
authorities
;
...
...
src/main/java/kz/project/printedFormsService/service/GitlabClient.java
View file @
6c420f34
...
...
@@ -4,9 +4,9 @@ import org.springframework.web.multipart.MultipartFile;
import
reactor.core.publisher.Mono
;
public
interface
GitlabClient
{
Mono
<
byte
[]>
downloadFileFromGitLab
(
String
projectName
,
String
filePath
);
Mono
<
byte
[]>
downloadFileFromGitLab
(
String
projectName
,
String
filePath
,
String
branch
);
Mono
<
String
>
downloadFileContentAsString
(
String
projectName
,
String
filePath
);
Mono
<
String
>
downloadFileContentAsString
(
String
projectName
,
String
filePath
,
String
branch
);
MultipartFile
downloadFileAsMultipartFile
(
String
projectName
,
String
filePath
);
MultipartFile
downloadFileAsMultipartFile
(
String
projectName
,
String
filePath
,
String
branch
);
}
src/main/java/kz/project/printedFormsService/service/impl/GitlabClientImpl.java
View file @
6c420f34
...
...
@@ -24,12 +24,12 @@ public class GitlabClientImpl implements GitlabClient {
//http://gitlab.lan.arta.kz/d.ermakov/templates/-/raw/master/dto.txt?inline=false
@Override
public
Mono
<
byte
[]>
downloadFileFromGitLab
(
String
projectName
,
String
filePath
)
{
public
Mono
<
byte
[]>
downloadFileFromGitLab
(
String
projectName
,
String
filePath
,
String
branch
)
{
String
urlPath
=
String
.
format
(
"/api/v4/projects/%s/repository/files/%s/raw"
,
projectName
,
filePath
);
return
webClient
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
urlPath
)
.
queryParam
(
"ref"
,
"master"
)
// or the branch you want to fetch from
.
queryParam
(
"ref"
,
branch
)
// or the branch you want to fetch from
.
build
())
.
retrieve
()
.
bodyToMono
(
byte
[].
class
)
...
...
@@ -37,12 +37,12 @@ public class GitlabClientImpl implements GitlabClient {
}
@Override
public
Mono
<
String
>
downloadFileContentAsString
(
String
projectName
,
String
filePath
)
{
public
Mono
<
String
>
downloadFileContentAsString
(
String
projectName
,
String
filePath
,
String
branch
)
{
String
urlPath
=
String
.
format
(
"/api/v4/projects/%s/repository/files/%s/raw"
,
projectName
,
filePath
);
return
webClient
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
urlPath
)
.
queryParam
(
"ref"
,
"master"
)
// or the branch you want to fetch from
.
queryParam
(
"ref"
,
branch
)
// or the branch you want to fetch from
.
build
())
.
retrieve
()
.
bodyToMono
(
String
.
class
)
...
...
@@ -50,12 +50,12 @@ public class GitlabClientImpl implements GitlabClient {
}
@Override
public
MultipartFile
downloadFileAsMultipartFile
(
String
projectName
,
String
filePath
)
{
public
MultipartFile
downloadFileAsMultipartFile
(
String
projectName
,
String
filePath
,
String
branch
)
{
String
urlPath
=
String
.
format
(
"/api/v4/projects/%s/repository/files/%s/raw"
,
projectName
,
filePath
);
return
webClient
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
urlPath
)
.
queryParam
(
"ref"
,
"master"
)
// or the branch you want to fetch from
.
queryParam
(
"ref"
,
branch
)
// or the branch you want to fetch from
.
build
())
.
retrieve
()
.
bodyToMono
(
byte
[].
class
)
...
...
src/main/java/kz/project/printedFormsService/service/impl/GitlabTemplateServiceImpl.java
View file @
6c420f34
package
kz.project.printedFormsService.service.impl
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
kz.project.printedFormsService.config.SecurityContextUtils
;
import
kz.project.printedFormsService.data.dto.GitlabUploadRequest
;
import
kz.project.printedFormsService.data.dto.TemplateDto
;
import
kz.project.printedFormsService.data.dto.TemplateResponseDto
;
...
...
@@ -28,16 +29,19 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
@SneakyThrows
@Override
public
TemplateDto
saveFromGitlab
(
GitlabUploadRequest
gitlabUploadRequest
)
{
String
gitlabBranch
=
SecurityContextUtils
.
getGitlabProjectBranchFromRole
();
List
<
MultipartFile
>
filesToSave
=
new
ArrayList
<>();
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDataPath
()
gitlabUploadRequest
.
getFileDataPath
(),
gitlabBranch
));
String
dtoString
=
gitlabClient
.
downloadFileContentAsString
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDtoPath
()
gitlabUploadRequest
.
getFileDtoPath
(),
gitlabBranch
)
.
blockOptional
()
.
orElseThrow
();
...
...
@@ -48,7 +52,8 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileHeaderPath
()
gitlabUploadRequest
.
getFileHeaderPath
(),
gitlabBranch
)
);
}
...
...
@@ -59,16 +64,19 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
@SneakyThrows
@Override
public
TemplateResponseDto
updateFromGitlab
(
GitlabUploadRequest
gitlabUploadRequest
)
{
String
gitlabBranch
=
SecurityContextUtils
.
getGitlabProjectBranchFromRole
();
List
<
MultipartFile
>
filesToSave
=
new
ArrayList
<>();
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDataPath
()
gitlabUploadRequest
.
getFileDataPath
(),
gitlabBranch
));
String
dtoString
=
gitlabClient
.
downloadFileContentAsString
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDtoPath
()
gitlabUploadRequest
.
getFileDtoPath
(),
gitlabBranch
)
.
blockOptional
()
.
orElseThrow
();
...
...
@@ -79,7 +87,8 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileHeaderPath
()
gitlabUploadRequest
.
getFileHeaderPath
(),
gitlabBranch
)
);
}
...
...
src/main/resources/application.yml
View file @
6c420f34
...
...
@@ -85,6 +85,5 @@ process-logger:
error-prefix
:
"
Неуспешный
процесс:
"
gitlab
:
base-url
:
http://gitlab.lan.arta.kz
token
:
zif-LhgdzuLtpNW7uxYs
base-url
:
${GITLAB_BASE_PATH:http://gitlab.lan.arta.kz}
token
:
${GITLAB_TOKEN:zif-LhgdzuLtpNW7uxYs}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment