Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) AddUserToDatabaseRole(ctx context.Context, role string, db string, user string) error
- func (c *Client) AddUserToServerRole(ctx context.Context, role string, userID string) error
- func (c *Client) CreateDatabaseUserForPrincipal(ctx context.Context, db, principal string) error
- func (c *Client) CreateLogin(ctx context.Context, loginType LoginType, username, password string) error
- func (c *Client) DeleteUserFromServer(ctx context.Context, userName string) error
- func (c *Client) GetDatabase(ctx context.Context, id int64) (*DbModel, error)
- func (c *Client) GetDatabaseRole(ctx context.Context, dbName string, id string) (*RoleModel, error)
- func (c *Client) GetServer(ctx context.Context) (*ServerModel, error)
- func (c *Client) GetServerPrincipalForDatabasePrincipal(ctx context.Context, dbName string, principalID int64) (*UserModel, error)
- func (c *Client) GetServerRole(ctx context.Context, id string) (*RoleModel, error)
- func (c *Client) GetUserFromDb(ctx context.Context, db, principalId string) (*UserDBModel, error)
- func (c *Client) GetUserPrincipal(ctx context.Context, userId string) (*UserModel, error)
- func (c *Client) GetUserPrincipalByName(ctx context.Context, name string) (*UserModel, error)
- func (c *Client) GrantPermissionOnDatabase(ctx context.Context, permission, db, user string) error
- func (c *Client) ListDatabasePermissions(ctx context.Context, dbName string, pager *Pager) ([]*PermissionModel, string, error)
- func (c *Client) ListDatabaseRolePrincipals(ctx context.Context, dbName string, databaseRoleID string, pager *Pager) ([]*RolePrincipalModel, string, error)
- func (c *Client) ListDatabaseRoles(ctx context.Context, dbName string, pager *Pager) ([]*RoleModel, string, error)
- func (c *Client) ListDatabaseUserPrincipals(ctx context.Context, dbName string, pager *Pager) ([]*UserModel, string, error)
- func (c *Client) ListDatabases(ctx context.Context, pager *Pager) ([]*DbModel, string, error)
- func (c *Client) ListGroupPrincipals(ctx context.Context, pager *Pager) ([]*GroupModel, string, error)
- func (c *Client) ListServerPermissions(ctx context.Context, pager *Pager) ([]*PermissionModel, string, error)
- func (c *Client) ListServerRolePrincipals(ctx context.Context, serverRoleID string, pager *Pager) ([]*RolePrincipalModel, string, error)
- func (c *Client) ListServerRoles(ctx context.Context, pager *Pager) ([]*RoleModel, string, error)
- func (c *Client) ListServerUserPrincipals(ctx context.Context, pager *Pager) ([]*UserModel, string, error)
- func (c *Client) RevokePermissionOnDatabase(ctx context.Context, permission, db, user string) error
- func (c *Client) RevokeUserToDatabaseRole(ctx context.Context, role string, db string, user string) error
- func (c *Client) RevokeUserToServerRole(ctx context.Context, role string, user string) error
- type DbModel
- type GroupModel
- type LoginType
- type Pager
- type PermissionModel
- type RoleModel
- type RolePrincipalModel
- type ServerModel
- type UserDBModel
- type UserModel
Constants ¶
View Source
const ( MaxPageSize = 100 MinPageSize = 10 )
View Source
const ( UserType = "user" DatabaseUserType = "database-user" )
View Source
const DatabaseRoleType = "database-role"
View Source
const DatabaseType = "database"
View Source
const GroupType = "group"
View Source
const ServerRoleType = "server-role"
View Source
const ServerType = "server"
Variables ¶
View Source
var DatabasePermissions = map[string]string{
"AADS": "Alter Any Database Event Session",
"AAMK": "Alter Any Mask",
"AEDS": "Alter Any External Data Source",
"AEFF": "Alter Any External File Format",
"AL": "Alter",
"ALAK": "Alter Any Asymmetric Key",
"ALAR": "Alter Any Application Role",
"ALAS": "Alter Any Assembly",
"ALCF": "Alter Any Certificate",
"ALDS": "Alter Any Dataspace",
"ALED": "Alter Any Database Event Notification",
"ALFT": "Alter Any Fulltext Catalog",
"ALMT": "Alter Any Message Type",
"ALRL": "Alter Any Role",
"ALRT": "Alter Any Route",
"ALSB": "Alter Any Remote Service Binding",
"ALSC": "Alter Any Contract",
"ALSK": "Alter Any Symmetric Key",
"ALSM": "Alter Any Schema",
"ALSV": "Alter Any Service",
"ALTG": "Alter Any Database DDL Trigger",
"ALUS": "Alter Any User",
"AUTH": "Authenticate",
"BADB": "Backup Database",
"BALO": "Backup Log",
"CL": "Control",
"CO": "Connect",
"CORP": "Connect Replication",
"CP": "Checkpoint",
"CRAG": "Create Aggregate",
"CRAK": "Create Asymmetric Key",
"CRAS": "Create Certificate",
"CRDB": "Create Fatabase",
"CRDF": "Create Default",
"CRED": "Create Database DDL Event Notification",
"CRFN": "Create Function",
"CRFT": "Create Fulltext Catalog",
"CRMT": "Create Message Type",
"CRPR": "Create Procedure",
"CRQU": "Create Queue",
"CRRL": "Create Role",
"CRRT": "Create Route",
"CRRU": "Create Rule",
"CRSB": "Create Remote Service Binding",
"CRSC": "Create contract",
"CRSK": "Create symmetric key",
"CRSM": "Create Schema",
"CRSN": "Create Synonym",
"CRSO": "Create Sequence",
"CRSV": "Create Service",
"CRTB": "Create Table",
"CRTY": "Create Type",
"CRVW": "Create View",
"CRXS": "Create XML Schema Collection",
"DL": "Delete",
"DABO": "Administer Database Bulk Operations",
"EAES": "Execute Any External Script",
"EX": "Execute",
"IN": "Insert",
"RC": "Receive Object",
"RF": "References",
"SL": "Select",
"SPLN": "Showplan",
"SUQN": "Subscribe Query Notifications",
"TO": "Take Ownership",
"UP": "Update",
"VW": "View Definition",
"VWCK": "View Any Column Encryption Key Definition",
"VWCM": "View Any Column Master Key Definition",
"VWCT": "View Change Tracking",
"VWDS": "View Database State Database",
}
View Source
var ErrNoServerPrincipal = errors.New("no server principal found")
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddUserToDatabaseRole ¶ added in v0.0.9
func (*Client) AddUserToServerRole ¶ added in v0.0.9
func (*Client) CreateDatabaseUserForPrincipal ¶ added in v0.0.9
func (*Client) CreateLogin ¶ added in v0.0.9
func (c *Client) CreateLogin(ctx context.Context, loginType LoginType, username, password string) error
CreateLogin creates a SQL Server login with the specified authentication type. For Windows authentication (loginType=WINDOWS):
- If domain is provided, it will create the login in the format [DOMAIN\Username]
- otherwise it will use just [Username]
For SQL authentication (loginType=SQL):
- It requires a password
- Domain is ignored
For Azure AD authentication (loginType=AZURE_AD):
- It creates from EXTERNAL PROVIDER
- Username should be the full Azure AD username/email
For Entra ID authentication (loginType=ENTRA_ID):
- It creates from EXTERNAL PROVIDER
- Username should be the full Entra ID username/email
func (*Client) DeleteUserFromServer ¶ added in v0.0.12
func (*Client) GetDatabase ¶
func (*Client) GetDatabaseRole ¶ added in v0.0.9
func (*Client) GetServerPrincipalForDatabasePrincipal ¶
func (c *Client) GetServerPrincipalForDatabasePrincipal(ctx context.Context, dbName string, principalID int64) (*UserModel, error)
GetServerPrincipalForDatabasePrincipal returns the server principal for a given database user. Returns ErrNoServerPrincipal if no server principal is found.
func (*Client) GetServerRole ¶ added in v0.0.9
func (*Client) GetUserFromDb ¶ added in v0.0.9
GetUserFromDb find db user from Server principal.
func (*Client) GetUserPrincipal ¶ added in v0.0.9
func (*Client) GetUserPrincipalByName ¶ added in v0.0.9
func (*Client) GrantPermissionOnDatabase ¶ added in v0.0.9
func (*Client) ListDatabasePermissions ¶
func (*Client) ListDatabaseRolePrincipals ¶
func (*Client) ListDatabaseRoles ¶
func (*Client) ListDatabaseUserPrincipals ¶
func (*Client) ListDatabases ¶
func (*Client) ListGroupPrincipals ¶
func (*Client) ListServerPermissions ¶
func (*Client) ListServerRolePrincipals ¶
func (*Client) ListServerRoles ¶
func (*Client) ListServerUserPrincipals ¶
func (*Client) RevokePermissionOnDatabase ¶ added in v0.0.9
func (*Client) RevokeUserToDatabaseRole ¶ added in v0.0.9
type GroupModel ¶
type LoginType ¶ added in v0.0.9
type LoginType string
LoginType represents the SQL Server login type.
const ( // LoginTypeWindows represents Windows authentication. LoginTypeWindows LoginType = "WINDOWS" // LoginTypeSQL represents SQL Server authentication. LoginTypeSQL LoginType = "SQL" // LoginTypeAzureAD represents Azure AD authentication. LoginTypeAzureAD LoginType = "AZURE_AD" // LoginTypeEntraID represents Azure Entra ID authentication. LoginTypeEntraID LoginType = "ENTRA_ID" )
type PermissionModel ¶
type RolePrincipalModel ¶
type ServerModel ¶
type ServerModel struct {
Name string `db:"ServerName"`
}
type UserDBModel ¶ added in v0.0.9
type UserDBModel struct {
ID string `db:"principal_id"`
DatabasePrincipalId string `db:"database_principal_id"`
Sid string `db:"sid"`
Name string `db:"name"`
Type string `db:"type_desc"`
CreateDate string `db:"create_date"`
ModifyDate string `db:"modify_date"`
OwningPrincipalId string `db:"owning_principal_id"`
}
Click to show internal directories.
Click to hide internal directories.