Skip to content

Commit

Permalink
Add datasource description
Browse files Browse the repository at this point in the history
Signed-off-by: Vamsi Manohar <[email protected]>
  • Loading branch information
vmmusings committed Sep 22, 2023
1 parent 086bc74 commit dc2aeca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.xml.crypto.Data;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -31,6 +32,8 @@ public class DataSourceMetadata {

@JsonProperty private String name;

@JsonProperty private String description;

@JsonProperty
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
private DataSourceType connector;
Expand All @@ -39,6 +42,13 @@ public class DataSourceMetadata {

@JsonProperty private Map<String, String> properties;

public DataSourceMetadata(String name, DataSourceType connector, List<String> allowedRoles, Map<String, String> properties) {
this.name = name;
this.connector = connector;
this.properties = properties;
this.allowedRoles = allowedRoles;
}

/**
* Default OpenSearch {@link DataSourceMetadata}. Which is used to register default OpenSearch
* {@link DataSource} to {@link DataSourceService}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.identity.IdentityService;
import org.opensearch.sql.datasource.model.DataSourceMetadata;
import org.opensearch.sql.datasource.model.DataSourceType;

/** Utitlity class to serialize and deserialize objects in XContent. */
@UtilityClass
public class XContentParserUtils {
public static final String NAME_FIELD = "name";
public static final String DESCRIPTION_FIELD = "description";
public static final String CONNECTOR_FIELD = "connector";
public static final String PROPERTIES_FIELD = "properties";
public static final String ALLOWED_ROLES_FIELD = "allowedRoles";
Expand All @@ -39,6 +41,7 @@ public class XContentParserUtils {
*/
public static DataSourceMetadata toDataSourceMetadata(XContentParser parser) throws IOException {
String name = null;
String description = null;
DataSourceType connector = null;
List<String> allowedRoles = new ArrayList<>();
Map<String, String> properties = new HashMap<>();
Expand All @@ -50,6 +53,9 @@ public static DataSourceMetadata toDataSourceMetadata(XContentParser parser) thr
case NAME_FIELD:
name = parser.textOrNull();
break;
case DESCRIPTION_FIELD:
description = parser.textOrNull();
break;
case CONNECTOR_FIELD:
connector = DataSourceType.fromString(parser.textOrNull());
break;
Expand All @@ -74,7 +80,7 @@ public static DataSourceMetadata toDataSourceMetadata(XContentParser parser) thr
if (name == null || connector == null) {
throw new IllegalArgumentException("name and connector are required fields.");
}
return new DataSourceMetadata(name, connector, allowedRoles, properties);
return new DataSourceMetadata(name, description, connector, allowedRoles, properties);
}

/**
Expand Down

0 comments on commit dc2aeca

Please sign in to comment.