mongodb

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("not found")
	ErrNotOK    = errors.New("not ok")

	AppName = "terraform-provider-mongodb-driver"
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(uri string, cred Credentials) *Client

func (*Client) CreateDBRole added in v0.2.0

func (c *Client) CreateDBRole(ctx context.Context, dbName string, newRole NewRole) (Role, error)

func (*Client) CreateDBUser

func (c *Client) CreateDBUser(ctx context.Context, dbName string, newUser NewUser) (User, error)

func (*Client) DeleteDBRole added in v0.2.0

func (c *Client) DeleteDBRole(ctx context.Context, dbName, roleName string) error

func (*Client) DeleteDBUser

func (c *Client) DeleteDBUser(ctx context.Context, dbName, userName string) error

func (*Client) GetDBRole added in v0.2.0

func (c *Client) GetDBRole(ctx context.Context, dbName, roleName string) (Role, error)

func (*Client) GetDBUser

func (c *Client) GetDBUser(ctx context.Context, dbName, userName string) (User, error)

func (*Client) ListAllUsers

func (c *Client) ListAllUsers(ctx context.Context, filter any) ([]User, error)

func (*Client) ListDBRoles added in v0.2.0

func (c *Client) ListDBRoles(ctx context.Context, dbName string) ([]Role, error)

func (*Client) ListDBUsers

func (c *Client) ListDBUsers(ctx context.Context, dbName string, filter any) ([]User, error)

func (*Client) UpdateDBRole added in v0.2.0

func (c *Client) UpdateDBRole(ctx context.Context, dbName string, update UpdateRole) (Role, error)

func (*Client) UpdateDBUser

func (c *Client) UpdateDBUser(ctx context.Context, dbName string, update UpdateUser) (User, error)

type CommandResponse

type CommandResponse struct {
	OK            int       `bson:"ok"`
	OperationTime time.Time `bson:"operationTime"`
}

type Credentials

type Credentials struct {
	Username string
	Password string
}

type Mechanism

type Mechanism string

Mechanism is the mechanism for user authentication.

[https://www.mongodb.com/docs/manual/reference/parameters/#mongodb-parameter-param.authenticationMechanisms]

const (
	// MechanismSCRAMSHA1 is the SCRAM mechanism for creating SCRAM user credentials.
	//
	// RFC 5802 standard Salted Challenge Response Authentication Mechanism using the SHA-1 hash function.
	//
	// - Uses the SHA-1 hashing function.
	//
	// [https://www.mongodb.com/docs/manual/core/security-scram/#std-label-authentication-scram-sha-1]
	MechanismSCRAMSHA1 Mechanism = "SCRAM-SHA-1"

	// MechanismSCRAMSHA256 is the SCRAM mechanism for creating SCRAM user credentials.
	//
	// RFC 7677 standard Salted Challenge Response Authentication Mechanism using the SHA-256 hash function.
	//
	// - Uses the SHA-256 hashing function.
	// - Requires featureCompatibilityVersion set to 4.0.
	// - Requires digestPassword to be true.
	//
	// [https://www.mongodb.com/docs/manual/core/security-scram/#std-label-authentication-scram-sha-256]
	MechanismSCRAMSHA256 Mechanism = "SCRAM-SHA-256"

	// MechanismMONGODBX509 is the mechanism for MongoDB TLS/SSL certificate authentication.
	//
	// [https://www.mongodb.com/docs/manual/core/security-x.509/#std-label-security-auth-x509]
	MechanismMONGODBX509 Mechanism = "MONGODB-X509"

	// MechanismPLAIN is the mechanism for external authentication using LDAP.
	// You can also use PLAIN for authenticating in-database users.
	// PLAIN transmits passwords in plain text.
	// This mechanism is available only in MongoDB Enterprise.
	//
	// [https://www.mongodb.com/docs/manual/core/authentication/#std-label-security-auth-ldap]
	MechanismPLAIN Mechanism = "PLAIN"

	// MechanismGSSAPI is the mechanism for external authentication using Kerberos.
	// This mechanism is available only in MongoDB Enterprise.
	//
	// [https://www.mongodb.com/docs/manual/core/authentication/#std-label-security-auth-kerberos]
	MechanismGSSAPI Mechanism = "GSSAPI"
)

type NewRole added in v0.2.0

type NewRole struct {
	Role       string      `bson:"createRole"`
	Privileges []Privilege `bson:"privileges"`
	Roles      []RoleRef   `bson:"roles"`
}

type NewUser

type NewUser struct {
	User       string            `bson:"createUser"`
	Password   string            `bson:"pwd"`
	CustomData map[string]string `bson:"customData,omitempty"`
	Roles      []RoleRef         `bson:"roles"`
	Mechanisms []Mechanism       `bson:"mechanisms,omitempty"`
}

type Privilege added in v0.2.0

type Privilege struct {
	Resource ResourceWrapper `bson:"resource"`
	Actions  []string        `bson:"actions"`
}

type Resource added in v0.2.0

type Resource interface {
	// contains filtered or unexported methods
}

type ResourceAny added in v0.2.0

type ResourceAny struct {
	AnyResource bool `bson:"anyResource"`
}

type ResourceCluster added in v0.2.0

type ResourceCluster struct {
	Cluster bool `bson:"cluster"`
}

type ResourceCollection added in v0.2.0

type ResourceCollection struct {
	DB         string `bson:"db"`
	Collection string `bson:"collection"`
}

type ResourceSystemBuckets added in v0.2.0

type ResourceSystemBuckets struct {
	SystemBuckets string `bson:"system_buckets"`
}

type ResourceWrapper added in v0.2.0

type ResourceWrapper struct {
	Union Resource
}

func (*ResourceWrapper) MarshalBSONValue added in v0.2.0

func (r *ResourceWrapper) MarshalBSONValue() (bsontype.Type, []byte, error)

MarshalBSONValue implements bson.ValueMarshaler.

func (*ResourceWrapper) UnmarshalBSONValue added in v0.2.0

func (r *ResourceWrapper) UnmarshalBSONValue(t bsontype.Type, data []byte) error

UnmarshalBSONValue implements bson.ValueUnmarshaler.

type Role added in v0.2.0

type Role struct {
	ID                  string      `bson:"_id"`
	Role                string      `bson:"role"`
	DB                  string      `bson:"db"`
	Privileges          []Privilege `bson:"privileges"`
	IsBuiltin           bool        `bson:"isBuiltin"`
	Roles               []RoleDBRef `bson:"roles"`
	InheritedRoles      []RoleDBRef `bson:"inheritedRoles"`
	InheritedPrivileges []Privilege `bson:"inheritedPrivileges"`
}

type RoleDBRef

type RoleDBRef struct {
	Role string `bson:"role"`
	DB   string `bson:"db"`
}

RoleDBRef is a RoleRef that points to a role in a specific database.

type RoleRef

type RoleRef interface {
	// contains filtered or unexported methods
}

type RoleSameDBRef

type RoleSameDBRef string

RoleSameDBRef is a RoleRef that points to a role in the same database.

type UpdateRole added in v0.2.0

type UpdateRole struct {
	Role       string      `bson:"updateRole"`
	Privileges []Privilege `bson:"privileges,omitempty"`
	Roles      []RoleRef   `bson:"roles,omitempty"`
}

type UpdateUser

type UpdateUser struct {
	User       string            `bson:"updateUser"`
	Password   string            `bson:"pwd,omitempty"`
	CustomData map[string]string `bson:"customData,omitempty"`
	Roles      []RoleRef         `bson:"roles,omitempty"`
	Mechanisms []Mechanism       `bson:"mechanisms,omitempty"`
}

type User

type User struct {
	ID         string            `bson:"_id"`
	UserID     primitive.Binary  `bson:"userId"`
	User       string            `bson:"user"`
	DB         string            `bson:"db"`
	CustomData map[string]string `bson:"customData"`
	Roles      []RoleDBRef       `bson:"roles"`
	Mechanisms []Mechanism       `bson:"mechanisms"`
}

Jump to

Keyboard shortcuts

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