redis_acl

package module
v0.0.0-...-8d48f71 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 8 Imported by: 0

README

redis-acl

Redis starts supporting ACL from version 6. This repository contains an equivalent golang struct, and gives you the ability to parse ACL rules and stringify the ACLUser struct.

Installation

go get github.com/easton.lee/redis-acl

Usage

package main

import (
	"encoding/json"
	"fmt"

	acl "github.com/eastonlee/redis-acl"
)

func main() {
	user := &acl.ACLUser{
		Cluster:              "",
		Name:                 "easton",
		Flags:                []string{"off", "allkeys", "allcommands"},
		Enabled:              false,
		NoPass:               true,
		Passwords:            []string{"pass1"},
		PasswordHashes:       nil,
		Commands:             "-@keys",
		Keys:                 []string{"key1"},
		Channels:             []string{"channel1"},
		AllowedCommands:      nil,
		AllowedCategories:    nil,
		DisallowedCommands:   nil,
		DisallowedCategories: nil,
	}
	fmt.Println(user.String())
	// Output:
	// "easton off nopass ~* resetchannels &channel1 +@all"

	user, err := acl.ParseACLListUser("user easton off >p@ssw0rd ~sensitive-keys:* resetchannels &eventchannels* +@admin")
	if err != nil {
		fmt.Println(err)
	}
	bs, err := json.MarshalIndent(user, "", "  ")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(bs))
	// Output:
	/*
	** {
	**   "cluster": "",
	**   "name": "easton",
	**   "flags": [
	**     "off"
	**   ],
	**   "enabled": false,
	**   "nopass": false,
	**   "passwords": [
	**     "p@ssw0rd"
	**   ],
	**   "password_hashes": [
	**     "a075d17f3d453073853f813838c15b8023b8c487038436354fe599c3942e1f95"
	**   ],
	**   "passwords_to_remove": null,
	**   "password_hashes_to_remove": null,
	**   "commands": "",
	**   "keys": [
	**     "~sensitive-keys:*"
	**   ],
	**   "channels": [
	**     "eventchannels*"
	**   ],
	**   "allowed_commands": null,
	**   "allowed_categories": [
	**     "@admin"
	**   ],
	**   "disallowed_commands": null,
	**   "disallowed_categories": [
	**     "@all"
	**   ]
	** }
	 */
}

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ACLDelUser

func ACLDelUser(ctx context.Context, client redis.UniversalClient, name string) error

func ACLSetUser

func ACLSetUser(ctx context.Context, client redis.UniversalClient, user *ACLUser) error

func Sha256

func Sha256(pass string) string

Types

type ACLUser

type ACLUser struct {
	Cluster string `json:"cluster"`

	Name                   string   `json:"name"`
	Flags                  []string `json:"flags"`
	Enabled                bool     `json:"enabled"`
	NoPass                 bool     `json:"nopass"`
	Passwords              []string `json:"passwords"`
	PasswordHashes         []string `json:"password_hashes"`
	PasswordsToRemove      []string `json:"passwords_to_remove"`
	PasswordHashesToRemove []string `json:"password_hashes_to_remove"`
	// Commands in form of "+@all -keys"
	Commands string `json:"commands"`

	Keys     []string `json:"keys"`
	Channels []string `json:"channels"`

	AllowedCommands   []string `json:"allowed_commands"`
	AllowedCategories []string `json:"allowed_categories"`

	DisallowedCommands   []string `json:"disallowed_commands"`
	DisallowedCategories []string `json:"disallowed_categories"`
}

func ACLGetUser

func ACLGetUser(ctx context.Context, client redis.UniversalClient, name string) (*ACLUser, error)

func ACLList

func ACLList(ctx context.Context, client redis.UniversalClient) ([]*ACLUser, error)

func ParseACLListUser

func ParseACLListUser(s string) (*ACLUser, error)

func (*ACLUser) Consolidate

func (u *ACLUser) Consolidate()

func (*ACLUser) String

func (u *ACLUser) String(showPass bool) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL