Migrate plugin host/set/catalog prefixes to typed (#2256)

* Migrate plugin host/set/catalog prefixes to typed

* Add credential store typing too
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2022-07-15 13:09:55 -04:00
1 parent 674b9627af
commit 8c56a5648d
20 files changed
+178 -71

No files matched your search

@@ -360,6 +360,9 @@ func (s Service) updateInRepo(
switch subtypes.SubtypeFromId(domain, id) {
case static.UsernamePasswordSubtype:
cred, err := toUsernamePasswordStorageCredential(storeId, in)
if err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to convert to username/password storage credential"))
}
cred.PublicId = id
repo, err := s.repoFn()
if err != nil {
@@ -530,7 +533,7 @@ func toUsernamePasswordStorageCredential(storeId string, in *pb.Credential) (out
// * All required parameters are set
// * There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetCredentialRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.CredentialPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.UsernamePasswordCredentialPrefix, static.PreviousUsernamePasswordCredentialPrefix)
}
func validateCreateRequest(req *pbs.CreateCredentialRequest) error {
@@ -539,7 +542,7 @@ func validateCreateRequest(req *pbs.CreateCredentialRequest) error {
if req.Item.GetType() != static.UsernamePasswordSubtype.String() {
badFields[globals.TypeField] = fmt.Sprintf("Unsupported credential type %q", req.Item.GetType())
}
if !handlers.ValidId(handlers.Id(req.Item.GetCredentialStoreId()), static.CredentialStorePrefix) {
if !handlers.ValidId(handlers.Id(req.Item.GetCredentialStoreId()), static.CredentialStorePrefix, static.PreviousCredentialStorePrefix) {
badFields[globals.CredentialStoreIdField] = "This field must be a valid credential store id."
}
@@ -570,16 +573,16 @@ func validateUpdateRequest(req *pbs.UpdateCredentialRequest) error {
}
return badFields
}, static.CredentialPrefix)
}, static.UsernamePasswordCredentialPrefix, static.PreviousUsernamePasswordCredentialPrefix)
}
func validateDeleteRequest(req *pbs.DeleteCredentialRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.CredentialPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.UsernamePasswordCredentialPrefix, static.PreviousUsernamePasswordCredentialPrefix)
}
func validateListRequest(req *pbs.ListCredentialsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetCredentialStoreId()), static.CredentialStorePrefix) {
if !handlers.ValidId(handlers.Id(req.GetCredentialStoreId()), static.CredentialStorePrefix, static.PreviousCredentialStorePrefix) {
badFields[globals.CredentialStoreIdField] = "This field must be a valid credential store id."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -172,6 +172,7 @@ func TestGet(t *testing.T) {
store := static.TestCredentialStore(t, conn, wrapper, prj.GetPublicId())
cred := static.TestUsernamePasswordCredential(t, conn, wrapper, "user", "pass", store.GetPublicId(), prj.GetPublicId())
credPrev := static.TestUsernamePasswordCredential(t, conn, wrapper, "user", "pass", store.GetPublicId(), prj.GetPublicId(), static.WithPublicId(fmt.Sprintf("%s_1234567890", static.PreviousUsernamePasswordCredentialPrefix)))
s, err := NewService(staticRepoFn, iamRepoFn)
require.NoError(t, err)
@@ -209,9 +210,31 @@ func TestGet(t *testing.T) {
},
},
},
{
name: "success-prev-prefix",
id: credPrev.GetPublicId(),
res: &pbs.GetCredentialResponse{
Item: &pb.Credential{
Id: credPrev.GetPublicId(),
CredentialStoreId: cred.GetStoreId(),
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: static.UsernamePasswordSubtype.String(),
AuthorizedActions: testAuthorizedActions,
CreatedTime: credPrev.CreateTime.GetTimestamp(),
UpdatedTime: credPrev.UpdateTime.GetTimestamp(),
Version: 1,
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
Username: wrapperspb.String("user"),
PasswordHmac: base64.RawURLEncoding.EncodeToString([]byte(hm)),
},
},
},
},
},
{
name: "not found error",
id: fmt.Sprintf("%s_1234567890", static.CredentialPrefix),
id: fmt.Sprintf("%s_1234567890", static.UsernamePasswordCredentialPrefix),
err: handlers.NotFoundError(),
},
{
@@ -279,7 +302,7 @@ func TestDelete(t *testing.T) {
},
{
name: "not found error",
id: fmt.Sprintf("%s_1234567890", static.CredentialPrefix),
id: fmt.Sprintf("%s_1234567890", static.UsernamePasswordCredentialPrefix),
err: handlers.NotFoundError(),
},
{
@@ -334,7 +357,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Id: static.CredentialPrefix + "_notallowed",
Id: static.UsernamePasswordCredentialPrefix + "_notallowed",
Type: static.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
@@ -446,9 +469,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: static.CredentialPrefix + "_",
idPrefix: static.UsernamePasswordCredentialPrefix + "_",
res: &pbs.CreateCredentialResponse{
Uri: fmt.Sprintf("credentials/%s_", static.CredentialPrefix),
Uri: fmt.Sprintf("credentials/%s_", static.UsernamePasswordCredentialPrefix),
Item: &pb.Credential{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -759,7 +759,7 @@ func toStorageVaultStore(scopeId string, in *pb.CredentialStore) (out *vault.Cre
// * All required parameters are set
// * There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetCredentialStoreRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, vault.CredentialStorePrefix, static.CredentialStorePrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, vault.CredentialStorePrefix, static.CredentialStorePrefix, static.PreviousCredentialStorePrefix)
}
func validateCreateRequest(req *pbs.CreateCredentialStoreRequest) error {
@@ -845,11 +845,11 @@ func validateUpdateRequest(req *pbs.UpdateCredentialStoreRequest) error {
}
}
return badFields
}, vault.CredentialStorePrefix, static.CredentialStorePrefix)
}, vault.CredentialStorePrefix, static.CredentialStorePrefix, static.PreviousCredentialStorePrefix)
}
func validateDeleteRequest(req *pbs.DeleteCredentialStoreRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, vault.CredentialStorePrefix, static.CredentialStorePrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, vault.CredentialStorePrefix, static.CredentialStorePrefix, static.PreviousCredentialStorePrefix)
}
func validateListRequest(req *pbs.ListCredentialStoresRequest) error {
@@ -739,6 +739,7 @@ func TestGet(t *testing.T) {
vaultStore := vault.TestCredentialStores(t, conn, wrapper, prj.GetPublicId(), 1)[0]
staticStore := credstatic.TestCredentialStore(t, conn, wrapper, prj.GetPublicId())
staticStorePrev := credstatic.TestCredentialStore(t, conn, wrapper, prj.GetPublicId(), credstatic.WithPublicId(fmt.Sprintf("%s_1234567890", credstatic.PreviousCredentialStorePrefix)))
s, err := NewService(vaultRepoFn, staticRepoFn, iamRepoFn)
require.NoError(t, err)
@@ -790,6 +791,23 @@ func TestGet(t *testing.T) {
},
},
},
{
name: "static prev prefix success",
id: staticStorePrev.GetPublicId(),
res: &pbs.GetCredentialStoreResponse{
Item: &pb.CredentialStore{
Id: staticStorePrev.GetPublicId(),
ScopeId: staticStorePrev.GetScopeId(),
Scope: &scopepb.ScopeInfo{Id: staticStorePrev.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
Type: credstatic.Subtype.String(),
AuthorizedActions: testAuthorizedActions,
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
CreatedTime: staticStorePrev.CreateTime.GetTimestamp(),
UpdatedTime: staticStorePrev.UpdateTime.GetTimestamp(),
Version: 1,
},
},
},
{
name: "vault not found error",
id: fmt.Sprintf("%s_1234567890", vault.CredentialStorePrefix),
@@ -820,7 +820,7 @@ func toStoragePluginCatalog(ctx context.Context, scopeId, plgId string, item *pb
// * The type asserted by the ID and/or field is known
// * If relevant, the type derived from the id prefix matches what is claimed by the type field
func validateGetRequest(req *pbs.GetHostCatalogRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix)
}
func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
@@ -876,11 +876,11 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error {
}
}
return badFields
}, static.HostCatalogPrefix, plugin.HostCatalogPrefix)
}, static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix)
}
func validateDeleteRequest(req *pbs.DeleteHostCatalogRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix)
}
func validateListRequest(req *pbs.ListHostCatalogsRequest) error {
@@ -186,6 +186,7 @@ func TestGet_Plugin(t *testing.T) {
name := "test"
plg := host.TestPlugin(t, conn, name)
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar")))
hcPrev := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar")), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", plugin.PreviousHostCatalogPrefix)))
toMerge := &pbs.GetHostCatalogRequest{
Id: hc.GetPublicId(),
@@ -224,6 +225,17 @@ func TestGet_Plugin(t *testing.T) {
req: &pbs.GetHostCatalogRequest{Id: hc.GetPublicId()},
res: &pbs.GetHostCatalogResponse{Item: pHostCatalog},
},
{
name: "Get an Existing Previous-ID HostCatalog",
req: &pbs.GetHostCatalogRequest{Id: hcPrev.GetPublicId()},
res: func() *pbs.GetHostCatalogResponse {
resp := proto.Clone(pHostCatalog).(*pb.HostCatalog)
resp.Id = hcPrev.PublicId
resp.CreatedTime = hcPrev.CreateTime.GetTimestamp()
resp.UpdatedTime = hcPrev.UpdateTime.GetTimestamp()
return &pbs.GetHostCatalogResponse{Item: resp}
}(),
},
{
name: "Get a non existing Host Catalog",
req: &pbs.GetHostCatalogRequest{Id: plugin.HostCatalogPrefix + "_DoesntExis"},
@@ -943,13 +943,13 @@ func toStoragePluginSet(ctx context.Context, catalogId string, item *pb.HostSet)
// * The type asserted by the ID and/or field is known
// * If relevant, the type derived from the id prefix matches what is claimed by the type field
func validateGetRequest(req *pbs.GetHostSetRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix)
}
func validateCreateRequest(ctx context.Context, req *pbs.CreateHostSetRequest) error {
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix) {
badFields[globals.HostCatalogIdField] = "The field is incorrectly formatted."
}
if len(req.GetItem().GetPreferredEndpoints()) > 0 {
@@ -1002,16 +1002,16 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateHostSetRequest) e
}
}
return badFields
}, static.HostSetPrefix, plugin.HostSetPrefix)
}, static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix)
}
func validateDeleteRequest(req *pbs.DeleteHostSetRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix)
}
func validateListRequest(req *pbs.ListHostSetsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix) {
badFields[globals.HostCatalogIdField] = "The field is incorrectly formatted."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -170,10 +170,11 @@ func TestGet_Plugin(t *testing.T) {
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
hs := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1))
hsPrev := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", plugin.PreviousHostSetPrefix)))
toMerge := &pbs.GetHostSetRequest{}
pHost := &pb.HostSet{
pHostSet := &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Id: hs.GetPublicId(),
CreatedTime: hs.CreateTime.GetTimestamp(),
@@ -197,9 +198,20 @@ func TestGet_Plugin(t *testing.T) {
err error
}{
{
name: "Get an Existing Host",
name: "Get an Existing HostSet",
req: &pbs.GetHostSetRequest{Id: hs.GetPublicId()},
res: &pbs.GetHostSetResponse{Item: pHost},
res: &pbs.GetHostSetResponse{Item: pHostSet},
},
{
name: "Get an Existing Previous-ID HostSet",
req: &pbs.GetHostSetRequest{Id: hsPrev.GetPublicId()},
res: func() *pbs.GetHostSetResponse {
resp := proto.Clone(pHostSet).(*pb.HostSet)
resp.Id = hsPrev.PublicId
resp.CreatedTime = hsPrev.CreateTime.GetTimestamp()
resp.UpdatedTime = hsPrev.UpdateTime.GetTimestamp()
return &pbs.GetHostSetResponse{Item: resp}
}(),
},
{
name: "Get a non existing Host Set",
@@ -614,7 +614,7 @@ func validateGetRequest(req *pbs.GetHostRequest) error {
badFields["id"] = "Improperly formatted identifier used."
}
return badFields
}, req, static.HostPrefix, plugin.HostPrefix)
}, req, static.HostPrefix, plugin.HostPrefix, plugin.PreviousHostPrefix)
}
func validateCreateRequest(req *pbs.CreateHostRequest) error {
@@ -705,7 +705,7 @@ func validateDeleteRequest(req *pbs.DeleteHostRequest) error {
func validateListRequest(req *pbs.ListHostsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix) {
badFields["host_catalog_id"] = "The field is incorrectly formatted."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -162,8 +162,9 @@ func TestGet_Plugin(t *testing.T) {
}
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
h := plugin.TestHost(t, conn, hc.GetPublicId(), "test")
hPrev := plugin.TestHost(t, conn, hc.GetPublicId(), "test-prev", plugin.WithPublicId(fmt.Sprintf("%s_1234567890", plugin.PreviousHostPrefix)))
hs := plugin.TestSet(t, conn, kms, sche, hc, plgm)
plugin.TestSetMembers(t, conn, hs.GetPublicId(), []*plugin.Host{h})
plugin.TestSetMembers(t, conn, hs.GetPublicId(), []*plugin.Host{h, hPrev})
pHost := &pb.Host{
HostCatalogId: hc.GetPublicId(),
@@ -193,6 +194,18 @@ func TestGet_Plugin(t *testing.T) {
req: &pbs.GetHostRequest{Id: h.GetPublicId()},
res: &pbs.GetHostResponse{Item: pHost},
},
{
name: "Get an Existing Previous-ID Host",
req: &pbs.GetHostRequest{Id: hPrev.GetPublicId()},
res: func() *pbs.GetHostResponse {
resp := proto.Clone(pHost).(*pb.Host)
resp.Id = hPrev.PublicId
resp.CreatedTime = hPrev.CreateTime.GetTimestamp()
resp.UpdatedTime = hPrev.UpdateTime.GetTimestamp()
resp.ExternalId = "test-prev"
return &pbs.GetHostResponse{Item: resp}
}(),
},
{
name: "non existing",
req: &pbs.GetHostRequest{Id: plugin.HostPrefix + "_DoesntExis"},
@@ -1664,8 +1664,7 @@ func validateAddSetsRequest(req *pbs.AddTargetHostSetsRequest) error {
badFields[globals.HostSetIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostSetIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix) &&
!strings.HasPrefix(id, fmt.Sprintf("%s_", plugin.HostSetPrefix)) {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
badFields[globals.HostSetIdsField] = fmt.Sprintf("Incorrectly formatted host set identifier %q.", id)
break
}
@@ -1685,8 +1684,7 @@ func validateSetSetsRequest(req *pbs.SetTargetHostSetsRequest) error {
badFields[globals.VersionField] = "Required field."
}
for _, id := range req.GetHostSetIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix) &&
!strings.HasPrefix(id, fmt.Sprintf("%s_", plugin.HostSetPrefix)) {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
badFields[globals.HostSetIdsField] = fmt.Sprintf("Incorrectly formatted host set identifier %q.", id)
break
}
@@ -1709,8 +1707,7 @@ func validateRemoveSetsRequest(req *pbs.RemoveTargetHostSetsRequest) error {
badFields[globals.HostSetIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostSetIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix) &&
!strings.HasPrefix(id, fmt.Sprintf("%s_", plugin.HostSetPrefix)) {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
badFields[globals.HostSetIdsField] = fmt.Sprintf("Incorrectly formatted host set identifier %q.", id)
break
}
@@ -1733,8 +1730,7 @@ func validateAddHostSourcesRequest(req *pbs.AddTargetHostSourcesRequest) error {
badFields[globals.HostSourceIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostSourceIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix) &&
!strings.HasPrefix(id, fmt.Sprintf("%s_", plugin.HostSetPrefix)) {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
badFields[globals.HostSourceIdsField] = fmt.Sprintf("Incorrectly formatted host source identifier %q.", id)
break
}
@@ -1754,8 +1750,7 @@ func validateSetHostSourcesRequest(req *pbs.SetTargetHostSourcesRequest) error {
badFields[globals.VersionField] = "Required field."
}
for _, id := range req.GetHostSourceIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix) &&
!strings.HasPrefix(id, fmt.Sprintf("%s_", plugin.HostSetPrefix)) {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
badFields[globals.HostSourceIdsField] = fmt.Sprintf("Incorrectly formatted host source identifier %q.", id)
break
}
@@ -1778,8 +1773,7 @@ func validateRemoveHostSourcesRequest(req *pbs.RemoveTargetHostSourcesRequest) e
badFields[globals.HostSourceIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostSourceIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix) &&
!strings.HasPrefix(id, fmt.Sprintf("%s_", plugin.HostSetPrefix)) {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
badFields[globals.HostSourceIdsField] = fmt.Sprintf("Incorrectly formatted host source identifier %q.", id)
break
}
@@ -1803,13 +1797,13 @@ func validateAddCredentialSourcesRequest(req *pbs.AddTargetCredentialSourcesRequ
badFields[globals.EgressCredentialSourceIdsField] = "Application or Egress Credential Source IDs must be provided."
}
for _, cl := range req.GetApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.CredentialPrefix) {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.UsernamePasswordCredentialPrefix, credstatic.PreviousUsernamePasswordCredentialPrefix) {
badFields[globals.ApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetEgressCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.CredentialPrefix) {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.UsernamePasswordCredentialPrefix, credstatic.PreviousUsernamePasswordCredentialPrefix) {
badFields[globals.EgressCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
@@ -1829,13 +1823,13 @@ func validateSetCredentialSourcesRequest(req *pbs.SetTargetCredentialSourcesRequ
badFields[globals.VersionField] = "Required field."
}
for _, cl := range req.GetApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.CredentialPrefix) {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.UsernamePasswordCredentialPrefix, credstatic.PreviousUsernamePasswordCredentialPrefix) {
badFields[globals.ApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetEgressCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.CredentialPrefix) {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.UsernamePasswordCredentialPrefix, credstatic.PreviousUsernamePasswordCredentialPrefix) {
badFields[globals.EgressCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
@@ -1859,13 +1853,13 @@ func validateRemoveCredentialSourcesRequest(req *pbs.RemoveTargetCredentialSourc
badFields[globals.EgressCredentialSourceIdsField] = "Application or Egress Credential Source IDs must be provided."
}
for _, cl := range req.GetApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.CredentialPrefix) {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.UsernamePasswordCredentialPrefix, credstatic.PreviousUsernamePasswordCredentialPrefix) {
badFields[globals.ApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetEgressCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.CredentialPrefix) {
if !handlers.ValidId(handlers.Id(cl), vault.CredentialLibraryPrefix, credstatic.UsernamePasswordCredentialPrefix, credstatic.PreviousUsernamePasswordCredentialPrefix) {
badFields[globals.EgressCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}