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
3531f256
Commit
3531f256
authored
Jan 19, 2024
by
Denis
Committed by
Denis Ligin
Jan 19, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Загрузка шаблонов из гитлаба
parent
5233a7cb
Pipeline
#364
canceled with stage
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
21 deletions
+51
-21
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
-2
No files found.
docker-compose.yaml
View file @
3531f256
...
@@ -29,8 +29,10 @@ services:
...
@@ -29,8 +29,10 @@ services:
-
SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/template_db
-
SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/template_db
-
KEYCLOAK_URI=https://idp.applatform.qaztech.gov.kz
-
KEYCLOAK_URI=https://idp.applatform.qaztech.gov.kz
-
KEYCLOAK_CLIENT_SECRET=1NYLMNlWXpPDW3QKeZ4VjlY76DuzNtaB
-
KEYCLOAK_CLIENT_SECRET=1NYLMNlWXpPDW3QKeZ4VjlY76DuzNtaB
-
GITLAB_BASE_PATH=http://gitlab.lan.arta.kz
-
GITLAB_TOKEN=zif-LhgdzuLtpNW7uxYs
networks
:
networks
:
printform
:
printform
:
external
:
true
external
:
true
name
:
printform
name
:
printform
\ No newline at end of file
src/main/java/kz/project/printedFormsService/config/SecurityContextUtils.java
View file @
3531f256
package
kz.project.printedFormsService.config
;
package
kz.project.printedFormsService.config
;
import
kz.project.printedFormsService.exception.ValidationException
;
import
lombok.experimental.UtilityClass
;
import
lombok.experimental.UtilityClass
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.context.SecurityContextHolder
;
import
org.springframework.security.core.context.SecurityContextHolder
;
...
@@ -45,4 +46,18 @@ public class SecurityContextUtils {
...
@@ -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 @
3531f256
...
@@ -26,15 +26,19 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo
...
@@ -26,15 +26,19 @@ public class JwtAuthConverter implements Converter<Jwt, AbstractAuthenticationTo
private
Collection
<
GrantedAuthority
>
extractAuthorities
(
Jwt
jwt
)
{
private
Collection
<
GrantedAuthority
>
extractAuthorities
(
Jwt
jwt
)
{
if
(
jwt
.
getClaim
(
"resource_access"
)
!=
null
)
{
if
(
jwt
.
getClaim
(
"resource_access"
)
!=
null
)
{
Map
<
String
,
Map
<
String
,
Object
>>
resourceAccess
=
jwt
.
getClaim
(
"resource_access"
);
Map
<
String
,
Map
<
String
,
Object
>>
resourceAccess
=
jwt
.
getClaim
(
"resource_access"
);
if
(
resourceAccess
.
containsKey
(
"print_form"
)){
if
(
resourceAccess
.
containsKey
(
"print_form"
))
{
ObjectMapper
mapper
=
new
ObjectMapper
();
ObjectMapper
mapper
=
new
ObjectMapper
();
List
<
String
>
roles
=
mapper
.
convertValue
(
resourceAccess
.
get
(
"print_form"
).
get
(
"roles"
),
new
TypeReference
<>()
{
List
<
String
>
roles
=
mapper
.
convertValue
(
resourceAccess
.
get
(
"print_form"
).
get
(
"roles"
),
new
TypeReference
<>()
{
});
});
Set
<
GrantedAuthority
>
authorities
=
new
HashSet
<>();
Set
<
GrantedAuthority
>
authorities
=
new
HashSet
<>();
for
(
String
role
:
roles
)
{
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
;
return
authorities
;
...
...
src/main/java/kz/project/printedFormsService/service/GitlabClient.java
View file @
3531f256
...
@@ -4,9 +4,9 @@ import org.springframework.web.multipart.MultipartFile;
...
@@ -4,9 +4,9 @@ import org.springframework.web.multipart.MultipartFile;
import
reactor.core.publisher.Mono
;
import
reactor.core.publisher.Mono
;
public
interface
GitlabClient
{
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 @
3531f256
...
@@ -24,12 +24,12 @@ public class GitlabClientImpl implements GitlabClient {
...
@@ -24,12 +24,12 @@ public class GitlabClientImpl implements GitlabClient {
//http://gitlab.lan.arta.kz/d.ermakov/templates/-/raw/master/dto.txt?inline=false
//http://gitlab.lan.arta.kz/d.ermakov/templates/-/raw/master/dto.txt?inline=false
@Override
@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
);
String
urlPath
=
String
.
format
(
"/api/v4/projects/%s/repository/files/%s/raw"
,
projectName
,
filePath
);
return
webClient
.
get
()
return
webClient
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
urlPath
)
.
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
())
.
build
())
.
retrieve
()
.
retrieve
()
.
bodyToMono
(
byte
[].
class
)
.
bodyToMono
(
byte
[].
class
)
...
@@ -37,12 +37,12 @@ public class GitlabClientImpl implements GitlabClient {
...
@@ -37,12 +37,12 @@ public class GitlabClientImpl implements GitlabClient {
}
}
@Override
@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
);
String
urlPath
=
String
.
format
(
"/api/v4/projects/%s/repository/files/%s/raw"
,
projectName
,
filePath
);
return
webClient
.
get
()
return
webClient
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
urlPath
)
.
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
())
.
build
())
.
retrieve
()
.
retrieve
()
.
bodyToMono
(
String
.
class
)
.
bodyToMono
(
String
.
class
)
...
@@ -50,12 +50,12 @@ public class GitlabClientImpl implements GitlabClient {
...
@@ -50,12 +50,12 @@ public class GitlabClientImpl implements GitlabClient {
}
}
@Override
@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
);
String
urlPath
=
String
.
format
(
"/api/v4/projects/%s/repository/files/%s/raw"
,
projectName
,
filePath
);
return
webClient
.
get
()
return
webClient
.
get
()
.
uri
(
uriBuilder
->
uriBuilder
.
uri
(
uriBuilder
->
uriBuilder
.
path
(
urlPath
)
.
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
())
.
build
())
.
retrieve
()
.
retrieve
()
.
bodyToMono
(
byte
[].
class
)
.
bodyToMono
(
byte
[].
class
)
...
...
src/main/java/kz/project/printedFormsService/service/impl/GitlabTemplateServiceImpl.java
View file @
3531f256
package
kz.project.printedFormsService.service.impl
;
package
kz.project.printedFormsService.service.impl
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
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.GitlabUploadRequest
;
import
kz.project.printedFormsService.data.dto.TemplateDto
;
import
kz.project.printedFormsService.data.dto.TemplateDto
;
import
kz.project.printedFormsService.data.dto.TemplateResponseDto
;
import
kz.project.printedFormsService.data.dto.TemplateResponseDto
;
...
@@ -28,16 +29,19 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
...
@@ -28,16 +29,19 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
@SneakyThrows
@SneakyThrows
@Override
@Override
public
TemplateDto
saveFromGitlab
(
GitlabUploadRequest
gitlabUploadRequest
)
{
public
TemplateDto
saveFromGitlab
(
GitlabUploadRequest
gitlabUploadRequest
)
{
String
gitlabBranch
=
SecurityContextUtils
.
getGitlabProjectBranchFromRole
();
List
<
MultipartFile
>
filesToSave
=
new
ArrayList
<>();
List
<
MultipartFile
>
filesToSave
=
new
ArrayList
<>();
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDataPath
()
gitlabUploadRequest
.
getFileDataPath
(),
gitlabBranch
));
));
String
dtoString
=
gitlabClient
.
downloadFileContentAsString
(
String
dtoString
=
gitlabClient
.
downloadFileContentAsString
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDtoPath
()
gitlabUploadRequest
.
getFileDtoPath
(),
gitlabBranch
)
)
.
blockOptional
()
.
blockOptional
()
.
orElseThrow
();
.
orElseThrow
();
...
@@ -48,7 +52,8 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
...
@@ -48,7 +52,8 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
filesToSave
.
add
(
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileHeaderPath
()
gitlabUploadRequest
.
getFileHeaderPath
(),
gitlabBranch
)
)
);
);
}
}
...
@@ -59,16 +64,19 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
...
@@ -59,16 +64,19 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
@SneakyThrows
@SneakyThrows
@Override
@Override
public
TemplateResponseDto
updateFromGitlab
(
GitlabUploadRequest
gitlabUploadRequest
)
{
public
TemplateResponseDto
updateFromGitlab
(
GitlabUploadRequest
gitlabUploadRequest
)
{
String
gitlabBranch
=
SecurityContextUtils
.
getGitlabProjectBranchFromRole
();
List
<
MultipartFile
>
filesToSave
=
new
ArrayList
<>();
List
<
MultipartFile
>
filesToSave
=
new
ArrayList
<>();
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDataPath
()
gitlabUploadRequest
.
getFileDataPath
(),
gitlabBranch
));
));
String
dtoString
=
gitlabClient
.
downloadFileContentAsString
(
String
dtoString
=
gitlabClient
.
downloadFileContentAsString
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileDtoPath
()
gitlabUploadRequest
.
getFileDtoPath
(),
gitlabBranch
)
)
.
blockOptional
()
.
blockOptional
()
.
orElseThrow
();
.
orElseThrow
();
...
@@ -79,7 +87,8 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
...
@@ -79,7 +87,8 @@ public class GitlabTemplateServiceImpl implements kz.project.printedFormsService
filesToSave
.
add
(
filesToSave
.
add
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabClient
.
downloadFileAsMultipartFile
(
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getRepository
(),
gitlabUploadRequest
.
getFileHeaderPath
()
gitlabUploadRequest
.
getFileHeaderPath
(),
gitlabBranch
)
)
);
);
}
}
...
...
src/main/resources/application.yml
View file @
3531f256
...
@@ -74,5 +74,5 @@ management:
...
@@ -74,5 +74,5 @@ management:
enabled
:
false
enabled
:
false
gitlab
:
gitlab
:
base-url
:
http://gitlab.lan.arta.kz
base-url
:
${GITLAB_BASE_PATH:http://gitlab.lan.arta.kz}
token
:
zif-LhgdzuLtpNW7uxYs
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