admin

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 13 Imported by: 21

README

Prerequisites

You must create an admin user like so:

radosgw-admin user create --uid admin --display-name "Admin User" --caps "buckets=*;users=*;usage=read;metadata=read;zone=read --access-key=2262XNX11FZRR44XWIRD --secret-key=rmtuS1Uj1bIC08QFYGW18GfSHAbkPqdsuYynNudw

Then use the access_key and secret_key for authentication.

Snippet usage example:

package main

import (
    "github.com/ceph/go-ceph/rgw/admin"
)

func main() {
    // Generate a connection object
    co, err := admin.New("http://192.168.1.1", "2262XNX11FZRR44XWIRD", "rmtuS1Uj1bIC08QFYGW18GfSHAbkPqdsuYynNudw", nil)
    if err != nil {
        panic(err)
    }

    // Get the "admin" user
    user, err := co.GetUser(context.Background(), "admin")
    if err != nil {
        panic(err)
    }

    // Print the user display name
    fmt.Println(user.DisplayName)
}

Documentation

Overview

Package admin contains a set of wrappers around Ceph's RGW Admin Ops API.

Index

Constants

View Source
const (
	// ErrUserExists - Attempt to create existing user
	ErrUserExists errorReason = "UserAlreadyExists"

	// ErrNoSuchUser - Attempt to create existing user
	ErrNoSuchUser errorReason = "NoSuchUser"

	// ErrInvalidAccessKey - Invalid access key specified
	ErrInvalidAccessKey errorReason = "InvalidAccessKey"

	// ErrInvalidSecretKey - Invalid secret key specified
	ErrInvalidSecretKey errorReason = "InvalidSecretKey"

	// ErrInvalidKeyType - Invalid key type specified
	ErrInvalidKeyType errorReason = "InvalidKeyType"

	// ErrKeyExists - Provided access key exists and belongs to another user
	ErrKeyExists errorReason = "KeyExists"

	// ErrEmailExists - Provided email address exists
	ErrEmailExists errorReason = "EmailExists"

	// ErrInvalidCapability - Attempt to remove an invalid admin capability
	ErrInvalidCapability errorReason = "InvalidCapability"

	// ErrSubuserExists - Specified subuser exists
	ErrSubuserExists errorReason = "SubuserExists"

	// ErrInvalidAccess - Invalid subuser access specified
	ErrInvalidAccess errorReason = "InvalidAccess"

	// ErrIndexRepairFailed - Bucket index repair failed
	ErrIndexRepairFailed errorReason = "IndexRepairFailed"

	// ErrBucketNotEmpty - Attempted to delete non-empty bucket
	ErrBucketNotEmpty errorReason = "BucketNotEmpty"

	// ErrObjectRemovalFailed - Unable to remove objects
	ErrObjectRemovalFailed errorReason = "ObjectRemovalFailed"

	// ErrBucketUnlinkFailed - Unable to unlink bucket from specified user
	ErrBucketUnlinkFailed errorReason = "BucketUnlinkFailed"

	// ErrBucketLinkFailed - Unable to link bucket to specified user
	ErrBucketLinkFailed errorReason = "BucketLinkFailed"

	// ErrNoSuchObject - Specified object does not exist
	ErrNoSuchObject errorReason = "NoSuchObject"

	// ErrIncompleteBody - Either bucket was not specified for a bucket policy request or bucket and object were not specified for an object policy request.
	ErrIncompleteBody errorReason = "IncompleteBody"

	// ErrNoSuchCap - User does not possess specified capability
	ErrNoSuchCap errorReason = "NoSuchCap"

	// ErrInternalError - Internal server error.
	ErrInternalError errorReason = "InternalError"

	// ErrAccessDenied - Access denied.
	ErrAccessDenied errorReason = "AccessDenied"

	// ErrNoSuchBucket - Bucket does not exist.
	ErrNoSuchBucket errorReason = "NoSuchBucket"

	// ErrNoSuchKey - No such access key.
	ErrNoSuchKey errorReason = "NoSuchKey"

	// ErrInvalidArgument - Invalid argument.
	ErrInvalidArgument errorReason = "InvalidArgument"

	// ErrUnknown - reports an unknown error
	ErrUnknown errorReason = "Unknown"

	// ErrSignatureDoesNotMatch - the query to the API has invalid parameters
	ErrSignatureDoesNotMatch errorReason = "SignatureDoesNotMatch"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	AccessKey  string
	SecretKey  string
	Endpoint   string
	HTTPClient HTTPClient
}

API struct for New Client

func New

func New(endpoint, accessKey, secretKey string, httpClient HTTPClient) (*API, error)

New returns client for Ceph RGW

func (*API) CreateUser

func (api *API) CreateUser(ctx context.Context, user User) (User, error)

CreateUser creates a user in the object store

func (*API) GetBucketInfo

func (api *API) GetBucketInfo(ctx context.Context, bucket Bucket) (Bucket, error)

GetBucketInfo will return various information about a specific token

func (*API) GetUsage

func (api *API) GetUsage(ctx context.Context, usage Usage) (Usage, error)

GetUsage request bandwidth usage information on the object store

func (*API) GetUser

func (api *API) GetUser(ctx context.Context, user User) (User, error)

GetUser retrieves a given object store user

func (*API) GetUserQuota

func (api *API) GetUserQuota(ctx context.Context, quota QuotaSpec) (QuotaSpec, error)

GetUserQuota will return the quota for a user

func (*API) GetUsers

func (api *API) GetUsers(ctx context.Context) (*[]string, error)

GetUsers lists all object store users

func (*API) ListBuckets

func (api *API) ListBuckets(ctx context.Context) ([]string, error)

ListBuckets will return the list of all buckets present in the object store

func (*API) ModifyUser

func (api *API) ModifyUser(ctx context.Context, user User) (User, error)

ModifyUser - http://docs.ceph.com/docs/latest/radosgw/adminops/#modify-user

func (*API) RemoveBucket

func (api *API) RemoveBucket(ctx context.Context, bucket Bucket) error

RemoveBucket will remove a given token from the object store

func (*API) RemoveUser

func (api *API) RemoveUser(ctx context.Context, user User) error

RemoveUser remove an user from the object store

func (*API) SetUserQuota

func (api *API) SetUserQuota(ctx context.Context, quota QuotaSpec) error

SetUserQuota sets quota to a user Global quotas (https://docs.ceph.com/en/latest/radosgw/admin/#reading-writing-global-quotas) are not surfaced in the Admin Ops API So this library cannot expose it yet

func (*API) TrimUsage

func (api *API) TrimUsage(ctx context.Context, usage Usage) error

TrimUsage removes bandwidth usage information. With no dates specified, removes all usage information.

type Bucket

type Bucket struct {
	Bucket            string `json:"bucket" url:"bucket"`
	Zonegroup         string `json:"zonegroup"`
	PlacementRule     string `json:"placement_rule"`
	ExplicitPlacement struct {
		DataPool      string `json:"data_pool"`
		DataExtraPool string `json:"data_extra_pool"`
		IndexPool     string `json:"index_pool"`
	} `json:"explicit_placement"`
	ID        string `json:"id"`
	Marker    string `json:"marker"`
	IndexType string `json:"index_type"`
	Owner     string `json:"owner"`
	Ver       string `json:"ver"`
	MasterVer string `json:"master_ver"`
	Mtime     string `json:"mtime"`
	MaxMarker string `json:"max_marker"`
	Usage     struct {
		RgwMain struct {
			Size           *uint64 `json:"size"`
			SizeActual     *uint64 `json:"size_actual"`
			SizeUtilized   *uint64 `json:"size_utilized"`
			SizeKb         *uint64 `json:"size_kb"`
			SizeKbActual   *uint64 `json:"size_kb_actual"`
			SizeKbUtilized *uint64 `json:"size_kb_utilized"`
			NumObjects     *uint64 `json:"num_objects"`
		} `json:"rgw.main"`
		RgwMultimeta struct {
			Size           *uint64 `json:"size"`
			SizeActual     *uint64 `json:"size_actual"`
			SizeUtilized   *uint64 `json:"size_utilized"`
			SizeKb         *uint64 `json:"size_kb"`
			SizeKbActual   *uint64 `json:"size_kb_actual"`
			SizeKbUtilized *uint64 `json:"size_kb_utilized"`
			NumObjects     *uint64 `json:"num_objects"`
		} `json:"rgw.multimeta"`
	} `json:"usage"`
	BucketQuota QuotaSpec `json:"bucket_quota"`
	Policy      *bool     `url:"policy"`
	PurgeObject *bool     `url:"purge-objects"`
}

Bucket describes an object store bucket

type HTTPClient added in v0.11.0

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient interface that conforms to that of the http package's Client.

type Policy

type Policy struct {
	ACL struct {
		ACLUserMap []struct {
			User string `json:"user"`
			ACL  *int   `json:"acl"`
		} `json:"acl_user_map"`
		ACLGroupMap []interface{} `json:"acl_group_map"`
		GrantMap    []struct {
			ID    string `json:"id"`
			Grant struct {
				Type struct {
					Type int `json:"type"`
				} `json:"type"`
				ID         string `json:"id"`
				Email      string `json:"email"`
				Permission struct {
					Flags int `json:"flags"`
				} `json:"permission"`
				Name    string `json:"name"`
				Group   *int   `json:"group"`
				URLSpec string `json:"url_spec"`
			} `json:"grant"`
		} `json:"grant_map"`
	} `json:"acl"`
	Owner struct {
		ID          string `json:"id"`
		DisplayName string `json:"display_name"`
	} `json:"owner"`
}

Policy describes a bucket policy

type QuotaSpec

type QuotaSpec struct {
	UID        string `json:"user_id" url:"uid"`
	QuotaType  string `url:"quota-type"`
	Enabled    *bool  `json:"enabled" url:"enabled"`
	CheckOnRaw bool   `json:"check_on_raw"`
	MaxSize    *int64 `json:"max_size" url:"max-size"`
	MaxSizeKb  *int   `json:"max_size_kb" url:"max-size-kb"`
	MaxObjects *int64 `json:"max_objects" url:"max-objects"`
}

QuotaSpec describes an object store quota for a user or a bucket Only user's quota are supported

type Usage

type Usage struct {
	Entries []struct {
		User    string `json:"user"`
		Buckets []struct {
			Bucket     string `json:"bucket"`
			Time       string `json:"time"`
			Epoch      uint64 `json:"epoch"`
			Owner      string `json:"owner"`
			Categories []struct {
				Category      string `json:"category"`
				BytesSent     uint64 `json:"bytes_sent"`
				BytesReceived uint64 `json:"bytes_received"`
				Ops           uint64 `json:"ops"`
				SuccessfulOps uint64 `json:"successful_ops"`
			} `json:"categories"`
		} `json:"buckets"`
	} `json:"entries"`
	Summary []struct {
		User       string `json:"user"`
		Categories []struct {
			Category      string `json:"category"`
			BytesSent     uint64 `json:"bytes_sent"`
			BytesReceived uint64 `json:"bytes_received"`
			Ops           uint64 `json:"ops"`
			SuccessfulOps uint64 `json:"successful_ops"`
		} `json:"categories"`
		Total struct {
			BytesSent     uint64 `json:"bytes_sent"`
			BytesReceived uint64 `json:"bytes_received"`
			Ops           uint64 `json:"ops"`
			SuccessfulOps uint64 `json:"successful_ops"`
		} `json:"total"`
	} `json:"summary"`
	Start       string `url:"start"` //Example:	2012-09-25 16:00:00
	End         string `url:"end"`
	ShowEntries *bool  `url:"show-entries"`
	ShowSummary *bool  `url:"show-summary"`
	RemoveAll   *bool  `url:"remove-all"` //true
}

Usage struct

type User

type User struct {
	ID                  string        `json:"user_id" url:"uid"`
	DisplayName         string        `json:"display_name" url:"display-name"`
	Email               string        `json:"email" url:"email"`
	Suspended           *int          `json:"suspended" url:"suspended"`
	MaxBuckets          *int          `json:"max_buckets" url:"max-buckets"`
	Subusers            []interface{} `json:"subusers"`
	Keys                []UserKeySpec `json:"keys"`
	SwiftKeys           []interface{} `json:"swift_keys"`
	Caps                []UserCapSpec `json:"caps"`
	OpMask              string        `json:"op_mask"`
	DefaultPlacement    string        `json:"default_placement"`
	DefaultStorageClass string        `json:"default_storage_class"`
	PlacementTags       []interface{} `json:"placement_tags"`
	BucketQuota         QuotaSpec     `json:"bucket_quota"`
	UserQuota           QuotaSpec     `json:"user_quota"`
	TempURLKeys         []interface{} `json:"temp_url_keys"`
	Type                string        `json:"type"`
	MfaIds              []interface{} `json:"mfa_ids"`
	KeyType             string        `url:"key-type"`
	Tenant              string        `url:"tenant"`
	GenerateKey         *bool         `url:"generate-key"`
	PurgeData           *int          `url:"purge-data"`
	GenerateStat        *bool         `url:"stats"`
	Stat                UserStat      `json:"stats"`
	UserCaps            string        `url:"user-caps"`
}

User is GO representation of the json output of a user creation

type UserCapSpec

type UserCapSpec struct {
	Type string `json:"type"`
	Perm string `json:"perm"`
}

UserCapSpec represents a user capability which gives access to certain ressources

type UserKeySpec

type UserKeySpec struct {
	User      string `json:"user"`
	AccessKey string `json:"access_key" url:"access-key"`
	SecretKey string `json:"secret_key" url:"secret-key"`
}

UserKeySpec is the user credential configuration

type UserStat added in v0.11.0

type UserStat struct {
	Size        *uint64 `json:"size"`
	SizeRounded *uint64 `json:"size_rounded"`
	NumObjects  *uint64 `json:"num_objects"`
}

UserStat contains information about storage consumption by the ceph user

Jump to

Keyboard shortcuts

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