Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
task
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
task
Commits
346feba7
Commit
346feba7
authored
2 years ago
by
Lyuben Penkovski
Browse files
Options
Downloads
Patches
Plain Diff
Add auth config option and attache authentication middleware for jwt tokens
parent
97f0db85
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/task/main.go
+17
-4
17 additions, 4 deletions
cmd/task/main.go
internal/config/config.go
+7
-0
7 additions, 0 deletions
internal/config/config.go
with
24 additions
and
4 deletions
cmd/task/main.go
+
17
−
4
View file @
346feba7
...
...
@@ -21,6 +21,7 @@ import (
"golang.org/x/oauth2/clientcredentials"
"golang.org/x/sync/errgroup"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/auth"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/graceful"
goahealth
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/task/gen/health"
goahealthsrv
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/task/gen/http/health/server"
...
...
@@ -74,6 +75,8 @@ func main() {
// create storage
storage
:=
storage
.
New
(
db
)
httpClient
:=
httpClient
()
// create an HTTP Client which uses an authentication token
// Create an HTTP Client which uses an authentication token.
// The token will auto-refresh as necessary.
...
...
@@ -95,7 +98,7 @@ func main() {
cfg
.
Executor
.
Workers
,
cfg
.
Executor
.
PollInterval
,
cfg
.
Executor
.
MaxTaskRetries
,
httpClient
()
,
httpClient
,
logger
,
)
...
...
@@ -106,7 +109,7 @@ func main() {
cache
,
cfg
.
ListExecutor
.
Workers
,
cfg
.
ListExecutor
.
PollInterval
,
httpClient
()
,
httpClient
,
logger
,
)
...
...
@@ -166,6 +169,16 @@ func main() {
openapiServer
=
goaopenapisrv
.
New
(
openapiEndpoints
,
mux
,
dec
,
enc
,
nil
,
errFormatter
,
nil
,
nil
)
}
// Apply Authentication middleware if enabled.
if
cfg
.
Auth
.
Enabled
{
m
,
err
:=
auth
.
NewMiddleware
(
cfg
.
Auth
.
JwkURL
,
cfg
.
Auth
.
RefreshInterval
,
httpClient
)
if
err
!=
nil
{
log
.
Fatalf
(
"failed to create authentication middleware: %v"
,
err
)
}
taskServer
.
Use
(
m
.
Handler
())
taskListServer
.
Use
(
m
.
Handler
())
}
// Configure the mux.
goatasksrv
.
Mount
(
mux
,
taskServer
)
goatasklistsrv
.
Mount
(
mux
,
taskListServer
)
...
...
@@ -231,14 +244,14 @@ func httpClient() *http.Client {
Transport
:
&
http
.
Transport
{
Proxy
:
http
.
ProxyFromEnvironment
,
DialContext
:
(
&
net
.
Dialer
{
Timeout
:
3
0
*
time
.
Second
,
Timeout
:
1
0
*
time
.
Second
,
})
.
DialContext
,
MaxIdleConns
:
100
,
MaxIdleConnsPerHost
:
100
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
IdleConnTimeout
:
60
*
time
.
Second
,
},
Timeout
:
3
0
*
time
.
Second
,
Timeout
:
2
0
*
time
.
Second
,
}
}
...
...
This diff is collapsed.
Click to expand it.
internal/config/config.go
+
7
−
0
View file @
346feba7
...
...
@@ -4,6 +4,7 @@ import "time"
type
Config
struct
{
HTTP
httpConfig
Auth
authConfig
Mongo
mongoConfig
Policy
policyConfig
Executor
executorConfig
...
...
@@ -23,6 +24,12 @@ type httpConfig struct {
WriteTimeout
time
.
Duration
`envconfig:"HTTP_WRITE_TIMEOUT" default:"10s"`
}
type
authConfig
struct
{
Enabled
bool
`envconfig:"AUTH_ENABLED" default:"true"`
JwkURL
string
`envconfig:"AUTH_JWK_URL"`
RefreshInterval
time
.
Duration
`envconfig:"AUTH_REFRESH_INTERVAL" default:"1h"`
}
type
mongoConfig
struct
{
Addr
string
`envconfig:"MONGO_ADDR" required:"true"`
User
string
`envconfig:"MONGO_USER" required:"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