packages/udaru-core/lib/ops/policyOps.js
function createPolicy (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, version, name, organizationId, statements } = params

      Joi.validate({ id, version, name, organizationId, statements }, validationRules.createPolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))
        insertPolicies(db, [{
          id: id,
          version: version,
          name: name,
          org_id: organizationId,
          statements: statements
        }], (err, result) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict('policy already exists'))
          if (err) return cb(Boom.badImplementation(err))

          policyOps.readPolicy({ id: result.rows[0].id, organizationId }, cb)
        })
      })

      return promise
    }
function createPolicy (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, version, name, organizationId, statements } = params

      Joi.validate({ id, version, name, organizationId, statements }, validationRules.createPolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))
        insertPolicies(db, [{
          id: id,
          version: version,
          name: name,
          org_id: organizationId,
          statements: statements
        }], (err, result) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict('policy already exists'))
          if (err) return cb(Boom.badImplementation(err))

          policyOps.readPolicy({ id: result.rows[0].id, organizationId }, cb)
        })
      })

      return promise
    }
function createPolicy ( params , cb ) { let promise = null if ( typeof cb !== 'function' ) [ promise , cb ] = asyncify ( ) const { id , version , name , organizationId , statements } = params Joi . validate ( { id , version , name , organizationId , statements } , validationRules . createPolicy , function ( err ) { if ( err ) return cb ( Boom . badRequest ( err ) ) insertPolicies ( db , [ { id : id , version : version , name : name , org_id : organizationId , statements : statements } ] , ( err , result ) => { if ( utils . isUniqueViolationError ( err ) ) return cb ( Boom . conflict ( 'policy already exists' ) ) if ( err ) return cb ( Boom . badImplementation ( err ) ) policyOps . readPolicy ( { id : result . rows [ 0 ] . id , organizationId } , cb ) } ) } ) return promise }
Creates a new policy

@param  {Object}   params { id, version, name, organizationId, statements }
@param  {Function} cb
Creates a new policy