permify_go

package module
v2.0.0-...-297c1f6 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2022 License: MIT Imports: 15 Imported by: 0

README

Permify Go Library

GitHub last commit Twitter URL

Use Permify in server-side Go Projects.

Install

go get github.com/Permify/permify-go/v2

Usage

To get started, create the Permify client using your Workspace id and API private key:

import permify `github.com/Permify/permify-go/v2`

client := client.New("workspace_id", "private_token")
Create User

This method creates a user entity in Permify.

response, err := client.User.Create(user.Create{ExternalID: "user_external_id", GroupExternalID: "group_external_id", Name: "user_name", Photo: permify_go.String("user_photo"), Title: permify_go.String("user_title")})
Create Role

This method creates a role entity in Permify.

response, err = client.Role.Create(role.Create{GroupExternalID: "group_external_id", Name: "role_name", Description: permify_go.String("user_photo"), Color: permify_go.String("color")})
Create Group

This method creates a group entity in Permify.

response, err = client.Group.Create(group.Create{ExternalID: "external_id", Name: "name"})
IsAuthorized

This method returns a decision about whether the user can do this action.

cascade create means if permission does not exist in the database, it creates a new permission and continues processing.

response, err = client.User.IsAuthorized(user.IsAuthorized{UserExternalID: "user_external_id", PermissionName: "permission_name", CascadeCreate: true, Description: permify_go.String("description")})
Create Portal Session

This method creates a new portal session. More information about Permify Portal.

response, err = client.Session.Create(session.Create{GroupExternalID: "group_external_id"})

For more information on how to use the Permify API, please refer to the Permify API Reference.

Permify Documentation

See more

Documentation

Index

Constants

View Source
const DefaultBatchSize = 250
View Source
const DefaultEndpoint = "https://api.permify.co"
View Source
const DefaultInterval = 5 * time.Second
View Source
const Version = "v1"

Variables

This section is empty.

Functions

func Bool

func Bool(v bool) *bool

func Guard

func Guard(b string) string

func GuardArray

func GuardArray(b []string) (guardArray []string)

func HmacSha1

func HmacSha1(message string, secret string) string

func String

func String(v string) *string

Types

type API

type API interface {
	Call(request Request, successValue interface{}) error
}

type APIValidationError

type APIValidationError struct {
	Errors map[string]interface{} `json:"errors"`
}

func (APIValidationError) Error

func (e APIValidationError) Error() string

type AppInfo

type AppInfo struct {
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
}

type Backend

type Backend struct {
	Configuration
	// contains filtered or unexported fields
}

func GetBackend

func GetBackend(workspaceID, privateKey string) *Backend

func GetBackendWithConfiguration

func GetBackendWithConfiguration(workspaceID, privateKey string, configuration Configuration) (client *Backend, err error)

func (*Backend) Call

func (b *Backend) Call(request Request, successValue interface{}) (err error)

type Configuration

type Configuration struct {
	Endpoint       string
	Interval       time.Duration
	Transport      http.RoundTripper
	DefaultContext *Context
	BatchSize      int

	Logger Logger
	// contains filtered or unexported fields
}

type Context

type Context struct {
	App       AppInfo     `json:"app,omitempty"`
	Library   LibraryInfo `json:"library,omitempty"`
	Locale    string      `json:"locale,omitempty"`
	Timezone  string      `json:"timezone,omitempty"`
	UserAgent string      `json:"userAgent,omitempty"`
}

type Counter

type Counter struct {
	ID           string      `json:"id"`
	UserID       string      `json:"user_id"`
	User         *User       `json:"user"`
	PermissionID string      `json:"permission_id"`
	Permission   *Permission `json:"permission"`
	WorkspaceID  string      `json:"workspace_id"`
	Value        int64       `json:"value"`
	CreatedAt    time.Time   `json:"created_at"`
	UpdatedAt    time.Time   `json:"updated_at"`
}

type Group

type Group struct {
	ID          string    `json:"id"`
	ExternalID  string    `json:"external_id"`
	Name        string    `json:"name"`
	WorkspaceID string    `json:"workspace_id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Group */

type LibraryInfo

type LibraryInfo struct {
	Name    string `json:"name,omitempty"`
	Version string `json:"version,omitempty"`
}

type Logger

type Logger interface {
	Logf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

func StdLogger

func StdLogger(logger *log.Logger) Logger

type MessageResponse

type MessageResponse struct {
	Message string `json:"message"`
}

func (MessageResponse) Error

func (e MessageResponse) Error() string

type Permission

type Permission struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	GuardName   string    `json:"guard_name"`
	Description string    `json:"description"`
	Color       string    `json:"color"`
	WorkspaceID string    `json:"workspace_id"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Permission */

type Request

type Request interface {
	GetMethod() string
	GetPath() string
	GetQueries() map[string][]string
	GetBody() map[string]interface{}
}

type ResponseDecoder

type ResponseDecoder interface {
	Decode(resp *http.Response, v interface{}) error
}

type Role

type Role struct {
	ID                   string       `json:"id"`
	Name                 string       `json:"name"`
	GuardName            string       `json:"guard_name"`
	Description          string       `json:"description"`
	Color                string       `json:"color"`
	GroupID              string       `json:"group_id"`
	Permissions          []Permission `json:"permissions"`
	Users                []User       `json:"users"`
	TotalPermissionCount uint         `json:"total_permission_count"`
	TotalUserCount       uint         `json:"total_user_count"`
	CreatedAt            time.Time    `json:"created_at"`
	UpdatedAt            time.Time    `json:"updated_at"`
}

Role */

type Scheduler

type Scheduler struct {
	ID          string       `json:"id"`
	Name        string       `json:"name"`
	UserID      string       `json:"user_id"`
	User        *User        `json:"user"`
	WorkspaceID string       `json:"workspace_id"`
	Roles       []Role       `json:"roles"`
	Permissions []Permission `json:"permissions"`
	Triggers    []Trigger    `json:"triggers"`
	CreatedAt   time.Time    `json:"created_at"`
}

type Session

type Session struct {
	ID          string    `json:"id"`
	Token       string    `json:"token"`
	WorkspaceID string    `json:"workspace_id"`
	GroupID     string    `json:"group_id"`
	CreatedAt   time.Time `json:"created_at"`
	ExpiresAt   time.Time `json:"expires_at"`
}

Session */

type Trigger

type Trigger struct {
	ID          string    `json:"id"`
	Type        string    `json:"type"`
	SchedulerID string    `json:"scheduler_id"`
	IsCompleted bool      `json:"is_completed"`
	TriggerAt   int64     `json:"trigger_at"`
	CreatedAt   time.Time `json:"created_at"`
}

type User

type User struct {
	ID          string       `json:"id"`
	ExternalID  string       `json:"external_id"`
	Name        string       `json:"name"`
	Photo       *string      `json:"photo"`
	Title       *string      `json:"title"`
	WorkspaceID string       `json:"workspace_id"`
	Roles       []Role       `json:"roles"`
	Permissions []Permission `json:"permissions"`
	GroupID     string       `json:"group_id"`
	CreatedAt   time.Time    `json:"created_at"`
	UpdatedAt   time.Time    `json:"updated_at"`
}

User */

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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