Export some consts/functions
Needed to allow backup filtering. Would be better to have a function that returns the values based on a Reason or something.
This commit is contained in:
parent
dab4d7f0c7
commit
1867a13f4d
@ -167,7 +167,7 @@ func New(
|
||||
for _, reason := range backup.Reasons {
|
||||
mergeBases[backup.ID] = append(
|
||||
mergeBases[backup.ID],
|
||||
serviceCatString(reason.Service(), reason.Category()))
|
||||
ServiceCatString(reason.Service(), reason.Category()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ func New(
|
||||
for _, reason := range backup.Reasons {
|
||||
assistBases[backup.ID] = append(
|
||||
assistBases[backup.ID],
|
||||
serviceCatString(reason.Service(), reason.Category()))
|
||||
ServiceCatString(reason.Service(), reason.Category()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +258,7 @@ func (b Backup) Bases() (PersistedBaseSet, error) {
|
||||
}
|
||||
|
||||
func (b Backup) Tenant() (string, error) {
|
||||
t := b.Tags[tenantIDKey]
|
||||
t := b.Tags[TenantIDKey]
|
||||
if len(t) == 0 {
|
||||
return "", clues.Wrap(errs.NotFound, "getting tenant")
|
||||
}
|
||||
|
||||
@ -24,20 +24,20 @@ const (
|
||||
// [1] https://github.com/kopia/kopia/blob/05e729a7858a6e86cb48ba29fb53cb6045efce2b/cli/command_snapshot_create.go#L169
|
||||
LegacyUserTagPrefix = "tag:"
|
||||
|
||||
tenantIDKey = "tenant"
|
||||
resourceIDKey = "protectedResource"
|
||||
TenantIDKey = "tenant"
|
||||
ResourceIDKey = "protectedResource"
|
||||
serviceCatPrefix = "sc-"
|
||||
separator = "_"
|
||||
|
||||
// Sentinel value for tags. Could technically be empty but we'll store
|
||||
// something for now.
|
||||
//nolint
|
||||
defaultTagValue = "1"
|
||||
DefaultTagValue = "1"
|
||||
)
|
||||
|
||||
var errMissingPrefix = clues.New("missing tag prefix")
|
||||
|
||||
func serviceCatString(
|
||||
func ServiceCatString(
|
||||
service path.ServiceType,
|
||||
category path.CategoryType,
|
||||
) string {
|
||||
@ -86,9 +86,9 @@ func serviceCatStringToTypes(
|
||||
// nolint
|
||||
func reasonTags(r identity.Reasoner) map[string]string {
|
||||
return map[string]string{
|
||||
tenantIDKey: r.Tenant(),
|
||||
resourceIDKey: r.ProtectedResource(),
|
||||
serviceCatString(r.Service(), r.Category()): defaultTagValue,
|
||||
TenantIDKey: r.Tenant(),
|
||||
ResourceIDKey: r.ProtectedResource(),
|
||||
ServiceCatString(r.Service(), r.Category()): DefaultTagValue,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ func (suite *BackupBasesUnitSuite) TestServiceCategorySerialization() {
|
||||
}{
|
||||
{
|
||||
name: "ProperFormat",
|
||||
input: serviceCatString(path.ExchangeService, path.EmailCategory),
|
||||
input: ServiceCatString(path.ExchangeService, path.EmailCategory),
|
||||
expectErr: assert.NoError,
|
||||
expectService: path.ExchangeService,
|
||||
expectCategory: path.EmailCategory,
|
||||
@ -38,14 +38,14 @@ func (suite *BackupBasesUnitSuite) TestServiceCategorySerialization() {
|
||||
{
|
||||
name: "MissingPrefix",
|
||||
input: strings.TrimPrefix(
|
||||
serviceCatString(path.ExchangeService, path.EmailCategory),
|
||||
ServiceCatString(path.ExchangeService, path.EmailCategory),
|
||||
serviceCatPrefix),
|
||||
expectErr: assert.Error,
|
||||
},
|
||||
{
|
||||
name: "MissingSeparator",
|
||||
input: strings.ReplaceAll(
|
||||
serviceCatString(path.ExchangeService, path.EmailCategory),
|
||||
ServiceCatString(path.ExchangeService, path.EmailCategory),
|
||||
separator,
|
||||
""),
|
||||
expectErr: assert.Error,
|
||||
|
||||
@ -104,13 +104,13 @@ func (suite *BackupUnitSuite) TestBackup_Bases() {
|
||||
res.AssistBases = map[model.StableID][]string{}
|
||||
|
||||
res.MergeBases[mergeID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
}
|
||||
|
||||
res.AssistBases[assistID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
}
|
||||
@ -133,13 +133,13 @@ func (suite *BackupUnitSuite) TestBackup_Bases() {
|
||||
res.AssistBases = map[model.StableID][]string{}
|
||||
|
||||
res.MergeBases[mergeID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
}
|
||||
|
||||
res.AssistBases[assistID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultContactsReason.Service(),
|
||||
defaultContactsReason.Category()),
|
||||
}
|
||||
@ -162,19 +162,19 @@ func (suite *BackupUnitSuite) TestBackup_Bases() {
|
||||
res.AssistBases = map[model.StableID][]string{}
|
||||
|
||||
res.MergeBases[mergeID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultContactsReason.Service(),
|
||||
defaultContactsReason.Category()),
|
||||
}
|
||||
|
||||
res.AssistBases[assistID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultContactsReason.Service(),
|
||||
defaultContactsReason.Category()),
|
||||
}
|
||||
@ -202,7 +202,7 @@ func (suite *BackupUnitSuite) TestBackup_Bases() {
|
||||
res.MergeBases = map[model.StableID][]string{}
|
||||
|
||||
res.MergeBases[mergeID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
}
|
||||
@ -221,7 +221,7 @@ func (suite *BackupUnitSuite) TestBackup_Bases() {
|
||||
res.AssistBases = map[model.StableID][]string{}
|
||||
|
||||
res.AssistBases[mergeID] = []string{
|
||||
serviceCatString(
|
||||
ServiceCatString(
|
||||
defaultEmailReason.Service(),
|
||||
defaultEmailReason.Category()),
|
||||
}
|
||||
@ -298,7 +298,7 @@ func (suite *BackupUnitSuite) TestBackup_Tenant() {
|
||||
}{
|
||||
{
|
||||
name: "ProperlyFormatted",
|
||||
inputKey: tenantIDKey,
|
||||
inputKey: TenantIDKey,
|
||||
inputValue: tenant,
|
||||
expectErr: assert.NoError,
|
||||
expect: tenant,
|
||||
@ -311,7 +311,7 @@ func (suite *BackupUnitSuite) TestBackup_Tenant() {
|
||||
},
|
||||
{
|
||||
name: "EmptyValue",
|
||||
inputKey: tenantIDKey,
|
||||
inputKey: TenantIDKey,
|
||||
inputValue: "",
|
||||
expectErr: assert.Error,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user