Schiefelbein, Andrew dc43d5b17d POC pluggable auth method
Fixes #32

The changes are as follows:
1. An example for basic auth
2. An example for cookie based auth
3. An example for JWT (oauth)
4. Update the linting tools to also test the examples dir
5. Update the examples structure to be more logical

Things still needing to be worked:
1. Determine the best way to handle confs pertaining to auth
2. Understand how credentials are going to be passed where
3. How to store user credentials

Change-Id: Ie8798131d7fa338a8aeec3303593afb0390ab393
2020-05-15 11:45:50 -05:00

87 lines
2.8 KiB
Go
Executable File

/*
Copyright (c) 2020 AT&T. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"log"
"github.com/vmware-tanzu/octant/pkg/navigation"
"github.com/vmware-tanzu/octant/pkg/plugin"
"github.com/vmware-tanzu/octant/pkg/plugin/service"
"github.com/vmware-tanzu/octant/pkg/view/component"
)
var pluginName = "airshipui-example-plugin"
// HelloWorldPlugin is a required struct to be an octant compliant plugin
type HelloWorldPlugin struct{}
// return a new hello world struct
func newHelloWorldPlugin() *HelloWorldPlugin {
return &HelloWorldPlugin{}
}
// This is a sample plugin showing the features of Octant's plugin API.
func main() {
// Remove the prefix from the go logger since Octant will print logs with timestamps.
log.SetPrefix("")
// Tell Octant to call this plugin when printing configuration or tabs for Pods
capabilities := &plugin.Capabilities{
IsModule: true,
}
hwp := newHelloWorldPlugin()
// Set up what should happen when Octant calls this plugin.
options := []service.PluginOption{
service.WithNavigation(hwp.handleNavigation, hwp.initRoutes),
}
// Use the plugin service helper to register this plugin.
p, err := service.Register(pluginName, "The very smallest thing you can do", capabilities, options...)
if err != nil {
log.Fatal(err)
}
// The plugin can log and the log messages will show up in Octant.
log.Printf("hello-world-plugin is starting")
p.Serve()
}
// handles the navigation pane interation
func (hwp *HelloWorldPlugin) handleNavigation(request *service.NavigationRequest) (navigation.Navigation, error) {
return navigation.Navigation{
Title: "Hello World Plugin",
Path: request.GeneratePath(),
IconName: "folder",
}, nil
}
// initRoutes routes for this plugin. In this example, there is a global catch all route
// that will return the content for every single path.
func (hwp *HelloWorldPlugin) initRoutes(router *service.Router) {
router.HandleFunc("*", hwp.routeHandler)
}
// this function returns the octant wrapped HTML content for the page
func (hwp *HelloWorldPlugin) routeHandler(request service.Request) (component.ContentResponse, error) {
contentResponse := component.NewContentResponse(component.TitleFromString("Hello World Title"))
helloWorld := component.NewText("Hello World just some text on the page")
contentResponse.Add(helloWorld)
return *contentResponse, nil
}