Skip to content

Commit

Permalink
Nicer YAML format; ignore unknown endpoint types in the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
ikapelyukhin committed Nov 17, 2020
1 parent bedc751 commit d4b9a1d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/jetstream/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"
"github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
)

// Endpoint - This represents the CNSI endpoint
Expand Down Expand Up @@ -97,7 +98,14 @@ func (p *portalProxy) getInfo(c echo.Context) (*interfaces.Info, error) {
endpoint.SystemSharedToken = token.SystemShared
}
cnsiType := cnsi.CNSIType
s.Endpoints[cnsiType][cnsi.GUID] = endpoint

_, ok = s.Endpoints[cnsiType]
if ok {
s.Endpoints[cnsiType][cnsi.GUID] = endpoint
} else {
// definitions of YAML-defined plugins may be removed
log.Warnf("Unknown endpoint type %q encountered in the DB", cnsiType)
}
}

// Allow plugin to modify the info data
Expand Down
8 changes: 4 additions & 4 deletions src/jetstream/plugins.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: git
auth_types:
private_github: HttpBasic
private_gitlab: Bearer
- name: git.private_github
auth_type: HttpBasic
- name: git.private_gitlab
auth_type: Bearer

31 changes: 25 additions & 6 deletions src/jetstream/plugins/yamlgenerated/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/url"
"strings"

"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"
"github.com/labstack/echo/v4"
Expand Down Expand Up @@ -128,8 +129,8 @@ func (gep GeneratedEndpointPlugin) UpdateMetadata(info *interfaces.Info, userGUI
}

type PluginConfig struct {
Name string `yaml:"name"`
AuthTypes map[string]string `yaml:"auth_types"`
Name string `yaml:"name"`
AuthType string `yaml:"auth_type"`
}

func MakePluginsFromConfig() {
Expand All @@ -149,6 +150,8 @@ func MakePluginsFromConfig() {
return
}

plugins := make(map[string]map[string]string)

for _, plugin := range config {
if len(plugin.Name) == 0 {
log.Errorf("Plugin must have a name")
Expand All @@ -157,9 +160,25 @@ func MakePluginsFromConfig() {

log.Debugf("Generating plugin %s", plugin.Name)

pieces := strings.SplitN(plugin.Name, ".", 2)
endpointType, endpointSubtype := pieces[0], ""

if len(pieces) > 1 {
endpointSubtype = pieces[1]
}

_, ok := plugins[endpointType]
if !ok {
plugins[endpointType] = make(map[string]string)
}

plugins[endpointType][endpointSubtype] = plugin.AuthType
}

for endpointType, authTypes := range plugins {
gep := GeneratedEndpointPlugin{}
gep.endpointType = plugin.Name
gep.authTypes = plugin.AuthTypes
gep.endpointType = endpointType
gep.authTypes = authTypes

gp := GeneratedPlugin{}
gp.initMethod = func() error { return nil }
Expand All @@ -168,10 +187,10 @@ func MakePluginsFromConfig() {
gp.routePlugin = func() (interfaces.RoutePlugin, error) { return nil, errors.New("Not implemented") }

interfaces.AddPlugin(
plugin.Name,
endpointType,
[]string{},
func(portalProxy interfaces.PortalProxy) (interfaces.StratosPlugin, error) {
log.Debugf("%s -- initializing", plugin.Name)
log.Debugf("%s -- initializing", endpointType)

gep.portalProxy = portalProxy
return gp, nil
Expand Down

0 comments on commit d4b9a1d

Please sign in to comment.