Giter Site home page Giter Site logo

sonar-client's Introduction

sonar-client

Ruby API Wrapper and CLI for Sonar

Installation

Install the gem by running

gem install sonar-client

or add this line to your application's Gemfile:

gem 'sonar-client'

And then execute:

$ bundle install

Gem usage

    require 'sonar'

    # If you're using Rails 3+, create an initializer
    # config/initializers/sonar.rb
    Sonar.configure do |config|
      config.api_url        = 'https://sonar.labs.rapid7.com'
      config.api_version    = 'v2'
      config.email          = '[email protected]'
      config.access_token   = 'YOURTOKEN'
    end

    # If you're using straight ruby (no Rails),
    # create a Sonar::Client Object
    options = {
      api_url: 'https://sonar.labs.rapid7.com',
      api_version: 'v2',
      access_token: 'YOURTOKEN',
      email: '[email protected]'
    }
    client = Sonar::Client.new(options)

    # Create a Client Object expecting you have an initializer in place
    # Sonar::Client Object
    client = Sonar::Client.new

    # Get fdns
    client.search(fdns: 'rapid7.com')
    # => responds with a Hashie object

CLI dev setup

From the project root directory

$ rake install
sonar-client 0.0.1 built to pkg/sonar-client-0.0.1.gem.
sonar-client (0.0.1) installed.
$ sonar

On the first run, sonar will setup a sonar.rc config file in your user folder. Run sonar config to view the full path to your config file. Here's what your file will look like when it's first created:

email: YOUR_EMAIL
access_token: SONAR_TOKEN
api_url: https://sonar.labs.rapid7.com
format: flat
record_limit: 10000

Replace YOUR_EMAIL with the email you used to register on the Sonar website. Replace SONAR_TOKEN with your API token found on the Settings page of the Sonar website. The format option can either pretty-print the return JSON or display it in a flat output (by default). The record limit is the maximum number of records to return for a query. Responses are returned in 1000 record chunks that are streamed into the output to avoid API timeouts. Enclosing quotes around these two settings are not needed. These configurations can always be overwritten for a single command line query by specifying the option and argument: --format pretty.

CLI usage

Typing sonar help will list all the available commands. You can type sonar help TASK to get help for a specific command. If running locally from the root project directory, you may need to prefix sonar commands with bundle exec. A rdns search command might look like bundle exec sonar search rdns .rapid7.com.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

sonar-client's People

Contributors

pdeardorff-r7 avatar themetric avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.