This repository was archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathservice_registration.go
More file actions
54 lines (45 loc) · 1.56 KB
/
service_registration.go
File metadata and controls
54 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2016 Fraunhofer Institute for Applied Information Technology FIT
package main
import (
"fmt"
_ "github.com/linksmart/go-sec/auth/keycloak/obtainer"
"github.com/linksmart/go-sec/auth/obtainer"
"github.com/linksmart/historical-datastore/common"
"github.com/linksmart/service-catalog/v2/catalog"
"github.com/linksmart/service-catalog/v2/client"
)
func registerInServiceCatalog(conf *common.Config) (func() error, error) {
cat := conf.ServiceCatalog
service := catalog.Service{
ID: conf.ServiceID,
Name: "_linksmart-hds._tcp",
Description: "LinkSmart Historical Datastore",
APIs: map[string]string{"REST API": conf.HTTP.PublicEndpoint},
Docs: []catalog.Doc{{
Description: "Documentation",
APIs: []string{"REST API"},
URL: "https://docs.linksmart.eu/display/HDS",
Type: "text/html",
}},
Meta: map[string]interface{}{
"codename": "HDS",
"apiVersion": common.APIVersion,
"apiEndpoints": []string{common.RegistryAPILoc, common.DataAPILoc},
},
TTL: cat.TTL,
}
var ticket *obtainer.Client
var err error
if cat.Auth.Enabled {
// Setup ticket client
ticket, err = obtainer.NewClient(cat.Auth.Provider, cat.Auth.ProviderURL, cat.Auth.Username, cat.Auth.Password, cat.Auth.ClientID)
if err != nil {
return nil, fmt.Errorf("error creating auth client: %s", err)
}
}
stopRegistrator, _, err := client.RegisterServiceAndKeepalive(cat.Endpoint, service, ticket)
if err != nil {
return nil, fmt.Errorf("error registering service: %s", err)
}
return stopRegistrator, nil
}