How to use knox - 10 common examples

To help you get started, we’ve selected a few knox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github soldair / node-s3-npm / lib / server.js View on Github external
res.end(json);
          }
        });

      } else {
        doPublic();
      }

    } else {
      var parts = req.url.split('/');
      var bucket = parts[1];
      var tar = parts.pop();
      log('info','fetching tar ',tar,' in ',bucket,' from s3');
      
      // create client. get fili\
      var client = knox.createClient({
        key:config.key,
        secret:config.secret,
        bucket:bucket
      });

      client.get('/'+tar).on('response',function(s3res){
        log('info','response from s3 ',s3res.statusCode);
        s3res.pipe(res);
      }).end();
    }
  });
github suddenlyGiovanni / spiced_academy--p2p_chat / routes / api.js View on Github external
limits: {
        filesize: 2097152
    }
} );

//_ KNOX_ _ _ _ _ __ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
let secrets;
if ( process.env.NODE_ENV == 'production' ) {
    secrets = process.env;
    // in prod the secrets are environment variables
} else {
    secrets = require( '../config/secrets.json' );
    // secrets.json is in .gitignore
}

const client = knox.createClient( {
    key: secrets.AWS_KEY,
    secret: secrets.AWS_SECRET,
    bucket: secrets.AWS_BUCKET
} );

// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _




// ROOT OF THE API _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
router.get( '/', ( req, res ) => {
    console.log( 'API: ', 'method: GET ', '/api/' );
    res.json( { message: 'api route working fine' } );
github ripple / ripple-data-api / s3upload.js View on Github external
var utils = require('ripple-lib').utils;
var remote = ripple.Remote.from_config(config.remote);

// MySQL
var mysql = require('mysql');
var db = mysql.createConnection({
  host: config.db.mysql_ip,
  user: config.db.mysql_user,
  password: config.db.mysql_pass,
  database: config.db.mysql_db,
  multipleStatements: true
});

//Amazon S3
var knox = require('knox');
var client = knox.createClient({
  key: config.s3.key,
  secret: config.s3.secret,
  bucket: config.s3.bucket
});

// Configuration
var http_config = {};
app.configure(function(){
  extend(http_config, {
    ssl: false,
    port: 3000
  });
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.static(__dirname + '/public'));
  app.use(app.router);
github ripple / ripple-data-api / s3upload-chunk.js View on Github external
extend = require('extend'),
    fs = require('fs'),
    winston = require('winston'),
    config = require('./config'),
    model = require('./model');

var app = module.exports = express();

// Ripple client
var ripple = require('ripple-lib');
var utils = require('ripple-lib').utils;
var remote = ripple.Remote.from_config(config.remote);

//Amazon S3
var knox = require('knox');
var client = knox.createClient({
  key: config.s3.key,
  secret: config.s3.secret,
  bucket: config.s3.bucket
});

remote.on('error', function (err) {
  winston.error(err);
});

remote.on('connected', function(connection) {
  winston.info('WebSocket client connected');

  model.apply({
    status_connected: true
  });
  getLedgerIndex();
github keystonejs / keystone-storage-adapter-s3 / index.js View on Github external
function S3Adapter (options, schema) {
	this.options = assign({}, DEFAULT_OPTIONS, options.s3);

	// Support `defaultHeaders` option alias for `headers`
	// TODO: Remove me with the next major version bump
	if (this.options.defaultHeaders) {
		this.options.headers = this.options.defaultHeaders;
	}

	// Knox will check for the 'key', 'secret' and 'bucket' options.
	this.client = knox.createClient(this.options);

	// If path is specified it must be absolute.
	if (options.path != null && !pathlib.isAbsolute(options.path)) {
		throw Error('Configuration error: S3 path must be absolute');
	}

	// Ensure the generateFilename option takes a callback
	this.options.generateFilename = ensureCallback(this.options.generateFilename);
}
github bcoe / thumbd / lib / utils.js View on Github external
exports.s3 = function (_bucket, _region) {
  var bucket = _bucket || config.get('s3Bucket')
  var region = _region || config.get('awsRegion')

  // Knox wants 'us-standard' instead of 'us-east-1'.
  if (region === 'us-east-1') region = 'us-standard'

  // cache the most recently used client.
  if (client && bucket === client.bucket && region === client.region) {
    return client
  } else {
    client = knox.createClient({
      key: config.get('awsKey'),
      secret: config.get('awsSecret'),
      bucket: bucket,
      region: region
    })
  }

  return client
}
github jxson / haiku / lib / haiku / site.js View on Github external
beam = function(_path, stats){
      var destination = _path.replace(directories.build, '')
        , client = knox.createClient({
            key: site.options.key,
            secret: site.options.secret,
            bucket: site.options.bucket
          })
      ;

      // Keep track
      tracker.push(_path);

      var stream = fs.createReadStream(_path)
        , md5sum = crypto.createHash('md5')
        , buffers = []
      ;

      stream.on('data', function(chunk){
        md5sum.update(chunk);
github nathanoehlman / knox-mpu / test / multipart.js View on Github external
before(function(done) {
        try {
            var auth = require('./auth.json');
            client = knox.createClient(auth);
            done();
        } catch (err) {
            done('Could not create Knox client - please provide an ./auth.json file');
        }
    });
github LockerProject / Locker / Connectors / AmazonS3 / s3.js View on Github external
app.get('/init', function(req, res) {
    if(!req.param('key') || !req.param('secret') || !req.param('bucket') ) {
        res.writeHead(400);
        res.end('whats the creds yo?');
        return;
    }
    console.log("initializing for "+req.param('bucket') );
    s3 = knox.createClient({key:req.param('key'), secret:req.param('secret'), bucket:req.param('bucket')});
    fs.writeFileSync('auth.json', JSON.stringify({key:req.param('key'), secret:req.param('secret'), bucket:req.param('bucket')}));
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end("saved, <a href="./">continue</a>");        
});
github naffis / nodejs-s3-example / app.js View on Github external
var express = require('express');
var knox = require('knox');
var url = require('url');
var http = require('http');

var client = knox.createClient({
    key: ''
  , secret: ''
  , bucket: 'mybucket'
});

var app = express.createServer(express.logger());

app.get('/', function (req, res) {  
  var src = req.query.src;
  console.log('src: ' + src);

  var options = {
    host: url.parse(src).host,
    port: 80,
    path: url.parse(src).pathname
  };

knox

Amazon S3 client

MIT
Latest version published 10 years ago

Package Health Score

51 / 100
Full package analysis

Popular knox functions