{"modulePath":"github.com/spiffe/spire","version":"v0.12.3","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package sql\n\n## Constants\n\n```go\nconst (\n\tPluginName = \"sql\"\n\n\t// MySQL database type\n\tMySQL = \"mysql\"\n\t// PostgreSQL database type\n\tPostgreSQL = \"postgres\"\n\t// SQLite database type\n\tSQLite = \"sqlite3\"\n)\n```\n\n## Functions\n\n```go\nfunc BuiltIn() catalog.Plugin\n```\n\n## Types\n\n```go\ntype AttestedNode struct {\n\tModel\n\n\tSpiffeID        string `gorm:\"unique_index\"`\n\tDataType        string\n\tSerialNumber    string\n\tExpiresAt       time.Time `gorm:\"index\"`\n\tNewSerialNumber string\n\tNewExpiresAt    *time.Time\n\n\tSelectors []*NodeSelector\n}\n```\nAttestedNode holds an attested node (agent)\n\n```go\nfunc (AttestedNode) TableName() string\n```\nTableName gets table name of AttestedNode\n\n```go\ntype Bundle struct {\n\tModel\n\n\tTrustDomain string `gorm:\"not null;unique_index\"`\n\tData        []byte `gorm:\"size:16777215\"` // make MySQL to use MEDIUMBLOB (max 24MB) - doesn't affect PostgreSQL/SQLite\n\n\tFederatedEntries []RegisteredEntry `gorm:\"many2many:federated_registration_entries;\"`\n}\n```\nBundle holds a trust bundle.\n\n```go\ntype DNSName struct {\n\tModel\n\n\tRegisteredEntryID uint   `gorm:\"unique_index:idx_dns_entry\"`\n\tValue             string `gorm:\"unique_index:idx_dns_entry\"`\n}\n```\nDNSName holds a DNS for a registration entry\n\n```go\nfunc (DNSName) TableName() string\n```\nTableName gets table name for DNS entries\n\n```go\ntype JoinToken struct {\n\tModel\n\n\tToken  string `gorm:\"unique_index\"`\n\tExpiry int64\n}\n```\nJoinToken holds a join token\n\n```go\ntype Migration struct {\n\tModel\n\n\t// Database version\n\tVersion int\n\n\t// SPIRE Code versioning\n\tCodeVersion string\n}\n```\nMigration holds database schema version number, and the SPIRE Code version number\n\n```go\ntype Model struct {\n\tID        uint `gorm:\"primary_key\"`\n\tCreatedAt time.Time\n\tUpdatedAt time.Time\n}\n```\nModel is used as a base for other models. Similar to gorm.Model without \\`DeletedAt\\`. We don't want soft-delete support.\n\n```go\ntype NodeSelector struct {\n\tModel\n\n\tSpiffeID string `gorm:\"unique_index:idx_node_resolver_map\"`\n\tType     string `gorm:\"unique_index:idx_node_resolver_map\"`\n\tValue    string `gorm:\"unique_index:idx_node_resolver_map\"`\n}\n```\nNodeSelector holds a node selector by spiffe ID\n\n```go\nfunc (NodeSelector) TableName() string\n```\nTableName gets table name of NodeSelector\n\n```go\ntype Plugin struct {\n\tdatastore.UnsafeDataStoreServer\n\t// contains filtered or unexported fields\n}\n```\nPlugin is a DataStore plugin implemented via a SQL database\n\n```go\nfunc New() *Plugin\n```\nNew creates a new sql plugin struct. Configure must be called in order to start the db.\n\n```go\nfunc (ds *Plugin) AppendBundle(ctx context.Context, req *datastore.AppendBundleRequest) (resp *datastore.AppendBundleResponse, err error)\n```\nAppendBundle append bundle contents to the existing bundle (by trust domain). If no existing one is present, create it.\n\n```go\nfunc (ds *Plugin) Configure(ctx context.Context, req *spi.ConfigureRequest) (*spi.ConfigureResponse, error)\n```\nConfigure parses HCL config payload into config struct, and opens new DB based on the result\n\n```go\nfunc (ds *Plugin) CountAttestedNodes(ctx context.Context,\n\treq *datastore.CountAttestedNodesRequest) (resp *datastore.CountAttestedNodesResponse, err error)\n```\nCountAttestedNodes counts all attested nodes\n\n```go\nfunc (ds *Plugin) CountBundles(ctx context.Context, req *datastore.CountBundlesRequest) (resp *datastore.CountBundlesResponse, err error)\n```\nCountBundles can be used to count all existing bundles.\n\n```go\nfunc (ds *Plugin) CountRegistrationEntries(ctx context.Context,\n\treq *datastore.CountRegistrationEntriesRequest) (resp *datastore.CountRegistrationEntriesResponse, err error)\n```\nCounCountRegistrationEntries counts all registrations (pagination available)\n\n```go\nfunc (ds *Plugin) CreateAttestedNode(ctx context.Context,\n\treq *datastore.CreateAttestedNodeRequest) (resp *datastore.CreateAttestedNodeResponse, err error)\n```\nCreateAttestedNode stores the given attested node\n\n```go\nfunc (ds *Plugin) CreateBundle(ctx context.Context, req *datastore.CreateBundleRequest) (resp *datastore.CreateBundleResponse, err error)\n```\nCreateBundle stores the given bundle\n\n```go\nfunc (ds *Plugin) CreateJoinToken(ctx context.Context, req *datastore.CreateJoinTokenRequest) (resp *datastore.CreateJoinTokenResponse, err error)\n```\nCreateJoinToken takes a Token message and stores it\n\n```go\nfunc (ds *Plugin) CreateRegistrationEntry(ctx context.Context,\n\treq *datastore.CreateRegistrationEntryRequest) (resp *datastore.CreateRegistrationEntryResponse, err error)\n```\nCreateRegistrationEntry stores the given registration entry\n\n```go\nfunc (ds *Plugin) DeleteAttestedNode(ctx context.Context,\n\treq *datastore.DeleteAttestedNodeRequest) (resp *datastore.DeleteAttestedNodeResponse, err error)\n```\nDeleteAttestedNode deletes the given attested node\n\n```go\nfunc (ds *Plugin) DeleteBundle(ctx context.Context, req *datastore.DeleteBundleRequest) (resp *datastore.DeleteBundleResponse, err error)\n```\nDeleteBundle deletes the bundle with the matching TrustDomain. Any CACert data passed is ignored.\n\n```go\nfunc (ds *Plugin) DeleteJoinToken(ctx context.Context, req *datastore.DeleteJoinTokenRequest) (resp *datastore.DeleteJoinTokenResponse, err error)\n```\nDeleteJoinToken deletes the given join token\n\n```go\nfunc (ds *Plugin) DeleteRegistrationEntry(ctx context.Context,\n\treq *datastore.DeleteRegistrationEntryRequest) (resp *datastore.DeleteRegistrationEntryResponse, err error)\n```\nDeleteRegistrationEntry deletes the given registration\n\n```go\nfunc (ds *Plugin) FetchAttestedNode(ctx context.Context,\n\treq *datastore.FetchAttestedNodeRequest) (resp *datastore.FetchAttestedNodeResponse, err error)\n```\nFetchAttestedNode fetches an existing attested node by SPIFFE ID\n\n```go\nfunc (ds *Plugin) FetchBundle(ctx context.Context, req *datastore.FetchBundleRequest) (resp *datastore.FetchBundleResponse, err error)\n```\nFetchBundle returns the bundle matching the specified Trust Domain.\n\n```go\nfunc (ds *Plugin) FetchJoinToken(ctx context.Context, req *datastore.FetchJoinTokenRequest) (resp *datastore.FetchJoinTokenResponse, err error)\n```\nFetchJoinToken takes a Token message and returns one, populating the fields we have knowledge of\n\n```go\nfunc (ds *Plugin) FetchRegistrationEntry(ctx context.Context,\n\treq *datastore.FetchRegistrationEntryRequest) (resp *datastore.FetchRegistrationEntryResponse, err error)\n```\nFetchRegistrationEntry fetches an existing registration by entry ID\n\n```go\nfunc (ds *Plugin) GetNodeSelectors(ctx context.Context,\n\treq *datastore.GetNodeSelectorsRequest) (resp *datastore.GetNodeSelectorsResponse, err error)\n```\nGetNodeSelectors gets node (agent) selectors by SPIFFE ID\n\n```go\nfunc (*Plugin) GetPluginInfo(context.Context, *spi.GetPluginInfoRequest) (*spi.GetPluginInfoResponse, error)\n```\nGetPluginInfo returns the sql plugin\n\n```go\nfunc (ds *Plugin) ListAttestedNodes(ctx context.Context,\n\treq *datastore.ListAttestedNodesRequest) (resp *datastore.ListAttestedNodesResponse, err error)\n```\nListAttestedNodes lists all attested nodes (pagination available)\n\n```go\nfunc (ds *Plugin) ListBundles(ctx context.Context, req *datastore.ListBundlesRequest) (resp *datastore.ListBundlesResponse, err error)\n```\nListBundles can be used to fetch all existing bundles.\n\n```go\nfunc (ds *Plugin) ListNodeSelectors(ctx context.Context,\n\treq *datastore.ListNodeSelectorsRequest) (resp *datastore.ListNodeSelectorsResponse, err error)\n```\nListNodeSelectors gets node (agent) selectors by SPIFFE ID\n\n```go\nfunc (ds *Plugin) ListRegistrationEntries(ctx context.Context,\n\treq *datastore.ListRegistrationEntriesRequest) (resp *datastore.ListRegistrationEntriesResponse, err error)\n```\nListRegistrationEntries lists all registrations (pagination available)\n\n```go\nfunc (ds *Plugin) PruneBundle(ctx context.Context, req *datastore.PruneBundleRequest) (resp *datastore.PruneBundleResponse, err error)\n```\nPruneBundle removes expired certs and keys from a bundle\n\n```go\nfunc (ds *Plugin) PruneJoinTokens(ctx context.Context, req *datastore.PruneJoinTokensRequest) (resp *datastore.PruneJoinTokensResponse, err error)\n```\nPruneJoinTokens takes a Token message, and deletes all tokens which have expired before the date in the message\n\n```go\nfunc (ds *Plugin) PruneRegistrationEntries(ctx context.Context, req *datastore.PruneRegistrationEntriesRequest) (resp *datastore.PruneRegistrationEntriesResponse, err error)\n```\nPruneRegistrationEntries takes a registration entry message, and deletes all entries which have expired before the date in the message\n\n```go\nfunc (ds *Plugin) SetBundle(ctx context.Context, req *datastore.SetBundleRequest) (resp *datastore.SetBundleResponse, err error)\n```\nSetBundle sets bundle contents. If no bundle exists for the trust domain, it is created.\n\n```go\nfunc (ds *Plugin) SetLogger(logger hclog.Logger)\n```\n\n```go\nfunc (ds *Plugin) SetNodeSelectors(ctx context.Context, req *datastore.SetNodeSelectorsRequest) (resp *datastore.SetNodeSelectorsResponse, err error)\n```\nSetNodeSelectors sets node (agent) selectors by SPIFFE ID, deleting old selectors first\n\n```go\nfunc (ds *Plugin) UpdateAttestedNode(ctx context.Context,\n\treq *datastore.UpdateAttestedNodeRequest) (resp *datastore.UpdateAttestedNodeResponse, err error)\n```\nUpdateAttestedNode updates the given node's cert serial and expiration.\n\n```go\nfunc (ds *Plugin) UpdateBundle(ctx context.Context, req *datastore.UpdateBundleRequest) (resp *datastore.UpdateBundleResponse, err error)\n```\nUpdateBundle updates an existing bundle with the given CAs. Overwrites any existing certificates.\n\n```go\nfunc (ds *Plugin) UpdateRegistrationEntry(ctx context.Context,\n\treq *datastore.UpdateRegistrationEntryRequest) (resp *datastore.UpdateRegistrationEntryResponse, err error)\n```\nUpdateRegistrationEntry updates an existing registration entry\n\n```go\ntype RegisteredEntry struct {\n\tModel\n\n\tEntryID  string `gorm:\"unique_index\"`\n\tSpiffeID string `gorm:\"index\"`\n\tParentID string `gorm:\"index\"`\n\t// TTL of identities derived from this entry\n\tTTL           int32\n\tSelectors     []Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n\tDownstream    bool\n\t// (optional) expiry of this entry\n\tExpiry int64 `gorm:\"index\"`\n\t// (optional) DNS entries\n\tDNSList []DNSName\n\n\t// RevisionNumber is a counter that is incremented when the entry is\n\t// updated.\n\tRevisionNumber int64\n}\n```\nRegisteredEntry holds a registered entity entry\n\n```go\ntype Selector struct {\n\tModel\n\n\tRegisteredEntryID uint   `gorm:\"unique_index:idx_selector_entry\"`\n\tType              string `gorm:\"unique_index:idx_selector_entry;index:idx_selectors_type_value\"`\n\tValue             string `gorm:\"unique_index:idx_selector_entry;index:idx_selectors_type_value\"`\n}\n```\n\n```go\ntype V10RegisteredEntry struct {\n\tModel\n\n\tEntryID  string `gorm:\"unique_index\"`\n\tSpiffeID string `gorm:\"index\"`\n\tParentID string `gorm:\"index\"`\n\t// TTL of identities derived from this entry\n\tTTL           int32\n\tSelectors     []Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n\tDownstream    bool\n\t// (optional) expiry of this entry\n\tExpiry int64 `gorm:\"index\"`\n\t// (optional) DNS entries\n\tDNSList []DNSName\n}\n```\nV10RegisteredEntry holds a registered entity entry\n\n```go\nfunc (V10RegisteredEntry) TableName() string\n```\nTableName gets table name for v10 registered entry\n\n```go\ntype V11Migration struct {\n\tModel\n\n\t// Database version\n\tVersion int\n}\n```\n\n```go\nfunc (V11Migration) TableName() string\n```\nTableName gets table name for v11 migrations table\n\n```go\ntype V3AttestedNode struct {\n\tModel\n\n\tSpiffeID     string `gorm:\"unique_index\"`\n\tDataType     string\n\tSerialNumber string\n\tExpiresAt    time.Time\n}\n```\n\n```go\nfunc (V3AttestedNode) TableName() string\n```\n\n```go\ntype V3Bundle struct {\n\tModel\n\n\tTrustDomain string `gorm:\"not null;unique_index\"`\n\tCACerts     []V3CACert\n\n\tFederatedEntries []RegisteredEntry `gorm:\"many2many:federated_registration_entries;\"`\n}\n```\nV3Bundle holds a version 3 trust bundle\n\n```go\nfunc (V3Bundle) TableName() string\n```\nTableName get table name for v3 bundle\n\n```go\ntype V3CACert struct {\n\tModel\n\n\tCert   []byte    `gorm:\"not null\"`\n\tExpiry time.Time `gorm:\"not null;index\"`\n\n\tBundleID uint `gorm:\"not null;index\" sql:\"type:integer REFERENCES bundles(id)\"`\n}\n```\nV3CACert holds a version 3 CA certificate\n\n```go\nfunc (V3CACert) TableName() string\n```\nTableName gets table name for v3 bundle\n\n```go\ntype V4RegisteredEntry struct {\n\tModel\n\n\tEntryID       string `gorm:\"unique_index\"`\n\tSpiffeID      string\n\tParentID      string\n\tTTL           int32\n\tSelectors     []V8Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n}\n```\nV4RegisteredEntry holds a version 4 registered entry\n\n```go\nfunc (V4RegisteredEntry) TableName() string\n```\nTableName gets table name for v4 registered entry\n\n```go\ntype V5RegisteredEntry struct {\n\tModel\n\n\tEntryID       string `gorm:\"unique_index\"`\n\tSpiffeID      string\n\tParentID      string\n\tTTL           int32\n\tSelectors     []V8Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n}\n```\nV5RegisteredEntry holds a version 5 registered entry\n\n```go\nfunc (V5RegisteredEntry) TableName() string\n```\nTableName gets table name for v5 registered entry\n\n```go\ntype V6RegisteredEntry struct {\n\tModel\n\n\tEntryID       string `gorm:\"unique_index\"`\n\tSpiffeID      string\n\tParentID      string\n\tTTL           int32\n\tSelectors     []V8Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n\tDownstream    bool\n}\n```\nV6RegisteredEntry holds a version 6 registered entry\n\n```go\nfunc (V6RegisteredEntry) TableName() string\n```\nTableName gets table name for v6 registered entry\n\n```go\ntype V7RegisteredEntry struct {\n\tModel\n\n\tEntryID  string `gorm:\"unique_index\"`\n\tSpiffeID string\n\tParentID string\n\t// TTL of identities derived from this entry\n\tTTL           int32\n\tSelectors     []V8Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n\tDownstream    bool\n\t// (optional) expiry of this entry\n\tExpiry int64\n}\n```\nV7RegisteredEntry holds a version 7 registered entry\n\n```go\nfunc (V7RegisteredEntry) TableName() string\n```\nTableName gets table name for v7 registered entry\n\n```go\ntype V8RegisteredEntry struct {\n\tModel\n\n\tEntryID  string `gorm:\"unique_index\"`\n\tSpiffeID string\n\tParentID string\n\t// TTL of identities derived from this entry\n\tTTL           int32\n\tSelectors     []V8Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n\tDownstream    bool\n\t// (optional) expiry of this entry\n\tExpiry int64\n\t// (optional) DNS entries\n\tDNSList []DNSName\n}\n```\n\n```go\nfunc (V8RegisteredEntry) TableName() string\n```\nTableName gets table name for v8 registered entry\n\n```go\ntype V8Selector struct {\n\tModel\n\n\tRegisteredEntryID uint   `gorm:\"unique_index:idx_selector_entry\"`\n\tType              string `gorm:\"unique_index:idx_selector_entry\"`\n\tValue             string `gorm:\"unique_index:idx_selector_entry\"`\n}\n```\n\n```go\ntype V9RegisteredEntry struct {\n\tModel\n\n\tEntryID  string `gorm:\"unique_index\"`\n\tSpiffeID string `gorm:\"index\"`\n\tParentID string `gorm:\"index\"`\n\t// TTL of identities derived from this entry\n\tTTL           int32\n\tSelectors     []Selector\n\tFederatesWith []Bundle `gorm:\"many2many:federated_registration_entries;\"`\n\tAdmin         bool\n\tDownstream    bool\n\t// (optional) expiry of this entry\n\tExpiry int64\n\t// (optional) DNS entries\n\tDNSList []DNSName\n}\n```\n\n```go\nfunc (V9RegisteredEntry) TableName() string\n```\nTableName gets table name for v9 registered entry\n\n","path":"github.com/spiffe/spire/pkg/server/plugin/datastore/sql","name":"sql","synopsis":"","isRedistributable":true}
