npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

salt-api

v2.1.2

Published

A simple salt-api client library

Downloads

23

Readme

node-salt-api Known Vulnerabilities

A simple Node.js package to send functions to Salt Stack salt-api via CherryPy.
Use Salt modules from Node.js.

Requirements

You need to have salt-api and CherryPy installed and configured.
Please follow the installation instructions of Salt netapi rest_cherrypy.

Install

npm add salt-api axios eventsource

Please note that axios and eventsource are peerDependencies so depending on your use case, you may need to install these manually.

Usage

First, require salt-api

import { Salt } from "salt-api";

Configure

Configure the API via an object containing url, username, password.   If needed, you can also provide eauth. Defaults to "pam".

const salt = new Salt(YourConfigObjectHere, debug = false, axiosInstance = undefined);

Debug

Add second param true for debug logs.
const salt = new Salt(YourConfigObjectHere, true);

{
  tgt: 'not master',
  fun: 'saltutil.refresh_pillar',
  client: 'local',
  tgt_type: 'compound',
  duration: 1.934
}

Wait for authentication

Make sure salt-api is done with the authentication.

await salt.login();

or  

salt.login().then(() => {
	// Code
});

Run functions

salt.fun(target, function, funOptionsObjectHere)
target defaults to "*"
function defaults to "test.ping"
client defaults to "local"

Example of funOptions object
salt.fun("not master", "saltutil.refresh_pillar", { tgt_type: "compound" });

See more from Salt docs

Returns a Promise that resolves an object containing a return array with the data directly from the API.

Get minions

salt.minions(mid)

mid optional minion id

Returns a Promise that resolves an object containing a minon information in a return array with the data directly from the API.

Get jobs

salt.jobs(jid)

jid optional job id

Returns a Promise that resolves an object containing the job information in a return array with the data directly from the API.

Events

salt.eventSource()

Opens connection to An HTTP stream of the Salt Master Event Bus and returns EventSource.


const events = await salt.eventSource()
events.onopen = () => {
	console.log("Connected to Salt Master Event Bus")
}

events.onmessage = async (data) => {
	console.log("Got event from Salt Master Events Bus", data)
	// Do something with the data
}

events.onerror = async (err) => {
	if (err?.status === 401 || err?.status === 403) {
		console.log("Not authorized")
	};
}

Example

import { Salt } from "salt-api";
const salt = new Salt({
	url: "http://localhost:8000",
	username: "salt",
	password: "secret"
});

salt.login().then(() => {

	// Same as running `salt "*" test.ping` in the command line
	salt.fun("*", "test.ping").then(data => {

		// Do something with the data
		console.log(data);
		// { return: [ { b827eb3aaaf7: true, b827ebcc82fe: true } ] }

	}).catch(e => console.error(e));

});

LICENSE: MIT