<commit_before>/*
 * Copyright 2017 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.northernwall.hadrian.handlers.vip;

import com.northernwall.hadrian.config.Config;
import com.northernwall.hadrian.config.ConfigHelper;
import com.northernwall.hadrian.handlers.routing.Http400BadRequestException;
import com.northernwall.hadrian.handlers.vip.dao.PostVipData;

/**
 *
 * @author Richard
 */
public class VipValidator {
    private final ConfigHelper configHelper;

    public VipValidator(ConfigHelper configHelper) {
        this.configHelper = configHelper;
    }
    
    public String checkVipName(PostVipData data) throws Http400BadRequestException {
        String dns = data.dns;
        if (dns == null || dns.isEmpty()) {
            throw new Http400BadRequestException("VIP name is missing");
        }
        dns = dns.trim();
        if (dns == null || dns.isEmpty()) {
            throw new Http400BadRequestException("VIP name is missing");
        }
        
        if (!dns.matches("^[a-zA-Z0-9/-]+$")) {
            throw new Http400BadRequestException("VIP name contains an illegal character");
        }
        
        Config config = configHelper.getConfig();
        for (String dataCenter : config.dataCenters) {
            if (dns.endsWith("-" + dataCenter)) {
                throw new Http400BadRequestException("VIP name can not end in -" + dataCenter);
            }
        }
        
        if (dns.length() < 2) {
            throw new Http400BadRequestException("VIP name is to short, minimum is 2");
        }
        
        if (dns.length() > 45) {
            throw new Http400BadRequestException("VIP name is to long, maximum is 45");
        }
        return dns;
    }

}
<commit_msg>Remove the ends with DC check<commit_after>/*
 * Copyright 2017 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.northernwall.hadrian.handlers.vip;

import com.northernwall.hadrian.config.Config;
import com.northernwall.hadrian.config.ConfigHelper;
import com.northernwall.hadrian.handlers.routing.Http400BadRequestException;
import com.northernwall.hadrian.handlers.vip.dao.PostVipData;

/**
 *
 * @author Richard
 */
public class VipValidator {

    private final ConfigHelper configHelper;

    public VipValidator(ConfigHelper configHelper) {
        this.configHelper = configHelper;
    }

    public String checkVipName(PostVipData data) throws Http400BadRequestException {
        String dns = data.dns;
        if (dns == null || dns.isEmpty()) {
            throw new Http400BadRequestException("VIP name is missing");
        }
        dns = dns.trim();
        if (dns == null || dns.isEmpty()) {
            throw new Http400BadRequestException("VIP name is missing");
        }

        if (!dns.matches("^[a-zA-Z0-9/-]+$")) {
            throw new Http400BadRequestException("VIP name contains an illegal character");
        }

        //Config config = configHelper.getConfig();
        //for (String dataCenter : config.dataCenters) {
        //    if (dns.endsWith("-" + dataCenter)) {
        //        throw new Http400BadRequestException("VIP name can not end in -" + dataCenter);
        //    }
        //}
        
        if (dns.length() < 2) {
            throw new Http400BadRequestException("VIP name is to short, minimum is 2");
        }

        if (dns.length() > 45) {
            throw new Http400BadRequestException("VIP name is to long, maximum is 45");
        }
        return dns;
    }

}

{'fraction_non_alphanumeric': 0.09699570815450644, 'fraction_numerical': 0.017167381974248927, 'mean_word_length': 2.3873546511627906, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5528435', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1263, 'n_words': 393}