-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command for exporting organization audit logs (#749)
* PoC of using core API generated bindings in the cLI * add a script to fetch and generate an openAPI client for core API * remove generated client * * Just issue and HTTP query to retrieve audit logs * Use proper `net/http` methods * Update usage of client.DoPublic across the code * handle arguments * accept organization name and pass the short nameé * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update test * update mock * remove obsolete .gitignore entry * remove unused field * go fmt * undo format change * update comment and go fmt * use pointer and rename variable * fix formatting * fix tests * replace magic number by a variable * store regex in variable * new http client for the cloud APIs * break down command * go fmt * add TestGetOrganizationAuditLogs * go fmt * add TestOrganizationExportAuditLogs * use LocalCore rather than a new config entry * add TestContextGetPublicRESTAPIURL * test the --output-file flag * re-organize flags * Update cmd/cloud/organization.go Co-authored-by: Neel Dalsania <neel.dalsania@astronomer.io> * add missing import * remove redundant part of usage text * update unit test * Remove redundant information from usage and correctly set Local flags (Flags() instead of LocalFlags()) * stream the logs to the desired output rather than staging a copy * update test and mocks * remove print * remove unused variable * close buffer on error too * add unit tests * fix casing * fix test * add client name and version in headers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * never stream results to stdout + indicate the output are GZIP Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Neel Dalsania <neel.dalsania@astronomer.io>
- Loading branch information
1 parent
5234933
commit 8bf791a
Showing
22 changed files
with
443 additions
and
70 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
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
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 |
---|---|---|
@@ -1,13 +1,53 @@ | ||
package astro | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/astronomer/astro-cli/pkg/httputil" | ||
testUtil "github.com/astronomer/astro-cli/pkg/testing" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewAstroClient(t *testing.T) { | ||
client := NewAstroClient(httputil.NewHTTPClient()) | ||
assert.NotNil(t, client, "Can't create new Astro client") | ||
} | ||
|
||
func TestPrepareRESTRequest(t *testing.T) { | ||
client := NewAstroClient(httputil.NewHTTPClient()) | ||
doOpts := &httputil.DoOptions{ | ||
Path: "/test", | ||
Headers: map[string]string{ | ||
"test": "test", | ||
}, | ||
} | ||
err := client.prepareRESTRequest(doOpts) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "test", doOpts.Headers["test"]) | ||
// Test context has no token | ||
assert.Equal(t, "", doOpts.Headers["Authorization"]) | ||
} | ||
|
||
func TestDoPublicRESTQuery(t *testing.T) { | ||
mockResponse := "A REST query response" | ||
client := testUtil.NewTestClient(func(req *http.Request) *http.Response { | ||
return &http.Response{ | ||
StatusCode: 200, | ||
Body: io.NopCloser(bytes.NewBuffer([]byte(mockResponse))), | ||
Header: make(http.Header), | ||
} | ||
}) | ||
astroClient := NewAstroClient(client) | ||
doOpts := &httputil.DoOptions{ | ||
Path: "/test", | ||
Headers: map[string]string{ | ||
"test": "test", | ||
}, | ||
} | ||
resp, err := astroClient.DoPublicRESTQuery(doOpts) | ||
assert.NoError(t, err) | ||
assert.Equal(t, mockResponse, resp.Body) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.