Skip to content

Commit

Permalink
Merge pull request #1139 from shavidze/fetch-resource-by-id
Browse files Browse the repository at this point in the history
feat: fetch single resource by resource id
  • Loading branch information
mlabouardy authored Oct 30, 2023
2 parents c136d61 + 82614ef commit 81ca9d3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var configCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
c := models.Config{
AWS: []models.AWSConfig{
models.AWSConfig{
{
Name: "Demo",
Source: "CREDENTIALS_FILE",
Profile: "default",
Expand Down
2 changes: 1 addition & 1 deletion dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Follow the [Contribution Guide](https://github.com/tailwarden/komiser/blob/devel
From the Komiser root folder start the Komiser server by running:

```shell
go run \*.go start --config /path/to/config.toml
go run *.go start --config /path/to/config.toml
```

In a different terminal tab navigate to the `/dashboard` folder:
Expand Down
13 changes: 13 additions & 0 deletions handlers/resources_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,16 @@ func (handler *ApiHandler) RelationStatsHandler(c *gin.Context) {
c.JSON(http.StatusOK, out)

}

func (handler *ApiHandler) GetResourceByIdHandler(c *gin.Context) {
resourceId := c.Query("resourceId")

var resource Resource

err := handler.db.NewSelect().Model(&resource).Where("resource_id = ?", resourceId).Scan(handler.ctx)
if err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "Resource not found"})
}

c.JSON(http.StatusOK, resource)
}
1 change: 1 addition & 0 deletions internal/api/v1/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Endpoints(ctx context.Context, telemetry bool, analytics utils.Analytics, d
router.GET("/resources/export-csv", api.DownloadInventoryCSV)
router.GET("/resources/export-csv/:viewId", api.DownloadInventoryCSVForView)
router.POST("/resources/relations", api.RelationStatsHandler)
router.GET("/resources", api.GetResourceByIdHandler)

router.GET("/views", api.ListViewsHandler)
router.POST("/views", api.NewViewHandler)
Expand Down

0 comments on commit 81ca9d3

Please sign in to comment.