Skip to content

Commit

Permalink
Merge pull request CESNET#3145 from Johaney-s/csv_header
Browse files Browse the repository at this point in the history
Csv option for namespace configuration
  • Loading branch information
Vojtech-Sassmann authored Apr 1, 2021
2 parents 33469f4 + 6cc21f3 commit c6b2e92
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ public class NamespaceRules {

private String namespaceName;
private String defaultEmail;
private String csvGenHeader;
private String csvGenPlaceholder;
private Set<String> requiredAttributes;
private Set<String> optionalAttributes;

public NamespaceRules(String namespaceName, String defaultEmail, Set<String> requiredAttributes, Set<String> optionalAttributes) {
this.namespaceName = namespaceName;
this.defaultEmail = defaultEmail;
this.requiredAttributes = requiredAttributes;
this.optionalAttributes = optionalAttributes;
}
public NamespaceRules() {}

public String getNamespaceName() {
return namespaceName;
Expand Down Expand Up @@ -70,4 +67,20 @@ public String getDefaultEmail() {
public void setDefaultEmail(String defaultEmail) {
this.defaultEmail = defaultEmail;
}

public String getCsvGenHeader() {
return csvGenHeader;
}

public void setCsvGenHeader(String csvGenHeader) {
this.csvGenHeader = csvGenHeader;
}

public String getCsvGenPlaceholder() {
return csvGenPlaceholder;
}

public void setCsvGenPlaceholder(String csvGenPlaceholder) {
this.csvGenPlaceholder = csvGenPlaceholder;
}
}
6 changes: 6 additions & 0 deletions perun-base/src/test/resources/sponsored-accounts-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
# default_email - this field determines, which email will be set as a preferred attribute, for the generated sponsored
# user. If this value is not specified, it fallbacks to '[email protected]'
# csv_gen_header - this field defines the csv format used for parsing data.
# csv_gen_placeholder - this field contains placeholder for the used csv format.
# required_attributes - fields from the SponsoredUserData class, which are required for the given namespace during the
# creation of a sponsorship. Allowed values are fields of the SponsoredUserData class. This
# should be mainly used in GUI to determine, which items should be visible in the dialog. But, it
Expand Down Expand Up @@ -39,12 +41,16 @@ namespaces:

dummy:
default_email: "[email protected]"
csv_gen_header: ""
csv_gen_placeholder: ""
required_attributes: []
optional_attributes:
- password

dummy_with_login:
default_email: "[email protected]"
csv_gen_header: ""
csv_gen_placeholder: ""
required_attributes:
- login
optional_attributes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,24 @@ private Set<NamespaceRules> loadNamespacesRulesFromJsonNode(JsonNode rootNode) {
String namespaceName = namespacesNames.next();
JsonNode namespaceNode = namespacesNodes.get(namespaceName);
JsonNode defaultEmail = namespaceNode.get("default_email");
JsonNode csvGenHeader = namespaceNode.get("csv_gen_header");
JsonNode csvGenPlaceholder = namespaceNode.get("csv_gen_placeholder");
JsonNode requiredAttributesNode = namespaceNode.get("required_attributes");
JsonNode optionalAttributesNode = namespaceNode.get("optional_attributes");
Set<String> requiredAttributes = objectMapper.convertValue(requiredAttributesNode, new TypeReference<>() {});
Set<String> optionalAttributes = objectMapper.convertValue(optionalAttributesNode, new TypeReference<>() {});

rules.add(new NamespaceRules(namespaceName, defaultEmail.asText(), requiredAttributes, optionalAttributes));
NamespaceRules namespaceRules = new NamespaceRules();
namespaceRules.setNamespaceName(namespaceName);
namespaceRules.setDefaultEmail(defaultEmail.asText());
namespaceRules.setRequiredAttributes(requiredAttributes);
namespaceRules.setOptionalAttributes(optionalAttributes);
if (!csvGenHeader.isNull())
namespaceRules.setCsvGenHeader(csvGenHeader.asText());
if (!csvGenPlaceholder.isNull())
namespaceRules.setCsvGenPlaceholder(csvGenPlaceholder.asText());

rules.add(namespaceRules);
}

return rules;
Expand Down
2 changes: 2 additions & 0 deletions perun-openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,8 @@ components:
type: object
properties:
defaultEmail: { type: string }
csvGenHeader: { type: string }
csvGenPlaceholder: { type: string }
namespaceName: { type: string }
requiredAttributes:
type: array
Expand Down

0 comments on commit c6b2e92

Please sign in to comment.