-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build checks catalog #3
Merged
dottorblaster
merged 9 commits into
trento-project:main
from
arbulu89:feature/return-catalog
Mar 18, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
936b683
Make the runner a service like interface and add ready probe
arbulu89 f3c144b
Modify the app initialization to enable UT
arbulu89 f177c8f
Create BuildCatalog function
arbulu89 ca06056
Modify the metadata ansible playbook to store in file
arbulu89 09195c4
Add get catalog endpoint
arbulu89 4b4768f
Add tests to the BuildCatalog function
arbulu89 cefefb6
Move the catalog handlers to a new file
arbulu89 c84666b
Fix ansible lint warning on copy action
arbulu89 cbcd45d
Remove runner start commented piece of code
arbulu89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
13 changes: 13 additions & 0 deletions
13
runner/ansible/roles/post-metadata/tasks/build_catalog.yml
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,13 @@ | ||
- name: Include load_facts | ||
import_role: | ||
name: load_facts | ||
|
||
- name: Store metadata | ||
include_role: | ||
name: post-metadata | ||
tasks_from: store | ||
vars: | ||
metadata_path: "{{ check_file.path }}/defaults/main.yml" | ||
loop: "{{ checks.files|sort(attribute='path') }}" | ||
loop_control: | ||
loop_var: check_file |
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,5 @@ | ||
- name: Dump catalog data fo a file | ||
copy: | ||
dest: '{{ lookup("env", "CATALOG_DESTINATION") }}' | ||
content: "{{ metadata | to_json }}" | ||
mode: '0644' |
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package runner | ||
|
||
const ( | ||
CatalogDestinationFile = "ansible/catalog.json" | ||
) | ||
|
||
type Catalog struct { | ||
Checks []*CatalogCheck `json:"checks" binding:"required"` | ||
} | ||
|
||
type CatalogCheck struct { | ||
ID string `json:"id,omitempty" binding:"required"` | ||
Name string `json:"name,omitempty" binding:"required"` | ||
Group string `json:"group,omitempty" binding:"required"` | ||
Description string `json:"description,omitempty"` | ||
Remediation string `json:"remediation,omitempty"` | ||
Implementation string `json:"implementation,omitempty"` | ||
Labels string `json:"labels,omitempty"` | ||
Premium bool `json:"premium,omitempty"` | ||
} |
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,11 @@ | ||
package runner | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func CatalogHandler(runnerService RunnerService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
c.JSON(200, runnerService.GetCatalog()) | ||
} | ||
} |
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,61 @@ | ||
package runner | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type CatalogApiTestCase struct { | ||
suite.Suite | ||
config *Config | ||
} | ||
|
||
func TestCatalogApiTestCase(t *testing.T) { | ||
suite.Run(t, new(CatalogApiTestCase)) | ||
} | ||
|
||
func (suite *CatalogApiTestCase) SetupTest() { | ||
suite.config = &Config{} | ||
} | ||
|
||
func (suite *CatalogApiTestCase) Test_GetCatalogTest() { | ||
returnedCatalog := map[string]*Catalog{ | ||
"azure": &Catalog{ | ||
Checks: []*CatalogCheck{ | ||
{ | ||
ID: "156F64", | ||
Name: "1.1.1", | ||
Group: "Corosync", | ||
Description: "description azure", | ||
Remediation: "remediation", | ||
Implementation: "implementation", | ||
Labels: "generic", | ||
Premium: false, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
mockRunnerService := new(MockRunnerService) | ||
mockRunnerService.On("GetCatalog").Return(returnedCatalog) | ||
|
||
deps := Dependencies{ | ||
mockRunnerService, | ||
} | ||
|
||
app, err := NewAppWithDeps(suite.config, deps) | ||
if err != nil { | ||
suite.T().Fatal(err) | ||
} | ||
|
||
resp := httptest.NewRecorder() | ||
req := httptest.NewRequest("GET", "/api/catalog", nil) | ||
app.webEngine.ServeHTTP(resp, req) | ||
|
||
expectedJson, _ := json.Marshal(returnedCatalog) | ||
suite.Equal(200, resp.Code) | ||
suite.JSONEq(string(expectedJson), resp.Body.String()) | ||
} |
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,15 @@ | ||
package runner | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func HealthHandler(c *gin.Context) { | ||
c.JSON(200, map[string]string{"status": "ok"}) | ||
} | ||
|
||
func ReadyHandler(runnerService RunnerService) gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
c.JSON(200, map[string]bool{"ready": runnerService.IsCatalogReady()}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns always
200
state, even though you request the catalog and it is not ready.We can modify it of course