Skip to content

Commit

Permalink
add inactive field to akto data types
Browse files Browse the repository at this point in the history
  • Loading branch information
notshivansh committed Dec 31, 2024
1 parent 9065c5d commit e16c542
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public String execute() {

private AktoDataType aktoDataType;

public String saveAktoDataType(){
public String saveAktoDataType() {

aktoDataType = AktoDataTypeDao.instance.findOne("name",name);
if(aktoDataType==null){
Expand Down Expand Up @@ -305,7 +305,8 @@ public String saveAktoDataType(){
Updates.set(AktoDataType.KEY_CONDITIONS, keyConditions),
Updates.set(AktoDataType.VALUE_CONDITIONS, valueConditions),
Updates.set(AktoDataType.OPERATOR, mainOperator),
Updates.set(AktoDataType.DATA_TYPE_PRIORITY, dataTypePriority)
Updates.set(AktoDataType.DATA_TYPE_PRIORITY, dataTypePriority),
Updates.set(AktoDataType._INACTIVE, !active)
),
options
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function DataTypes() {
valueOperator: currState.valueConditions.operator,
dataTypePriority: currState?.priority ? currState.priority.toUpperCase() : "",
...transform.convertToSensitiveData(currState.sensitiveState),

active: JSON.parse(currState.active)
}
api.saveAktoDataType(obj).then((response) => {
func.setToast(true, false, "Data type updated successfully");
Expand Down Expand Up @@ -250,11 +250,9 @@ function DataTypes() {
requiredIndicator={true}
{...errorMessage.length > 0 ? {error: errorMessage} : {}}
/>
{currState.dataType === 'Custom' ?
<Dropdown id={"active-dropdown"} menuItems={statusItems}
selected={(val) => { handleChange({ active: val }) }}
initial={currState.active} label="Active" />
: null}
<Dropdown id={"active-dropdown"} menuItems={statusItems}
selected={(val) => { handleChange({ active: val }) }}
initial={currState.active} label="Active" />
<Dropdown
menuItems={severityItems}
initial={currState.priority}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const func = {
initialObj.iconString = dataObj?.iconString || globalFunc.getSensitiveIcons(dataObj.name)
let state = func.convertDataToState(dataObj.sensitiveAlways, dataObj.sensitivePosition)
initialObj.sensitiveState = state
initialObj.active = dataObj.active.toString()
if(type === 'Custom'){
initialObj.active = dataObj.active.toString()
initialObj.operator= dataObj.operator
initialObj.creatorId= dataObj.creatorId
initialObj.skipDataTypeTestTemplateMapping = dataObj.skipDataTypeTestTemplateMapping
Expand Down
18 changes: 17 additions & 1 deletion libs/dao/src/main/java/com/akto/dao/SingleTypeInfoDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.*;

import com.akto.dao.context.Context;
import com.akto.dto.AktoDataType;
import com.akto.dto.ApiInfo;
import com.akto.dto.CollectionConditions.MethodCondition;
import com.akto.dto.rbac.UsersCollectionsList;
Expand Down Expand Up @@ -209,13 +210,17 @@ public List<String> sensitiveSubTypeNames() {
// AKTO sensitive
for (SingleTypeInfo.SubType subType: SingleTypeInfo.subTypeMap.values()) {
if (subType.isSensitiveAlways()) {
AktoDataType dt = SingleTypeInfo.getAktoDataTypeMap(Context.accountId.get()).get(subType.getName());
if (dt != null && !dt.getActive()) {
continue;
}
sensitiveSubTypes.add(subType.getName());
}
}

// Custom data type sensitive
for (CustomDataType customDataType: SingleTypeInfo.getCustomDataTypeMap(Context.accountId.get()).values()) {
if (customDataType.isSensitiveAlways()) {
if (customDataType.isSensitiveAlways() && customDataType.isActive()){
sensitiveSubTypes.add(customDataType.getName());
}
}
Expand All @@ -229,6 +234,11 @@ public List<String> sensitiveSubTypeInRequestNames() {
if (subType.isSensitiveAlways() ||
subType.getSensitivePosition().contains(SingleTypeInfo.Position.REQUEST_HEADER)
|| subType.getSensitivePosition().contains(SingleTypeInfo.Position.REQUEST_PAYLOAD)) {

AktoDataType dt = SingleTypeInfo.getAktoDataTypeMap(Context.accountId.get()).get(subType.getName());
if (dt != null && !dt.getActive()) {
continue;
}
sensitiveInRequest.add(subType.getName());
}
}
Expand All @@ -252,6 +262,12 @@ public List<String> sensitiveSubTypeInResponseNames() {
if (subType.isSensitiveAlways() ||
subType.getSensitivePosition().contains(SingleTypeInfo.Position.RESPONSE_HEADER) ||
subType.getSensitivePosition().contains(SingleTypeInfo.Position.RESPONSE_PAYLOAD)) {

AktoDataType dt = SingleTypeInfo.getAktoDataTypeMap(Context.accountId.get()).get(subType.getName());
if (dt != null && !dt.getActive()) {
continue;
}

sensitiveInResponse.add(subType.getName());
}
}
Expand Down
20 changes: 20 additions & 0 deletions libs/dao/src/main/java/com/akto/dto/AktoDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class AktoDataType {
public static final String OPERATOR = "operator";
Conditions.Operator operator;

public static final String _INACTIVE = "inactive";
private boolean inactive;

public AktoDataType() {
}
public AktoDataType(String name, boolean sensitiveAlways, List<SingleTypeInfo.Position> sensitivePosition,int timestamp, IgnoreData ignoreData, boolean redacted, boolean sampleDataFixed) {
Expand Down Expand Up @@ -152,4 +155,21 @@ public boolean validate(Object value, Object key) {
public boolean validateRaw(Object value, Object key) throws Exception {
return CustomDataType.validateRawUtility(value, key, this.keyConditions, this.valueConditions, this.operator);
}

/*
* Default is inactive:false
*/
public boolean getInactive() {
return inactive;
}

public void setInactive(boolean inactive) {
this.inactive = inactive;
}

// To send a field in frontend.
public boolean getActive() {
return !inactive;
}

}

0 comments on commit e16c542

Please sign in to comment.