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

      Joi.validate(params, validationRules.createSharedPolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))

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

        insertSharedPolicies(db, [{
          id: id,
          version: version,
          name: name,
          statements: statements
        }], (err, result) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict('policy already exists'))
          if (err) return cb(err)

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

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

      Joi.validate(params, validationRules.createSharedPolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))

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

        insertSharedPolicies(db, [{
          id: id,
          version: version,
          name: name,
          statements: statements
        }], (err, result) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict('policy already exists'))
          if (err) return cb(err)

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

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

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