validateOptions: function()

in teamcity-kubernetes-plugin-server/src/main/resources/buildServerResources/kubeSettings.js [388:463]


    validateOptions: function (options){
        var isValid = true;

        var validators = {

            podTemplateMode : function () {
                var podTemplateMode = this._image['podTemplateMode'];
                if (!podTemplateMode || podTemplateMode === 'notSelected' || podTemplateMode === 'undefined') {
                    this.addOptionError('notSelectedPodTemplateMode', 'podTemplateMode');
                    isValid = false;
                }
            }.bind(this),

            dockerImage : function () {
                if (this._image['podTemplateMode'] === 'simple' && !this._image['dockerImage']) {
                    this.addOptionError('required', 'dockerImage');
                    isValid = false;
                }
            }.bind(this),

            sourceDeployment : function () {
                if (this._image['podTemplateMode'] === 'deployment-base' && !this._image['sourceDeployment']) {
                    this.addOptionError('required', 'sourceDeployment');
                    isValid = false;
                }
            }.bind(this),

            agentNamePrefix: function(){
                if (this._image['podTemplateMode'] === 'custom-pod-template' && !this._image['agentNamePrefix']) {
                    this.addOptionError('required', 'agentNamePrefix');
                    isValid = false;
                } else if (this._image['agentNamePrefix']){
                    if (!(/([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$/.test(this._image['agentNamePrefix']))){
                        this.addOptionError('invalidAgentNamePrefix', 'agentNamePrefix');
                        isValid = false;
                    }
                }
            }.bind(this),

            imageInstanceLimit: function () {
                var imageInstanceLimit = this._image['imageInstanceLimit'];
                if (imageInstanceLimit && (!$j.isNumeric(imageInstanceLimit) || imageInstanceLimit < 0 )) {
                    this.addOptionError('nonNegative', 'imageInstanceLimit');
                    isValid = false;
                }
            }.bind(this),

            agent_pool_id : function () {
                var agentPoolId = this._image['agent_pool_id'];
                if (!agentPoolId || agentPoolId === '' || agentPoolId === undefined) {
                    this.addOptionError('notSelectedAgentPool', 'agent_pool_id');
                    isValid = false;
                }
            }.bind(this),

            customPodTemplate : function () {
                var valueToValidate = this._image['customPodTemplate'];
                if (this._image['podTemplateMode'] === 'custom-pod-template' && (!valueToValidate || valueToValidate === '')) {
                    this.addOptionError('required', 'customPodTemplate');
                    isValid = false;
                }
            }.bind(this)
        };

        if (options && ! $j.isArray(options)) {
            options = [options];
        }

        this.clearOptionsErrors(options);

        (options || this._dataKeys).forEach(function(option) {
            if(validators[option]) validators[option]();
        });

        return isValid;
    },