-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Reporting] Separate internal and public API endpoints in Reporting #162288
[Reporting] Separate internal and public API endpoints in Reporting #162288
Conversation
@@ -110,9 +108,7 @@ export class ReportingAPIClient implements IReportingAPI { | |||
} | |||
|
|||
public async deleteReport(jobId: string) { | |||
return await this.http.delete<void>(`${API_LIST_URL}/delete/${jobId}`, { | |||
asSystemRequest: true, | |||
}); |
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.
deleting a report is manually done by the user: not a system request
@@ -151,47 +147,49 @@ export class ReportingAPIClient implements IReportingAPI { | |||
} | |||
|
|||
public async getInfo(jobId: string) { | |||
const report: ReportApiJSON = await this.http.get(`${API_LIST_URL}/info/${jobId}`, { | |||
asSystemRequest: true, |
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.
getting report info is manually done by the user: not a system request
|
||
public getServerBasePath = () => this.http.basePath.serverBasePath; | ||
|
||
public verifyBrowser() { | ||
return this.http.post<DiagnoseResponse>(`${API_BASE_URL}/diagnose/browser`, { | ||
asSystemRequest: true, |
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.
using the diagnostic tool is manually done by the user: not a system request
props.reportType, | ||
this.props.apiClient.getDecoratedJobParams(this.props.getJobParams(true)) | ||
); | ||
return url.resolve(window.location.href, relativePath); // FIXME: '(from: string, to: string): string' is deprecated |
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.
I can't figure out why my editor says this line uses a deprecated signature, so the comment isn't valid
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.
Nice I'm also not seeing any issues in my editor 👍🏻
4e7152f
to
c9941b7
Compare
…-ref HEAD~1..HEAD --fix'
fffb568
to
61c611e
Compare
}); | ||
}); | ||
|
||
describe('verifyScreenCapture', () => { | ||
it('should send a post request', async () => { | ||
await apiClient.verifyScreenCapture(); | ||
|
||
expect(httpClient.post).toHaveBeenCalledWith( | ||
expect.stringContaining('/diagnose/screenshot'), | ||
expect.any(Object) |
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.
the options object was removed from the API calls for many of these, since they mistakenly were used to send the asSystemRequest
field
4305bc8
to
5122ed6
Compare
counters: Counters | ||
) { | ||
public getJobParams(): BaseParams { | ||
let jobParamsRison: null | string = null; |
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.
I've added this helper because without it, this section of code would have had to be duplicated in x-pack/plugins/reporting/server/routes/internal/generate/generate_from_jobparams.ts
and x-pack/plugins/reporting/server/routes/public/generate_from_jobparams.ts
res: KibanaResponseFactory; | ||
} | ||
|
||
export const commonJobsRouteHandlerFactory = (reporting: ReportingCore) => { |
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.
Added these helpers to avoid duplicated code in x-pack/plugins/reporting/server/routes/internal/management/jobs.ts
and x-pack/plugins/reporting/server/routes/public/jobs.ts
// TODO: find a way to abstract this using ExportTypeRegistry: it needs a new | ||
// public method to return this array | ||
// const registry = reporting.getExportTypesRegistry(); | ||
// const kibanaAccessControlTags = registry.getAllAccessControlTags(); |
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.
I'm not sure if we still care about this, I just copied this comment from x-pack/plugins/reporting/server/routes/generate/generate_from_jobparams.ts
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.
I am also tempted to remove this comment - I don't think it's really relevant anymore
@@ -7,29 +7,26 @@ | |||
|
|||
import { schema } from '@kbn/config-schema'; | |||
import { ROUTE_TAG_CAN_REDIRECT } from '@kbn/security-plugin/server'; | |||
import { promisify } from 'util'; |
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.
A file was deleted and made into 2 versions, but Github shows this as a rename, so this diff makes a good outline of the goals of this PR:
- Use constants for the route path strings
- Use helpers within route handler functions to avoid duplicated code
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.
I love the constants/routes file making everything so much clearer
props.reportType, | ||
this.props.apiClient.getDecoratedJobParams(this.props.getJobParams(true)) | ||
); | ||
return url.resolve(window.location.href, relativePath); // FIXME: '(from: string, to: string): string' is deprecated |
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.
Nice I'm also not seeing any issues in my editor 👍🏻
|
||
const API_BASE_URL_V1 = '/api/reporting/v1'; | ||
const API_BASE_GENERATE_V1 = `${API_BASE_URL_V1}/generate`; | ||
const path = INTERNAL_ROUTES.DOWNLOAD_CSV; |
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.
I love that there's the constants/routes file in this PR to reference these vs it being spread across the plugin
// TODO: find a way to abstract this using ExportTypeRegistry: it needs a new | ||
// public method to return this array | ||
// const registry = reporting.getExportTypesRegistry(); | ||
// const kibanaAccessControlTags = registry.getAllAccessControlTags(); |
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.
I am also tempted to remove this comment - I don't think it's really relevant anymore
Pinging @elastic/appex-sharedux (Team:SharedUX) |
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @tsullivan |
…lastic#162288) ## Summary Closes elastic#160827 Closes elastic#134517 Closes elastic#149942 In this PR, the following API endpoints are moved into an internal namespace: | New endpoint path | Previous | |---|---| | `/internal/reporting/diagnose/browser` | `/api/reporting/diagnose/browser` | | `/internal/reporting/diagnose/screenshot` | `/api/reporting/diagnose/screenshot` | | `/internal/reporting/generate/immediate/csv_searchsource` | `/api/reporting/v1/generate/immediate/csv_searchsource` | | `/internal/reporting/generate/{exportTypeId}` | `/api/reporting/generate/{exportTypeId}` | | `/internal/reporting/jobs/count` | `/api/reporting/jobs/count` | | `/internal/reporting/jobs/delete/{jobId}` | `/api/reporting/jobs/delete/{jobId}` | | `/internal/reporting/jobs/info/{jobId}` | `/api/reporting/jobs/info/{jobId}` | | `/internal/reporting/jobs/list` | `/api/reporting/jobs/list` | Support for the public APIs continues: | Public endpoint path | |---| | `/api/reporting/generate/{exportTypeId}` | | `/api/reporting/jobs/delete/{jobId}` | | `/api/reporting/jobs/download/{jobId}` | ## Other changes 1. Set access options on the routes 2. Removed API Counter functional tests, which were skipped to begin with. 3. Replaced functional tests with Jest integration tests. 4. Consolidated code in the generation routes by creating the `getJobParams` method of the `RequestHandler` class. 5. Added a new test for `getJobParams` 6. Consolidated code in the job management routes 7. Added new code for shared helpers in job management routes 8. Reorganized libs used for route handlers: ``` routes/lib/request_handler.ts => routes/common/generate/request_handler.ts routes/lib/job_management_pre_routing.ts => routes/common/jobs/job_management_pre_routing.ts routes/lib/jobs_query.ts => routes/common/jobs/jobs_query.ts routes/lib/get_document_payload.ts => routes/common/jobs/get_document_payload.ts routes/lib/get_counter.ts => routes/common/get_counter.ts routes/lib/authorized_user_pre_routing.ts => routes/common/authorized_user_pre_routing.ts routes/lib/get_user.ts => routes/common/get_user.ts ``` ## Release Note Updated API endpoint paths for Reporting to clarify which routes are public and which are not. Make sure that any custom script or application that uses Reporting endpoints only uses the public endpoints. --------- Co-authored-by: kibanamachine <[email protected]>
Summary
Closes #160827
Closes #134517
Closes #149942
In this PR, the following API endpoints are moved into an internal namespace:
/internal/reporting/diagnose/browser
/api/reporting/diagnose/browser
/internal/reporting/diagnose/screenshot
/api/reporting/diagnose/screenshot
/internal/reporting/generate/immediate/csv_searchsource
/api/reporting/v1/generate/immediate/csv_searchsource
/internal/reporting/generate/{exportTypeId}
/api/reporting/generate/{exportTypeId}
/internal/reporting/jobs/count
/api/reporting/jobs/count
/internal/reporting/jobs/delete/{jobId}
/api/reporting/jobs/delete/{jobId}
/internal/reporting/jobs/info/{jobId}
/api/reporting/jobs/info/{jobId}
/internal/reporting/jobs/list
/api/reporting/jobs/list
Support for the public APIs continues:
/api/reporting/generate/{exportTypeId}
/api/reporting/jobs/delete/{jobId}
/api/reporting/jobs/download/{jobId}
Other changes
getJobParams
method of theRequestHandler
class.getJobParams
Release Note
Updated API endpoint paths for Reporting to clarify which routes are public and which are not. Make sure that any custom script or application that uses Reporting endpoints only uses the public endpoints.