Skip to content

Commit

Permalink
Merge branch 'main' into errorcomponent
Browse files Browse the repository at this point in the history
Signed-off-by: Lu Yu <nluyu@amazon.com>
  • Loading branch information
BionIT authored Apr 16, 2024
2 parents 210a25c + ce85706 commit cec0380
Show file tree
Hide file tree
Showing 21 changed files with 788 additions and 149 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple Datasource] Refactor data source selector component to include placeholder and add tests ([#6372](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6372))
- Replace control characters before logging ([#6402](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6402))
- [Dynamic Configurations] Improve dynamic configurations by adding cache and simplifying client fetch ([#6364](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6364))
- [CSP Handler] Update CSP handler to only query and modify frame ancestors instead of all CSP directives ([#6398](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6398))
- [MD] Add OpenSearch cluster group label to top of single selectable dropdown ([#6400](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6400))
- [Multiple Datasource] Add error state to all data source menu components to show error component and consolidate all fetch errors ([#6440](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6440))
- [Workspace] Support workspace in saved objects client in server side. ([#6365](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6365))
Expand All @@ -115,6 +116,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple Datasource] Fix sslConfig for multiple datasource to handle when certificateAuthorities is unset ([#6282](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6282))
- [BUG][Multiple Datasource]Fix bug in data source aggregated view to change it to depend on displayAllCompatibleDataSources property to show the badge value ([#6291](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6291))
- [BUG][Multiple Datasource]Read hideLocalCluster setting from yml and set in data source selector and data source menu ([#6361](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6361))
- [BUG][Multiple Datasource] Refactor read-only component to cover more edge cases ([#6416](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6416))
- [BUG] Fix for checkForFunctionProperty so that order does not matter ([#6248](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6248))
- [BUG][Multiple Datasource] Validation succeed as long as status code in response is 200 ([#6399](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6399))

Expand Down Expand Up @@ -150,6 +152,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Remove unused Sass in `tile_map` plugin ([#4110](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4110))
- [Multiple Datasource] Move data source selectable to its own folder, fix test and a few type errors for data source selectable component ([#6287](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6287))
- Remove KUI usage in `disabled_lab_visualization` ([#5462](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5462))
- [Multiple Datasource] Remove duplicate data source attribute interface from `data_source_management` ([#6437](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6437))

### 🔩 Tests

Expand Down
95 changes: 95 additions & 0 deletions DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ This guide applies to all development within the OpenSearch Dashboards project a
- [TypeScript/JavaScript](#typescriptjavascript)
- [React](#react)
- [API endpoints](#api-endpoints)
- [Submit pull request](#submit-pull-request)
- [Before submit pull request](#before-submit-a-pull-request)
- [Best practices for pull request](#best-practices-for-pull-request)

> To view these docs and all the readme's in this repository as webpages, visit https://opensearch-project.github.io/OpenSearch-Dashboards/docs/index.html#/
Expand Down Expand Up @@ -675,6 +678,42 @@ if (width < 300) {
}
```
#### Avoid using `var` to declare variables
Use `const` by default, and never use `var` to declare variables. `const` and `let` are block scoped, like variables in most other languages. `var` in JavaScript is function scoped, which can cause difficult to understand bugs.

#### Avoid using the `Array` constructor
Do not use the Array() constructor, with or without new. It has confusing and contradictory usage.

Instead, always use bracket notation to initialize arrays.

```js
// good
const arr = [2];

// bad
const arr = new Array(2); //[undefined, undefined]
const arr = new Array(2, 3); //[2, 3];
```

#### Avoid line continuations in string literals
Do not use line continuations (that is, ending a line inside a string literal with a backslash) in either ordinary or template string literals. Even though ES5 allows this, it can lead to tricky errors if any trailing whitespace comes after the slash, and is less obvious to readers.

```js
// good
const LONG_STRING = 'This is a very very very very very very long string. ' +
'It does not contain long stretches of spaces because it uses ' +
'concatenated strings.';

// bad
const LONG_STRING = 'This is a very very very very very very very long string. \
It inadvertently contains long stretches of spaces due to how the \
continued lines are indented.';
```

#### Avoid using `@ts-ignore`
Do not use @ts-ignore nor the variants @ts-expect-error or @ts-nocheck. They superficially seem to be an easy way to fix a compiler error, but in practice, a specific compiler error is often caused by a larger problem that can be fixed more directly.


#### Use native ES2015 module syntax

Module dependencies should be written using native ES2015 syntax wherever
Expand Down Expand Up @@ -938,6 +977,31 @@ Do not use setters, they cause more problems than they can solve.
[sideeffect]: http://en.wikipedia.org/wiki/Side_effect_(computer_science)
#### Use strict equality checks
Use strict equality operators (===/!==) to compare the operands. The equality (==/!=) operator will try to convert and compare operands that are of different types causing unexpected behavior.
#### Use uppercase for constants
Constants should be declared in uppercase letters especially for primitives because they are truly immutable.
#### Use named exports
Use named exports instead of default exports. Default exports provide no canonical name, which makes central maintenance difficult with relatively little benefit to code owners, including potentially decreased readability.
```js
// good
export class User { ... }

// bad
export default class User { ... }
// why bad
import User from './user'; // Legal.
import Group from './user'; // Also legal.
```
#### Use single quotes for string literals
Ordinary string literals are delimited with single quotes ('), rather than double quotes ("). If a string contains a single quote character, consider using a template string to avoid having to escape the quote.
#### Attribution
Parts of the JavaScript developer guide were initially forked from the
Expand Down Expand Up @@ -986,3 +1050,34 @@ POST /api/opensearch-dashboards/index_patterns
]
}
```
## Submit pull request
### Before submit a pull request
First-time contributors should head to the [contributing guide](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/CONTRIBUTING.md) to get started.
Make sure your pull request adheres to our [code guidelines](#code-guidelines).
Follow [testing guideline](https://github.com/opensearch-project/OpenSearch-Dashboards/blob/main/TESTING.md) about current tests in the repo, writing tests and running tests locally.
### Best practices for pull request
We deeply appreciate everyone who takes the time to make a contribution. We will review all contributions as quickly as possible. As a best practice, opening an issue and discussing your change before you make it is the best way to smooth the PR process. This will prevent a rejection because someone else is already working on the problem, or because the solution is incompatible with the architectural direction.
In addition, below are a few best practices so your pull request gets reviewed quickly.
#### Mark unfinished pull requests
It's okay to submit a draft PR if you want to solicit reviews before the implementation of your pull request is complete. To do that, you may add a `WIP` or `[WIP]` prefix to your pull request title and [convert the PR to a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft)
#### Clear title and description for pull request
Make sure that the title of the PR is easy to understand about the intent, and it should not conflict with the PR description or the implementation. To help reviewers get better context of the PR, we suggest to have a clear summary of the intent of the change as well as detailed steps for the manual tests that have been performed for this PR.
#### Small pull request is better
Small pull requests get reviewed faster and are more likely to be correct than big ones. Breaking your change into small pull requests while keep in mind that every pull request should be useful on its own.
#### Check and fix tests
The repository uses codecov to gather coverage information, contributors submitting pull requests to the codebase are required to ensure that their code changes include appropriate testing coverage. Very few pull requests can touch the code and NOT touch the tests.
If you don't know how to test a feature, please ask! Pull requests lacking sufficient testing coverage may be subject to delays in review or rejection until adequate tests are provided.
The repository has automated test workflows, and contributors submitting pull requests are required to check the failed test workflows and fix the tests related to their code change. If flaky test is identified, please ask a maintainer to retry the workflow.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import React from 'react';
import React, { useState, useMemo } from 'react';
import {
EuiBasicTable,
EuiPageBody,
Expand Down Expand Up @@ -34,8 +34,11 @@ export const DataSourceViewExample = ({
dataSourceEnabled,
setActionMenu,
dataSourceManagement,
notifications,
savedObjects,
}: DataSourceViewExampleProps) => {
const DataSourceMenu = dataSourceManagement.ui.getDataSourceMenu<DataSourceViewConfig>();
const [selectedDataSources, setSelectedDataSources] = useState<string[]>([]);
const data: ComponentProp[] = [
{
name: 'savedObjects',
Expand Down Expand Up @@ -68,19 +71,31 @@ export const DataSourceViewExample = ({
},
];

const renderDataSourceComponent = useMemo(() => {
return (
<DataSourceMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceView'}
componentConfig={{
notifications,
savedObjects: savedObjects.client,
fullWidth: false,
activeOption: [{ id: '' }],
dataSourceFilter: (ds) => {
return true;
},
onSelectedDataSources: (ds) => {
setSelectedDataSources(ds);
},
}}
/>
);
}, [setActionMenu, notifications, savedObjects]);

return (
<EuiPageBody component="main">
<EuiPageHeader>
{dataSourceEnabled && (
<DataSourceMenu
setMenuMountPoint={setActionMenu}
componentType={'DataSourceView'}
componentConfig={{
fullWidth: false,
activeOption: [{ id: 'example id', label: 'example data source' }],
}}
/>
)}
{dataSourceEnabled && renderDataSourceComponent}
<EuiPageHeaderSection>
<EuiTitle size="l">
<h1>Data Source View Example</h1>
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/csp_handler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A OpenSearch Dashboards plugin

This plugin is to support updating Content Security Policy (CSP) rules dynamically without requiring a server restart. It registers a pre-response handler to `HttpServiceSetup` which can get CSP rules from a dependent plugin `applicationConfig` and then rewrite to CSP header. Users are able to call the API endpoint exposed by the `applicationConfig` plugin directly, e.g through CURL. Currently there is no new OSD page for ease of user interactions with the APIs. Updates to the CSP rules will take effect immediately. As a comparison, modifying CSP rules through the key `csp.rules` in OSD YAML file would require a server restart.
This plugin is to support updating the `frame-ancestors` directive in Content Security Policy (CSP) rules dynamically without requiring a server restart. It registers a pre-response handler to `HttpServiceSetup` which can get the `frame-ancestors` directive from a dependent plugin `applicationConfig` and then rewrite to CSP header. It will not change other directives. Users are able to call the API endpoint exposed by the `applicationConfig` plugin directly, e.g through CURL. The configuration key is `csp.rules.frame-ancestors`. Currently there is no new OSD page for ease of user interactions with the APIs. Updates to the `frame-ancestors` directive will take effect immediately. As a comparison, modifying CSP rules through the key `csp.rules` in OSD YAML file would require a server restart.

By default, this plugin is disabled. Once enabled, the plugin will first use what users have configured through `applicationConfig`. If not configured, it will check whatever CSP rules aggregated by the values of `csp.rules` from OSD YAML file and default values. If the aggregated CSP rules don't contain the CSP directive `frame-ancestors` which specifies valid parents that may embed OSD page, then the plugin will append `frame-ancestors 'self'` to prevent Clickjacking.

Expand All @@ -23,23 +23,23 @@ Since it has a required dependency `applicationConfig`, make sure that the depen
application_config.enabled: true
```

For OSD users who want to make changes to allow a new site to embed OSD pages, they can update CSP rules through CURL. (See the README of `applicationConfig` for more details about the APIs.) **Please note that use backslash as string wrapper for single quotes inside the `data-raw` parameter. E.g use `'\''` to represent `'`**
For OSD users who want to make changes to allow a new site to embed OSD pages, they can update the `frame-ancestors` directive through CURL. (See the README of `applicationConfig` for more details about the APIs.) **Please note that use backslash as string wrapper for single quotes inside the `data-raw` parameter. E.g use `'\''` to represent `'`**

```
curl '{osd endpoint}/api/appconfig/csp.rules' -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty' --data-raw '{"newValue":"script-src '\''unsafe-eval'\'' '\''self'\''; worker-src blob: '\''self'\''; style-src '\''unsafe-inline'\'' '\''self'\''; frame-ancestors '\''self'\'' {new site}"}'
curl '{osd endpoint}/api/appconfig/csp.rules.frame-ancestors' -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty' --data-raw '{"newValue":"{new value}"}'
```

Below is the CURL command to delete CSP rules.
Below is the CURL command to delete the `frame-ancestors` directive.

```
curl '{osd endpoint}/api/appconfig/csp.rules' -X DELETE -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty'
curl '{osd endpoint}/api/appconfig/csp.rules.frame-ancestors' -X DELETE -H 'osd-xsrf: osd-fetch' -H 'Sec-Fetch-Dest: empty'
```

Below is the CURL command to get the CSP rules.
Below is the CURL command to get the `frame-ancestors` directive.

```
curl '{osd endpoint}/api/appconfig/csp.rules'
curl '{osd endpoint}/api/appconfig/csp.rules.frame-ancestors'
```

Expand Down
Loading

0 comments on commit cec0380

Please sign in to comment.