-
Notifications
You must be signed in to change notification settings - Fork 0
/
op_handler.go
129 lines (114 loc) · 3.63 KB
/
op_handler.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright 2022-2023 Thorsten A. Knieling
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
package server
import (
"context"
ht "github.com/ogen-go/ogen/http"
"github.com/tknie/clu"
"github.com/tknie/clu/api"
"github.com/tknie/services"
"github.com/tknie/services/auth"
)
// GetVersion implements getVersion operation.
//
// Retrieves the current version.
//
// GET /version
func (Handler) GetVersion(ctx context.Context) (r api.GetVersionRes, _ error) {
r = &api.Versions{Product: api.NewOptString("REST-API"),
Version: api.NewOptString(services.BuildVersion)}
return r, nil
}
// GetUserInfo implements getUserInfo operation.
//
// Retrieves the user information.
//
// GET /rest/user
func (Handler) GetUserInfo(ctx context.Context) (r api.GetUserInfoRes, _ error) {
return r, ht.ErrNotImplemented
}
// GetMaps implements getMaps operation.
//
// Retrieves a list of available views.
//
// GET /rest/view
func (Handler) GetMaps(ctx context.Context) (r api.GetMapsRes, _ error) {
session := ctx.(*clu.Context)
if !auth.ValidUser(auth.UserRole, false, session.User, "*Maps") {
return &api.GetMapsForbidden{}, nil
}
maps := make([]api.Map, 0)
for _, m := range GetAllViews() {
maps = append(maps, api.Map(m))
}
r = &api.Maps{Maps: maps}
return r, nil
}
// GetEnvironments implements getEnvironments operation.
//
// Retrieves the list of environments.
//
// GET /version/env
func (Handler) GetEnvironments(ctx context.Context) (r api.GetEnvironmentsRes, _ error) {
return r, ht.ErrNotImplemented
}
// GetDatabaseSessions implements getDatabaseSessions operation.
//
// Retrieve a list of user queue entries.
//
// GET /admin/database/{table}/sessions
func (Handler) GetDatabaseSessions(ctx context.Context, params api.GetDatabaseSessionsParams) (r api.GetDatabaseSessionsRes, _ error) {
return r, ht.ErrNotImplemented
}
// GetDatabaseStats implements getDatabaseStats operation.
//
// Retrieve SQL statistics.
//
// GET /admin/database/{table}/stats
func (Handler) GetDatabaseStats(ctx context.Context, params api.GetDatabaseStatsParams) (r api.GetDatabaseStatsRes, _ error) {
return r, ht.ErrNotImplemented
}
// DatabaseOperation implements databaseOperation operation.
//
// Retrieve the current status of database with the given dbid.
//
// GET /admin/database/{table_operation}
func (Handler) DatabaseOperation(ctx context.Context, params api.DatabaseOperationParams) (r api.DatabaseOperationRes, _ error) {
return r, ht.ErrNotImplemented
}
// DatabasePostOperations implements databasePostOperations operation.
//
// Initiate operations on the given dbid.
//
// POST /admin/database/{table_operation}
func (Handler) DatabasePostOperations(ctx context.Context, params api.DatabasePostOperationsParams) (r api.DatabasePostOperationsRes, _ error) {
return r, ht.ErrNotImplemented
}
// DeleteDatabase implements deleteDatabase operation.
//
// Delete the database.
//
// DELETE /admin/database/{table_operation}
func (Handler) DeleteDatabase(ctx context.Context, params api.DeleteDatabaseParams) (r api.DeleteDatabaseRes, _ error) {
return r, ht.ErrNotImplemented
}
// ShutdownServer implements shutdownServer operation.
//
// Init shutdown procedure.
//
// PUT /shutdown/{hash}
func (Handler) ShutdownServer(ctx context.Context, params api.ShutdownServerParams) (r api.ShutdownServerRes, _ error) {
session := ctx.(*clu.Context)
if !auth.ValidUser(auth.AdministratorRole, true, session.User, "") {
return &api.ShutdownServerForbidden{}, nil
}
return r, ht.ErrNotImplemented
}