-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add stub config to api be-1276 (#120)
* add stub config to api * remove openmeter api token and fix up stub usage
- Loading branch information
Showing
6 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package apiv1 | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
"github.com/beam-cloud/beta9/internal/auth" | ||
"github.com/beam-cloud/beta9/internal/repository" | ||
"github.com/beam-cloud/beta9/internal/types" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
type StubGroup struct { | ||
routerGroup *echo.Group | ||
config types.AppConfig | ||
backendRepo repository.BackendRepository | ||
} | ||
|
||
func NewStubGroup(g *echo.Group, backendRepo repository.BackendRepository, config types.AppConfig) *StubGroup { | ||
group := &StubGroup{routerGroup: g, | ||
backendRepo: backendRepo, | ||
config: config, | ||
} | ||
|
||
g.GET("/", group.ListStubs) | ||
|
||
return group | ||
} | ||
|
||
func (g *StubGroup) ListStubs(ctx echo.Context) error { | ||
cc, _ := ctx.(*auth.HttpAuthContext) | ||
if cc.AuthInfo.Token.TokenType != types.TokenTypeClusterAdmin { | ||
return echo.NewHTTPError(http.StatusUnauthorized) | ||
} | ||
|
||
var filters types.StubFilter | ||
if err := ctx.Bind(&filters); err != nil { | ||
return echo.NewHTTPError(http.StatusBadRequest, "Failed to decode query parameters") | ||
} | ||
|
||
if stubs, err := g.backendRepo.ListStubs(ctx.Request().Context(), filters); err != nil { | ||
log.Println(err) | ||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to list stubs") | ||
} else { | ||
return ctx.JSON(http.StatusOK, stubs) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,3 +137,6 @@ monitoring: | |
idleConnTimeout: 10s | ||
dialTimeout: 2s | ||
keepAlive: 30s | ||
openmeter: | ||
serverUrl: "" | ||
apiKey: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters