Add default content to always go to index.html.
Add mock sources Add links to sourcespull/62/head
parent
0a583b2492
commit
73d326d61d
|
@ -0,0 +1,32 @@
|
|||
package dist
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Dir functions like http.Dir except returns the content of a default file if not found.
|
||||
type Dir struct {
|
||||
Default string
|
||||
dir http.Dir
|
||||
}
|
||||
|
||||
func NewDir(dir, def string) Dir {
|
||||
return Dir{
|
||||
Default: def,
|
||||
dir: http.Dir(dir),
|
||||
}
|
||||
}
|
||||
|
||||
// Open will return the file in the dir if it exists, or, the Default file otherwise.
|
||||
func (d Dir) Open(name string) (http.File, error) {
|
||||
f, err := d.dir.Open(name)
|
||||
if err != nil {
|
||||
f, err = os.Open(d.Default)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
return f, err
|
||||
}
|
|
@ -8,23 +8,33 @@ import (
|
|||
|
||||
// DebugAssets serves assets via a specified directory
|
||||
type DebugAssets struct {
|
||||
Dir string // Dir is a directory location of asset files
|
||||
Dir string // Dir is a directory location of asset files
|
||||
Default string // Default is the file to serve if file is not found.
|
||||
}
|
||||
|
||||
// Handler is an http.FileServer for the Dir
|
||||
func (d *DebugAssets) Handler() http.Handler {
|
||||
return http.FileServer(http.Dir(d.Dir))
|
||||
return http.FileServer(NewDir(d.Dir, d.Default))
|
||||
}
|
||||
|
||||
// BindataAssets serves assets from go-bindata
|
||||
type BindataAssets struct {
|
||||
Prefix string // Prefix is prepended to the http file request
|
||||
Prefix string // Prefix is prepended to the http file request
|
||||
Default string // Default is the file to serve if the file is not found
|
||||
}
|
||||
|
||||
// Handler serves go-bindata using a go-bindata-assetfs façade
|
||||
func (b *BindataAssets) Handler() http.Handler {
|
||||
// def wraps the assets to return the default file if the file doesn't exist
|
||||
def := func(name string) ([]byte, error) {
|
||||
octets, err := Asset(name)
|
||||
if err != nil {
|
||||
return Asset(b.Default)
|
||||
}
|
||||
return octets, nil
|
||||
}
|
||||
var dir http.FileSystem = &assetfs.AssetFS{
|
||||
Asset: Asset,
|
||||
Asset: def,
|
||||
AssetDir: AssetDir,
|
||||
AssetInfo: AssetInfo,
|
||||
Prefix: b.Prefix,
|
||||
|
|
|
@ -23,6 +23,39 @@ func NewHandler() Handler {
|
|||
}
|
||||
}
|
||||
|
||||
func sampleSource() *models.Source {
|
||||
name := "muh name"
|
||||
influxType := "influx-enterprise"
|
||||
|
||||
return &models.Source{
|
||||
ID: "1",
|
||||
Links: &models.SourceLinks{
|
||||
Self: "/chronograf/v1/sources/1",
|
||||
Proxy: "/chronograf/v1/sources/1/proxy",
|
||||
},
|
||||
Name: &name,
|
||||
Type: &influxType,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (m *Handler) Sources(ctx context.Context, params op.GetSourcesParams) middleware.Responder {
|
||||
res := &models.Sources{
|
||||
Sources: []*models.Source{
|
||||
sampleSource(),
|
||||
},
|
||||
}
|
||||
|
||||
return op.NewGetSourcesOK().WithPayload(res)
|
||||
}
|
||||
|
||||
func (m *Handler) SourcesID(ctx context.Context, params op.GetSourcesIDParams) middleware.Responder {
|
||||
if params.ID != "1" {
|
||||
return op.NewGetSourcesIDNotFound()
|
||||
}
|
||||
return op.NewGetSourcesIDOK().WithPayload(sampleSource())
|
||||
}
|
||||
|
||||
func (m *Handler) Proxy(ctx context.Context, params op.PostSourcesIDProxyParams) middleware.Responder {
|
||||
query := params.Query.Query
|
||||
response, err := m.TimeSeries.Query(ctx, mrfusion.Query(*query))
|
||||
|
|
|
@ -18,6 +18,20 @@ swagger:model Permission
|
|||
*/
|
||||
type Permission string
|
||||
|
||||
const (
|
||||
PermissionViewAdmin Permission = "ViewAdmin"
|
||||
PermissionViewChronograf Permission = "ViewChronograf"
|
||||
PermissionCreateDatabase Permission = "CreateDatabase"
|
||||
PermissionCreateUserAndRole Permission = "CreateUserAndRole"
|
||||
PermissionAddRemoveNode Permission = "AddRemoveNode"
|
||||
PermissionDropDatabase Permission = "DropDatabase"
|
||||
PermissionDropData Permission = "DropData"
|
||||
PermissionReadData Permission = "ReadData"
|
||||
PermissionWriteData Permission = "WriteData"
|
||||
PermissionRebalance Permission = "Rebalance"
|
||||
PermissionManageShard Permission = "ManageShard"
|
||||
)
|
||||
|
||||
// for schema
|
||||
var permissionEnum []interface{}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@ type Source struct {
|
|||
*/
|
||||
ID string `json:"id,omitempty"`
|
||||
|
||||
/* link
|
||||
/* links
|
||||
*/
|
||||
Link *Link `json:"link,omitempty"`
|
||||
Links *SourceLinks `json:"links,omitempty"`
|
||||
|
||||
/* User facing name of data source
|
||||
|
||||
|
@ -46,7 +46,7 @@ type Source struct {
|
|||
func (m *Source) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if err := m.validateLink(formats); err != nil {
|
||||
if err := m.validateLinks(formats); err != nil {
|
||||
// prop
|
||||
res = append(res, err)
|
||||
}
|
||||
|
@ -67,15 +67,15 @@ func (m *Source) Validate(formats strfmt.Registry) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *Source) validateLink(formats strfmt.Registry) error {
|
||||
func (m *Source) validateLinks(formats strfmt.Registry) error {
|
||||
|
||||
if swag.IsZero(m.Link) { // not required
|
||||
if swag.IsZero(m.Links) { // not required
|
||||
return nil
|
||||
}
|
||||
|
||||
if m.Link != nil {
|
||||
if m.Links != nil {
|
||||
|
||||
if err := m.Link.Validate(formats); err != nil {
|
||||
if err := m.Links.Validate(formats); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -124,3 +124,44 @@ func (m *Source) validateType(formats strfmt.Registry) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
/*SourceLinks source links
|
||||
|
||||
swagger:model SourceLinks
|
||||
*/
|
||||
type SourceLinks struct {
|
||||
|
||||
/* URL location of the monitored services endpoint for this source
|
||||
*/
|
||||
Monitored string `json:"monitored,omitempty"`
|
||||
|
||||
/* URL location of the permissions endpoint for this source
|
||||
*/
|
||||
Permissions string `json:"permissions,omitempty"`
|
||||
|
||||
/* URL location of proxy endpoint for this source
|
||||
*/
|
||||
Proxy string `json:"proxy,omitempty"`
|
||||
|
||||
/* URL location of the roles endpoint for this source
|
||||
*/
|
||||
Roles string `json:"roles,omitempty"`
|
||||
|
||||
/* Self link mapping to this resource
|
||||
*/
|
||||
Self string `json:"self,omitempty"`
|
||||
|
||||
/* URL location of users endpoint for this source
|
||||
*/
|
||||
Users string `json:"users,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this source links
|
||||
func (m *SourceLinks) Validate(formats strfmt.Registry) error {
|
||||
var res []error
|
||||
|
||||
if len(res) > 0 {
|
||||
return errors.CompositeValidationError(res...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -39,11 +39,13 @@ func configureFlags(api *operations.MrFusionAPI) {
|
|||
func assets() mrfusion.Assets {
|
||||
if devFlags.Develop {
|
||||
return &dist.DebugAssets{
|
||||
Dir: "ui/build",
|
||||
Dir: "ui/build",
|
||||
Default: "ui/build/index.html",
|
||||
}
|
||||
}
|
||||
return &dist.BindataAssets{
|
||||
Prefix: "ui/build",
|
||||
Prefix: "ui/build",
|
||||
Default: "index.html",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,12 +89,10 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
|
|||
api.GetDashboardsIDHandler = operations.GetDashboardsIDHandlerFunc(func(ctx context.Context, params operations.GetDashboardsIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .GetDashboardsID has not yet been implemented")
|
||||
})
|
||||
api.GetSourcesHandler = operations.GetSourcesHandlerFunc(func(ctx context.Context, params operations.GetSourcesParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .GetSources has not yet been implemented")
|
||||
})
|
||||
api.GetSourcesIDHandler = operations.GetSourcesIDHandlerFunc(func(ctx context.Context, params operations.GetSourcesIDParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .GetSourcesID has not yet been implemented")
|
||||
})
|
||||
|
||||
api.GetSourcesHandler = operations.GetSourcesHandlerFunc(mockHandler.Sources)
|
||||
api.GetSourcesIDHandler = operations.GetSourcesIDHandlerFunc(mockHandler.SourcesID)
|
||||
|
||||
api.GetSourcesIDPermissionsHandler = operations.GetSourcesIDPermissionsHandlerFunc(func(ctx context.Context, params operations.GetSourcesIDPermissionsParams) middleware.Responder {
|
||||
return middleware.NotImplemented("operation .GetSourcesIDPermissions has not yet been implemented")
|
||||
})
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -343,6 +343,14 @@ func (o *MrFusionAPI) HandlerFor(method, path string) (http.Handler, bool) {
|
|||
return h, ok
|
||||
}
|
||||
|
||||
func (o *MrFusionAPI) Context() *middleware.Context {
|
||||
if o.context == nil {
|
||||
o.context = middleware.NewRoutableContext(o.spec, o, nil)
|
||||
}
|
||||
|
||||
return o.context
|
||||
}
|
||||
|
||||
func (o *MrFusionAPI) initHandlerCache() {
|
||||
if o.context == nil {
|
||||
o.context = middleware.NewRoutableContext(o.spec, o, nil)
|
||||
|
|
29
swagger.yaml
29
swagger.yaml
|
@ -754,8 +754,33 @@ definitions:
|
|||
enum:
|
||||
- influx
|
||||
- influx-enterprise
|
||||
link:
|
||||
$ref: "#/definitions/Link"
|
||||
links:
|
||||
type: object
|
||||
properties:
|
||||
self:
|
||||
type: string
|
||||
description: Self link mapping to this resource
|
||||
format: url
|
||||
users:
|
||||
type: string
|
||||
description: URL location of users endpoint for this source
|
||||
format: url
|
||||
roles:
|
||||
type: string
|
||||
description: URL location of the roles endpoint for this source
|
||||
format: url
|
||||
proxy:
|
||||
type: string
|
||||
description: URL location of proxy endpoint for this source
|
||||
format: url
|
||||
permissions:
|
||||
type: string
|
||||
description: URL location of the permissions endpoint for this source
|
||||
format: url
|
||||
monitored:
|
||||
type: string
|
||||
description: URL location of the monitored services endpoint for this source
|
||||
format: url
|
||||
Proxy:
|
||||
type: object
|
||||
required:
|
||||
|
|
Loading…
Reference in New Issue