admin

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package admin implements the functions to call pulsar admin

Index

Constants

View Source
const (
	// TopicDomainSeparator is the separator to separate the topic name
	TopicDomainSeparator = "://"
	// TopicDomainPersistent is the prefix for persistent topic
	TopicDomainPersistent = "persistent"
	// TopicDomainNonPersistent is the prefix for non persistent topic
	TopicDomainNonPersistent = "non-persistent"
)

Variables

This section is empty.

Functions

func IsAlreadyExist

func IsAlreadyExist(err error) bool

IsAlreadyExist returns true if the error indicates the resource already exist

func IsInternalServerError

func IsInternalServerError(err error) bool

IsInternalServerError returns true if the error indicates the resource already exist

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the error indicates the resource is not found on server

func IsPermissionNotFound

func IsPermissionNotFound(err error) bool

IsPermissionNotFound returns true if the permission is not set

Types

type DummyPulsarAdmin

type DummyPulsarAdmin struct {
}

DummyPulsarAdmin is a dummy struct of PulsarAdmin

func (*DummyPulsarAdmin) ApplyNamespace

func (d *DummyPulsarAdmin) ApplyNamespace(name string, params *NamespaceParams) error

ApplyNamespace is a fake implements of ApplyNamespace

func (*DummyPulsarAdmin) ApplyTenant

func (d *DummyPulsarAdmin) ApplyTenant(name string, params *TenantParams) error

ApplyTenant is a fake implements of ApplyTenant

func (*DummyPulsarAdmin) ApplyTopic

func (d *DummyPulsarAdmin) ApplyTopic(name string, params *TopicParams) error

ApplyTopic is a fake implements of ApplyTopic

func (*DummyPulsarAdmin) Close

func (d *DummyPulsarAdmin) Close() error

Close is a fake implements of Close

func (*DummyPulsarAdmin) DeleteNamespace

func (d *DummyPulsarAdmin) DeleteNamespace(name string) error

DeleteNamespace is a fake implements of DeleteNamespace

func (*DummyPulsarAdmin) DeleteTenant

func (d *DummyPulsarAdmin) DeleteTenant(name string) error

DeleteTenant is a fake implements of DeleteTenant

func (*DummyPulsarAdmin) DeleteTopic

func (d *DummyPulsarAdmin) DeleteTopic(name string) error

DeleteTopic is a fake implements of DeleteTopic

func (*DummyPulsarAdmin) GrantPermissions

func (d *DummyPulsarAdmin) GrantPermissions(p Permissioner) error

GrantPermissions is a fake implements of GrantPermissions

func (*DummyPulsarAdmin) RevokePermissions

func (d *DummyPulsarAdmin) RevokePermissions(p Permissioner) error

RevokePermissions is a fake implements of RevokePermissions

type NamespaceParams

type NamespaceParams struct {
	Bundles                     *int32
	MaxProducersPerTopic        *int32
	MaxConsumersPerTopic        *int32
	MaxConsumersPerSubscription *int32
	MessageTTL                  *metav1.Duration
	RetentionTime               *metav1.Duration
	RetentionSize               *resource.Quantity
	BacklogQuotaLimitTime       *metav1.Duration
	BacklogQuotaLimitSize       *resource.Quantity
	BacklogQuotaRetentionPolicy *string
	BacklogQuotaType            *string
}

NamespaceParams indicates the parameters for creating a namespace

type NamespacePermission

type NamespacePermission struct {
	ResourceName string
	Roles        []string
	Actions      []string
}

NamespacePermission is the parameters to grant permission for a namespace

func (*NamespacePermission) Grant

func (n *NamespacePermission) Grant(client pulsar.Client) error

Grant implements the grant method for namespace permission

func (*NamespacePermission) Revoke

func (n *NamespacePermission) Revoke(client pulsar.Client) error

Revoke implements the revoke method for namespace permission

type Permissioner

type Permissioner interface {
	// Grant grants permission to role on a resource
	Grant(client pulsar.Client) error
	// Revoke revokes permission from role on a resource
	Revoke(client pulsar.Client) error
}

Permissioner implements the functions to grant and revoke permission for namespace and topic

type PulsarAdmin

type PulsarAdmin interface {
	// ApplyTenant creates or updates a tenant with parameters
	ApplyTenant(name string, params *TenantParams) error

	// DeleteTenant delete a specific tenant
	DeleteTenant(name string) error

	// ApplyNamespace creates a namespace with parameters
	ApplyNamespace(name string, params *NamespaceParams) error

	// DeleteNamespace delete a specific namespace
	DeleteNamespace(name string) error

	// ApplyTopic creates a topic with parameters
	ApplyTopic(name string, params *TopicParams) error

	// DeleteTopic delete a specific topic
	DeleteTopic(name string) error

	// GrantPermissions grants permissions to multiple role with multiple actions
	// on a namespace or topic, each role will be granted the same actions
	GrantPermissions(p Permissioner) error

	// RevokePermissions revoke permissions from roles on a namespace or topic.
	// it will revoke all actions which granted to a role on a namespace or topic
	RevokePermissions(p Permissioner) error

	// Close releases the connection with pulsar admin
	Close() error
}

PulsarAdmin is the interface that defines the functions to call pulsar admin

func NewDummyPulsarAdmin

func NewDummyPulsarAdmin(config PulsarAdminConfig) (PulsarAdmin, error)

NewDummyPulsarAdmin is a dummy initialization function

func NewPulsarAdmin

func NewPulsarAdmin(conf PulsarAdminConfig) (PulsarAdmin, error)

NewPulsarAdmin initialize a pulsar admin client with configuration

type PulsarAdminClient

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

PulsarAdminClient define the client to call pulsar

func (*PulsarAdminClient) ApplyNamespace

func (p *PulsarAdminClient) ApplyNamespace(name string, params *NamespaceParams) error

ApplyNamespace creates a namespace with policies

func (*PulsarAdminClient) ApplyTenant

func (p *PulsarAdminClient) ApplyTenant(name string, params *TenantParams) error

ApplyTenant creates or updates a tenant, if AllowdClusters is not provided, it will list all clusters in pular When updates a tenant, If AdminRoles is empty, the current set of roles won't be modified

func (*PulsarAdminClient) ApplyTopic

func (p *PulsarAdminClient) ApplyTopic(name string, params *TopicParams) error

ApplyTopic creates a topic with policies

func (*PulsarAdminClient) Close

func (p *PulsarAdminClient) Close() error

Close do nothing for now

func (*PulsarAdminClient) DeleteNamespace

func (p *PulsarAdminClient) DeleteNamespace(name string) error

DeleteNamespace deletes a specific namespace

func (*PulsarAdminClient) DeleteTenant

func (p *PulsarAdminClient) DeleteTenant(name string) error

DeleteTenant deletes a specific tenant

func (*PulsarAdminClient) DeleteTopic

func (p *PulsarAdminClient) DeleteTopic(name string) error

DeleteTopic deletes a specific topic

func (*PulsarAdminClient) GrantPermissions

func (p *PulsarAdminClient) GrantPermissions(permission Permissioner) error

GrantPermissions grants permissions to multiple role with multiple actions on a namespace or topic, each role will be granted the same actions

func (*PulsarAdminClient) RevokePermissions

func (p *PulsarAdminClient) RevokePermissions(permission Permissioner) error

RevokePermissions revoke permissions from roles on a namespace or topic. it will revoke all actions which granted to a role on a namespace or topic

type PulsarAdminConfig

type PulsarAdminConfig struct {

	// WebServiceURL to connect to Pulsar.
	WebServiceURL string

	// Set the path to the trusted TLS certificate file
	TLSTrustCertsFilePath string
	// Configure whether the Pulsar client accept untrusted TLS certificate from broker (default: false)
	TLSAllowInsecureConnection bool

	TLSEnableHostnameVerification bool

	// Either Token or OAuth2 configuration must be provided
	// The Token used for authentication.
	Token string

	// OAuth2 related configuration used for authentication.
	IssuerEndpoint string
	ClientID       string
	Audience       string
	Key            string
}

PulsarAdminConfig indicates the configurations which are needed to initialize the pulsar admin

type PulsarAdminCreator

type PulsarAdminCreator func(config PulsarAdminConfig) (PulsarAdmin, error)

PulsarAdminCreator is the function type to create a PulsarAdmin with config

type Reason

type Reason int

Reason indicates the status code

const (
	// ReasonUnauthorized means need to authenticate to perform the operation
	ReasonUnauthorized Reason = 401

	// ReasonForbidden means don't have admin permission for the operation
	ReasonForbidden Reason = 403

	// ReasonNotFound means a resource is not found in Pulsar
	ReasonNotFound Reason = 404

	// ReasonAlreadyExist means a resource already exist in Pulsar
	ReasonAlreadyExist Reason = 409

	// ReasonInvalidParameter means a resource already exist in Pulsar
	// Status code 412
	ReasonInvalidParameter Reason = 412

	// ReasonInternalServerError means Pulsar server fail to handle the request
	// Status code 500
	ReasonInternalServerError Reason = 500

	// ReasonUnknown means error reason is not clear
	ReasonUnknown Reason = 0
)

func ErrorReason

func ErrorReason(err error) Reason

ErrorReason returns the HTTP status code for the error

type TenantParams

type TenantParams struct {
	AdminRoles      []string
	AllowedClusters []string
	Changed         bool
}

TenantParams indicates the parameters for creating a tenant

type TopicParams

type TopicParams struct {
	Persistent                        *bool
	Partitions                        *int32
	MaxProducers                      *int32
	MaxConsumers                      *int32
	MessageTTL                        *metav1.Duration
	MaxUnAckedMessagesPerConsumer     *int32
	MaxUnAckedMessagesPerSubscription *int32
	RetentionTime                     *metav1.Duration
	RetentionSize                     *resource.Quantity
	BacklogQuotaLimitTime             *metav1.Duration
	BacklogQuotaLimitSize             *resource.Quantity
	BacklogQuotaRetentionPolicy       *string
}

TopicParams indicates the parameters for creating a topic

type TopicPermission

type TopicPermission struct {
	ResourceName string
	Roles        []string
	Actions      []string
}

TopicPermission is the parameters to grant permission for a topic

func (*TopicPermission) Grant

func (t *TopicPermission) Grant(client pulsar.Client) error

Grant implements the grant method for topic permission

func (*TopicPermission) Revoke

func (t *TopicPermission) Revoke(client pulsar.Client) error

Revoke implements the revoke method for topic permission

Jump to

Keyboard shortcuts

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