Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Commit aaab759

Browse files
committed
Connect hydra admin api
1 parent 3f927ba commit aaab759

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

Gopkg.lock

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Config struct {
1111
DataSourceName string `envconfig:"data_source_name" required:"true"`
1212
RedisAddr string `envconfig:"redis_addr" required:"true"`
1313
DebugLog bool `envconfig:"debug_log"`
14+
HydraAdminURL string `envconfig:"hydra_admin_url" required:"true"`
1415
}
1516

1617
// LoadConfig loads config

app/di/client_component.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package di
2+
3+
import (
4+
"context"
5+
6+
"github.com/ory/hydra/sdk/go/hydra"
7+
"github.com/pkg/errors"
8+
9+
"github.com/ProgrammingLab/prolab-accounts/app/config"
10+
)
11+
12+
// ClientComponent is an interface of api clients
13+
type ClientComponent interface {
14+
HydraClient(ctx context.Context) *hydra.CodeGenSDK
15+
}
16+
17+
// NewClientComponent returns new client component
18+
func NewClientComponent(cfg *config.Config) (ClientComponent, error) {
19+
h, err := newHydraClient(cfg)
20+
if err != nil {
21+
return nil, errors.WithStack(err)
22+
}
23+
24+
return &clientComponentImpl{
25+
hydraCli: h,
26+
}, nil
27+
}
28+
29+
func newHydraClient(cfg *config.Config) (*hydra.CodeGenSDK, error) {
30+
hc := &hydra.Configuration{
31+
AdminURL: cfg.HydraAdminURL,
32+
}
33+
cli, err := hydra.NewSDK(hc)
34+
if err != nil {
35+
return nil, errors.WithStack(err)
36+
}
37+
return cli, nil
38+
}
39+
40+
type clientComponentImpl struct {
41+
hydraCli *hydra.CodeGenSDK
42+
}
43+
44+
func (c *clientComponentImpl) HydraClient(ctx context.Context) *hydra.CodeGenSDK {
45+
return c.hydraCli
46+
}
File renamed without changes.

0 commit comments

Comments
 (0)