Skip to content
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

DXCDT-282: Support suspended log streams #725

Merged
merged 8 commits into from
Jan 30, 2023
32 changes: 21 additions & 11 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,39 @@ export default class LogStreamsHandler extends DefaultAPIHandler {
return this.existing;
}

const logStreams = await this.client.logStreams.getAll({ paginate: false });
const logStreams = await this.client.logStreams
.getAll({ paginate: false })
.then((logStreams) => {
console.log(logStreams);
willvedd marked this conversation as resolved.
Show resolved Hide resolved
return logStreams.map((logStream) => {
if (logStream.status === 'suspended') delete logStream.status;
return logStream;
});
});

const nonSuspendedLogStreams = logStreams.filter(
(logStream: LogStream) => logStream.status !== 'suspended'
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this line allows us to unignore suspended log streams.

this.existing = logStreams;

this.existing = nonSuspendedLogStreams;

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;
willvedd marked this conversation as resolved.
Show resolved Hide resolved
}
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>;
};
Comment on lines +120 to +125
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies stricter type the Auth0 Management API when working with log streams. This is important because I do a lot of checking against the status field so want to make sure it's correct.

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
willvedd marked this conversation as resolved.
Show resolved Hide resolved
- `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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While re-recording the E2E tests, I came against these errors. I seem to always forget how to go through this process so any documentation is helpful to jog my memory.


## Running Tests w/ Recordings

**Run for all:**
Expand Down
Loading