Пример #1
0
ElasticProfiles.Profile = function (data) {
  this.id         = Stream(s.defaultToIfBlank(data.id, ''));
  this.pluginId   = Stream(s.defaultToIfBlank(data.pluginId, ''));
  this.properties = s.collectionToJSON(Stream(s.defaultToIfBlank(data.properties, new PluginConfigurations())));
  this.parent     = Mixins.GetterSetter();
  this.etag       = Mixins.GetterSetter();
  Mixins.HasUUID.call(this);

  Validatable.call(this, data);

  this.validatePresenceOf('id');
  this.validatePresenceOf('pluginId');
  this.validateFormatOf('id', {
    format:  /^[a-zA-Z0-9_\-]{1}[a-zA-Z0-9_\-.]*$/,
    message: 'Invalid id. This must be alphanumeric and can contain underscores and periods (however, it cannot start ' +
             'with a period). The maximum allowed length is 255 characters.'
  });

  CrudMixins.AllOperations.call(this, ['refresh', 'update', 'delete', 'create'],
    {
      type:     ElasticProfiles.Profile,
      indexUrl: Routes.apiv1ElasticProfilesPath(),
      version:  ElasticProfiles.API_VERSION,
      resourceUrl(profile) {
        return Routes.apiv1ElasticProfilePath(profile.id());
      }
    }
  );
};
Пример #2
0
AuthConfigs.AuthConfig = function (data) {
  this.id         = Stream(s.defaultToIfBlank(data.id, ''));
  this.pluginId   = Stream(s.defaultToIfBlank(data.pluginId, ''));
  this.properties = s.collectionToJSON(Stream(s.defaultToIfBlank(data.properties, new PluginConfigurations())));
  this.parent     = Mixins.GetterSetter();
  this.etag       = Mixins.GetterSetter();
  Mixins.HasUUID.call(this);

  Validatable.call(this, data);

  this.validatePresenceOf('id');
  this.validatePresenceOf('pluginId');
  this.validateFormatOf('id', {
    format:  /^[a-zA-Z0-9_\-]{1}[a-zA-Z0-9_\-.]*$/,
    message: 'Invalid id. This must be alphanumeric and can contain underscores and periods (however, it cannot start ' +
             'with a period). The maximum allowed length is 255 characters.'
  });

  CrudMixins.AllOperations.call(this, ['refresh', 'update', 'delete', 'create'], {
    type:     AuthConfigs.AuthConfig,
    indexUrl: Routes.apiv1AdminSecurityAuthConfigsPath(),
    resourceUrl (authConfig) {
      return Routes.apiv1AdminSecurityAuthConfigPath(authConfig.id());
    },
    version:  AuthConfigs.API_VERSION
  });

  this.verifyConnection = () => {
    const entity = this;
    return $.Deferred(function () {
      const deferred = this;

      const jqXHR = $.ajax({
        method:      'POST',
        url:         Routes.apiv1AdminInternalVerifyConnectionPath(),
        timeout:     mrequest.timeout,
        beforeSend:  mrequest.xhrConfig.forVersion(AuthConfigs.API_VERSION),
        data:        JSON.stringify(entity, s.snakeCaser),
        contentType: 'application/json'
      });

      const didFulfill = (data, _textStatus, jqXHR) => {
        if (jqXHR.status === 200) {
          const responseEntity = AuthConfigs.AuthConfig.fromJSON(data.auth_config);
          responseEntity.etag(entity.etag());
          deferred.resolve(responseEntity);
        }
      };

      const didReject = (jqXHR, _textStatus, _errorThrown) => {
        deferred.reject(VerifyConnectionResponse(jqXHR, entity.etag()));
      };

      jqXHR.then(didFulfill, didReject);
    }).promise();
  };
};
Пример #3
0
Pipeline.Timer = function (data) {
  this.constructor.modelType = 'pipelineTimer';
  Mixins.HasUUID.call(this);
  Validatable.call(this, data);

  this.spec          = Stream(s.defaultToIfBlank(data.spec, ''));
  this.onlyOnChanges = Stream(data.onlyOnChanges);

  this.isBlank = function () {
    return s.isBlank(this.spec()) && !this.onlyOnChanges();
  };
};
Пример #4
0
EnvironmentVariables.Variable = function (data) {
  this.constructor.modelType = 'environmentVariable';
  Mixins.HasUUID.call(this);
  Validatable.call(this, data);

  this.parent = Mixins.GetterSetter();

  this.name  = Stream(s.defaultToIfBlank(data.name, ''));
  const _value = Stream(plainOrCipherValue(data));
  Mixins.HasEncryptedAttribute.call(this, {attribute: _value, name: 'value'});

  this.toJSON = function () {
    if (this.isPlainValue()) {
      return {
        name:   this.name(),
        secure: false,
        value:  this.value()
      };
    } else {
      if (this.isDirtyValue()) {
        return {
          name:   this.name(),
          secure: true,
          value:  this.value()
        };
      } else {
        return {
          name:           this.name(),
          secure:         true,
          encryptedValue: this.value()
        };
      }
    }
  };

  this.isBlank = function () {
    return s.isBlank(this.name()) && s.isBlank(this.value());
  };

  this.validatePresenceOf('name', {
    condition(property) {
      return (!s.isBlank(property.value()));
    }
  });
  this.validateUniquenessOf('name');
};
Пример #5
0
TrackingTool.Generic = function (data) {
  TrackingTool.call(this, "generic");
  Validatable.call(this, data);
  this.urlPattern = Stream(s.defaultToIfBlank(data.urlPattern, ''));
  this.regex      = Stream(s.defaultToIfBlank(data.regex, ''));

  this.validatePresenceOf('urlPattern');
  this.validateUrlPattern('urlPattern');
  this.validateWith('urlPattern', UrlPatternValidator);
  this.validatePresenceOf('regex');

  this._attributesToJSON = function () {
    return {
      urlPattern: this.urlPattern(),
      regex:      this.regex()
    };
  };
};
Пример #6
0
const PluginSetting = function (data) {
  this.pluginId   = Stream(s.defaultToIfBlank(data.pluginId, ''));
  this.configuration = s.collectionToJSON(Stream(s.defaultToIfBlank(data.configuration, new PluginConfigurations())));
  this.etag       = Mixins.GetterSetter();

  Validatable.call(this, data);
  this.validatePresenceOf('pluginId');

  CrudMixins.AllOperations.call(this, ['refresh', 'update', 'create'],
    {
      type:     PluginSetting,
      indexUrl: Routes.apiv1AdminPluginSettingsPath(),
      version:  PluginSetting.API_VERSION,
      resourceUrl(pluginSettings) {
        return Routes.apiv1AdminPluginSettingPath(pluginSettings.pluginId());
      }
    }
  );
};
Пример #7
0
PluginConfigurations.Configuration = function (data) {
  this.parent                = Mixins.GetterSetter();
  this.constructor.modelType = 'plugin-configuration';

  this.key     = Stream(s.defaultToIfBlank(data.key, ''));
  const _value = Stream(plainOrCipherValue(data));

  Mixins.HasEncryptedAttribute.call(this, {attribute: _value, name: 'value'});

  Validatable.call(this, data);

  this.displayValue = () => {
    if (this.isSecureValue()) {
      return this.value().replace(/./gi, "*");
    } else {
      return this.value();
    }
  };

  this.toJSON = function () {
    if (this.isPlainValue()) {
      return {
        key:   this.key(),
        value: this.value()
      };
    } else {
      if (this.isDirtyValue()) {
        return {
          key:     this.key(),
          "value": this.value()
        };
      } else {
        return {
          key:               this.key(),
          "encrypted_value": this.value()
        };
      }
    }
  };

};
Пример #8
0
Parameters.Parameter = function (data) {
  this.constructor.modelType = 'parameter';
  Mixins.HasUUID.call(this);
  Validatable.call(this, data);

  this.parent = Mixins.GetterSetter();

  this.name  = Stream(s.defaultToIfBlank(data.name, ''));
  this.value = Stream(s.defaultToIfBlank(data.value, ''));

  this.isBlank = function () {
    return s.isBlank(this.name()) && s.isBlank(this.value());
  };

  this.validatePresenceOf('name', {
    condition(property) {
      return (!s.isBlank(property.value()));
    }
  });
  this.validateUniquenessOf('name');
};
Пример #9
0
Artifacts.Artifact = function (data) {
  this.constructor.modelType = 'artifact';
  Mixins.HasUUID.call(this);
  Validatable.call(this, data);

  this.parent = Mixins.GetterSetter();

  this.type        = Stream(s.defaultToIfBlank(data.type, 'build'));
  this.source      = Stream(s.defaultToIfBlank(data.source, ''));
  this.destination = Stream(s.defaultToIfBlank(data.destination, ''));

  this.isBlank = function () {
    return s.isBlank(this.source()) && s.isBlank(this.destination());
  };

  this.validatePresenceOf('source', {
    condition(property) {
      return (!s.isBlank(property.destination()));
    }
  });
};
Пример #10
0
TrackingTool.Mingle = function (data) {
  TrackingTool.call(this, "mingle");
  Validatable.call(this, data);
  this.baseUrl               = Stream(s.defaultToIfBlank(data.baseUrl, ''));
  this.projectIdentifier     = Stream(s.defaultToIfBlank(data.projectIdentifier, ''));
  this.mqlGroupingConditions = Stream(s.defaultToIfBlank(data.mqlGroupingConditions, ''));

  this.validatePresenceOf('baseUrl');
  this.validateUrlPattern('baseUrl');
  this.validatePresenceOf('projectIdentifier');
  this.validatePresenceOf('mqlGroupingConditions');

  this._attributesToJSON = function () {
    return {
      baseUrl:               this.baseUrl(),
      projectIdentifier:     this.projectIdentifier(),
      mqlGroupingConditions: this.mqlGroupingConditions()
    };
  };

};
Пример #11
0
Roles.Role = function (type, data) {
  const role                 = this;
  role.constructor.modelType = 'role';

  role.name   = Stream(s.defaultToIfBlank(data.name, ''));
  role.type   = Stream(type);
  role.parent = Mixins.GetterSetter();
  role.etag   = Mixins.GetterSetter();
  role.errors = ErrorsFromJSON(data);

  Mixins.HasUUID.call(this);
  Validatable.call(this, data);

  role.validatePresenceOf('name');
  role.validatePresenceOf('type');

  role.isPluginRole = function () {
    return role.type() === 'plugin';
  };

  this.toJSON = () => {
    return {
      type:       role.type(),
      name:       role.name(),
      attributes: this._attributesToJSON()
    };
  };

  CrudMixins.AllOperations.call(this, ['refresh', 'update', 'delete', 'create'], {
    type:     Roles.Role,
    indexUrl: Routes.apiv1AdminSecurityRolesPath(),
    resourceUrl (role) {
      return Routes.apiv1AdminSecurityRolePath(role.name());
    },
    version:  Roles.API_VERSION
  });
};
Пример #12
0
Файл: scms.js Проект: cv/gocd
SCMs.SCM = function (data) {
  Validatable.call(this, data);
  this.validatePresenceOf('name');

  this.init = function (data) {
    this.id             = Stream(s.defaultToIfBlank(data.id));
    this.name           = Stream(s.defaultToIfBlank(data.name, ''));
    this.autoUpdate     = Stream(s.defaultToIfBlank(data.auto_update, true));
    this.pluginMetadata = Stream(new SCMs.SCM.PluginMetadata(data.plugin_metadata || {}));
    this.configuration  = s.collectionToJSON(Stream(SCMs.SCM.Configurations.fromJSON(data.configuration || {})));
    this.errors         = Stream(new Errors(data.errors));
  };

  this.init(data);

  this.reInitialize = function (data) {
    this.init(data);
  };

  this.clone = function () {
    return new SCMs.SCM(JSON.parse(JSON.stringify(this)));
  };

  this.toJSON = function () {
    /* eslint-disable camelcase */
    return {
      id:              this.id(),
      name:            this.name(),
      auto_update:     this.autoUpdate(),
      plugin_metadata: this.pluginMetadata().toJSON(),
      configuration:   this.configuration
    };
    /* eslint-enable camelcase */
  };

  this.update = function () {
    const entity = this;

    const config = (xhr) => {
      xhr.setRequestHeader("Content-Type", "application/json");
      xhr.setRequestHeader("Accept", "application/vnd.go.cd.v1+json");
      xhr.setRequestHeader("If-Match", SCMs.scmIdToEtag[entity.id()]);
    };

    return $.Deferred(function () {
      const deferred = this;

      const jqXHR = $.ajax({
        method:      'PATCH',
        url:         Routes.apiv1AdminScmPath({material_name: entity.name()}), //eslint-disable-line camelcase
        background:  false,
        beforeSend:  config,
        data:        JSON.stringify(entity),
        contentType: 'application/json'
      });

      const callback = (data, _textStatus, jqXHR) => {
        if (jqXHR.status === 200) {
          SCMs.scmIdToEtag[data.id] = jqXHR.getResponseHeader('ETag');
        }
        deferred.resolve(new SCMs.SCM(data));
      };

      const errback = ({responseJSON}) => {
        deferred.reject(responseJSON);
      };

      jqXHR.then(callback, errback);

    }).promise();


  };

  this.create = function () {
    const entity = this;

    return $.Deferred(function () {
      const deferred = this;

      const jqXHR = $.ajax({
        method:      'POST',
        url:         Routes.apiv1AdminScmsPath(),
        background:  false,
        beforeSend:  mrequest.xhrConfig.forVersion('v1'),
        data:        JSON.stringify(entity),
        contentType: 'application/json'
      });

      const resolve = (data, _textStatus, jqXHR) => {
        if (jqXHR.status === 200) {
          SCMs.scmIdToEtag[data.id] = jqXHR.getResponseHeader('ETag');
        }
        deferred.resolve(new SCMs.SCM(data));
      };

      const errback = ({responseJSON}) => {
        deferred.reject(responseJSON);
      };

      jqXHR.then(resolve, errback);

    }).promise();
  };
};
Пример #13
0
const Pipeline = function (data) {
  this.constructor.modelType = 'pipeline';
  Mixins.HasUUID.call(this);
  Validatable.call(this, data);

  this.name                  = Stream(data.name);
  this.enablePipelineLocking = Stream(data.enablePipelineLocking);
  this.templateName          = Stream(s.defaultToIfBlank(data.templateName, ''));
  this.labelTemplate         = Stream(s.defaultToIfBlank(data.labelTemplate, ''));
  this.template              = Stream(data.template);
  this.timer                 = Stream(s.defaultToIfBlank(data.timer, new Pipeline.Timer({})));
  this.timer.toJSON          = function () {
    const timer = this();

    if (timer && timer.isBlank()) {
      return null;
    }

    return timer;
  };
  this.environmentVariables  = s.collectionToJSON(Stream(s.defaultToIfBlank(data.environmentVariables, new EnvironmentVariables())));
  this.parameters            = s.collectionToJSON(Stream(s.defaultToIfBlank(data.parameters, new Parameters())));
  this.materials             = s.collectionToJSON(Stream(s.defaultToIfBlank(data.materials, new Materials())));
  this.trackingTool          = Stream(data.trackingTool);
  this.trackingTool.toJSON   = function () {
    const value = this();
    if (value) {
      return value.toJSON();
    } else {
      return null;
    }
  };
  this.stages                = s.collectionToJSON(Stream(s.defaultToIfBlank(data.stages, new Stages())));

  this.validatePresenceOf('labelTemplate');
  this.validateFormatOf('labelTemplate', {
    format:  /(([a-zA-Z0-9_\-.!~*'()#:])*[$#]\{[a-zA-Z0-9_\-.!~*'()#:]+(\[:(\d+)])?}([a-zA-Z0-9_\-.!~*'()#:])*)+/,
    message: "Label should be composed of alphanumeric text, it may contain the build number as ${COUNT}, it may contain a material revision as ${<material-name>} or ${<material-name>[:<length>]}, or use params as #{<param-name>}"
  });
  this.validateAssociated('materials');
  this.validateAssociated('environmentVariables');
  this.validateAssociated('parameters');
  this.validateAssociated('stages');
  this.validateAssociated('trackingTool');

  this.update = function (etag, extract) {
    const config = (xhr) => {
      xhr.setRequestHeader("Content-Type", "application/json");
      xhr.setRequestHeader("Accept", "application/vnd.go.cd.v3+json");
      xhr.setRequestHeader("If-Match", etag);
    };

    const entity = this;

    return $.Deferred(function () {
      const deferred = this;

      const jqXHR = $.ajax({
        method:      'PUT',
        url:         Routes.apiv3AdminPipelinePath({pipeline_name: entity.name()}), //eslint-disable-line camelcase
        timeout:     mrequest.timeout,
        beforeSend:  config,
        data:        JSON.stringify(entity, s.snakeCaser),
        contentType: false
      });

      jqXHR.then((_data, _textStatus, jqXHR) => {
        deferred.resolve(extract(jqXHR));
      });

      jqXHR.fail(({responseJSON}, _textStatus, _error) => {
        deferred.reject(responseJSON);
      });

      jqXHR.always(m.redraw);

    }).promise();


  };

  this.isFirstStageAutoTriggered = function () {
    return this.stages().countStage() === 0 ? true : this.stages().firstStage().approval().isSuccess();
  };
};