Skip to content

Commit

Permalink
DXCDT-282: Support suspended log streams (#725)
Browse files Browse the repository at this point in the history
* Unignoring suspended log streams from managment

* Adding tests

* Adding e2e for suspended log streams, updating recordings, adding errors to docs

* Removing console log

* Update test/e2e/e2e_recordings.md

Co-authored-by: Rita Zerrizuela <zeta@widcket.com>

---------

Co-authored-by: Will Vedder <will.vedder@okta.com>
Co-authored-by: Rita Zerrizuela <zeta@widcket.com>
  • Loading branch information
3 people committed Jan 30, 2023
1 parent 4a191bd commit f252e8e
Show file tree
Hide file tree
Showing 7 changed files with 2,449 additions and 3,291 deletions.
27 changes: 17 additions & 10 deletions src/tools/auth0/handlers/logStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const schema = {
},
};

type LogStream = {
export type LogStream = {
type: 'eventbridge' | 'eventgrid' | 'datadog' | 'http' | 'splunk' | 'sumo';
name: string;
id: string;
status: 'active' | 'suspended' | 'paused';
status?: 'active' | 'suspended' | 'paused';
sink?: {
[key: string]: string | boolean;
};
Expand Down Expand Up @@ -54,29 +54,36 @@ export default class LogStreamsHandler extends DefaultAPIHandler {
return this.existing;
}

const logStreams = await this.client.logStreams.getAll({ paginate: false });

const nonSuspendedLogStreams = logStreams.filter(
(logStream: LogStream) => logStream.status !== 'suspended'
const logStreams = await this.client.logStreams.getAll({ paginate: false }).then((logStreams) =>
logStreams.map((logStream) => {
if (logStream.status === 'suspended') delete logStream.status;
return logStream;
})
);

this.existing = nonSuspendedLogStreams;
this.existing = logStreams;

return nonSuspendedLogStreams;
return logStreams;
}

async processChanges(assets: Assets): Promise<void> {
const { logStreams } = assets;
// Do nothing if not set

if (!logStreams) return;
// Figure out what needs to be updated vs created

const changes = await this.calcChanges(assets).then((changes) => {
return {
...changes,
update: changes.update.map((update: LogStream) => {
if (update.type === 'eventbridge' || update.type === 'eventgrid') {
delete update.sink;
}
if (update.status === 'suspended') {
// @ts-ignore because while status is usually expected for update payloads, it is ok to be omitted
// for suspended log streams. Setting as `active` in these instances would probably be ok
// but bit presumptuous, let suspended log streams remain suspended.
delete update.status;
}
return update;
}),
};
Expand Down
10 changes: 8 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { Tenant } from './tools/auth0/handlers/tenant';
import { Theme } from './tools/auth0/handlers/themes';
import { Page } from './tools/auth0/handlers/pages';
import { LogStream } from './tools/auth0/handlers/logStreams';

type SharedPaginationParams = {
checkpoint?: boolean;
Expand Down Expand Up @@ -116,7 +117,12 @@ export type BaseAuth0APIClient = {
getSecrets: (arg0: { id: string }) => Promise<Promise<Asset[]>>;
addSecrets: (arg0: {}, arg1: Asset) => Promise<void>;
};
logStreams: APIClientBaseFunctions;
logStreams: {
getAll: (arg0: SharedPaginationParams) => Promise<LogStream[]>;
create: (arg0: { id: string }) => Promise<LogStream>;
update: (arg0: {}, arg1: Partial<LogStream>) => Promise<LogStream>;
delete: (arg0: Asset) => Promise<void>;
};
migrations: APIClientBaseFunctions & {
getMigrations: () => Promise<{ flags: Asset[] }>;
updateMigrations: (arg0: { flags: Asset[] }) => Promise<void>;
Expand Down Expand Up @@ -232,7 +238,7 @@ export type Assets = Partial<{
policies: Asset[]; //TODO: eliminate this intermediate level for consistency
} | null;
hooks: Asset[] | null;
logStreams: Asset[] | null;
logStreams: LogStream[] | null;
migrations: Asset[] | null;
organizations: Asset[] | null;
pages: Page[] | null;
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/e2e_recordings.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ AUTH0_HTTP_RECORDINGS="record" npx ts-mocha --timeout=120000 -p tsconfig.json te
AUTH0_HTTP_RECORDINGS="record" npx ts-mocha --timeout=120000 -p tsconfig.json test/e2e/e2e.test.ts -g="AUTH0_ALLOW_DELETE is true"
```

### Common Errors When Re-Recording

- `access_denied: {"error":"access_denied","error_description":"Unauthorized"}` - The client ID/secret pair provided through `AUTH0_E2E_CLIENT_ID` and `AUTH0_E2E_CLIENT_SECRET` respectively is not valid, double-check their correct values.
- `APIError: Nock: Disallowed net connect for "auth0-deploy-cli-e2e.us.auth0.com:443/oauth/token"` - Recordings already exist for this test, will need to remove the correlating recordings file and try again. Re-recording the entire file is necessary even if HTTP request changes are additive.

## Running Tests w/ Recordings

**Run for all:**
Expand Down
Loading

0 comments on commit f252e8e

Please sign in to comment.