fix(target): Correctly return egress credentials assocaited with target (#2167)
This commit is contained in:
1 parent
a2477420da
commit
c4285b29cc
2 files changed
+92
-59
No files matched your search
@@ -702,23 +702,6 @@ func printItemTable(result api.GenericResult) string {
|
||||
}
|
||||
|
||||
var credentialSourceMaps map[credential.Purpose][]map[string]interface{}
|
||||
if len(item.ApplicationCredentialSources) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
}
|
||||
var applicationCredentialSourceMaps []map[string]interface{}
|
||||
for _, lib := range item.ApplicationCredentialSources {
|
||||
m := map[string]interface{}{
|
||||
"ID": lib.Id,
|
||||
"Credential Store ID": lib.CredentialStoreId,
|
||||
}
|
||||
applicationCredentialSourceMaps = append(applicationCredentialSourceMaps, m)
|
||||
}
|
||||
credentialSourceMaps[credential.ApplicationPurpose] = applicationCredentialSourceMaps
|
||||
if l := len("Credential Store ID"); l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
if len(item.ApplicationCredentialLibraries) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
@@ -736,6 +719,40 @@ func printItemTable(result api.GenericResult) string {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
if len(item.ApplicationCredentialSources) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
}
|
||||
var applicationCredentialSourceMaps []map[string]interface{}
|
||||
for _, source := range item.ApplicationCredentialSources {
|
||||
m := map[string]interface{}{
|
||||
"ID": source.Id,
|
||||
"Credential Store ID": source.CredentialStoreId,
|
||||
}
|
||||
applicationCredentialSourceMaps = append(applicationCredentialSourceMaps, m)
|
||||
}
|
||||
credentialSourceMaps[credential.ApplicationPurpose] = applicationCredentialSourceMaps
|
||||
if l := len("Credential Store ID"); l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
if len(item.EgressCredentialSources) > 0 {
|
||||
if credentialSourceMaps == nil {
|
||||
credentialSourceMaps = make(map[credential.Purpose][]map[string]interface{})
|
||||
}
|
||||
var egressCredentialSourceMaps []map[string]interface{}
|
||||
for _, source := range item.EgressCredentialSources {
|
||||
m := map[string]interface{}{
|
||||
"ID": source.Id,
|
||||
"Credential Store ID": source.CredentialStoreId,
|
||||
}
|
||||
egressCredentialSourceMaps = append(egressCredentialSourceMaps, m)
|
||||
}
|
||||
credentialSourceMaps[credential.EgressPurpose] = egressCredentialSourceMaps
|
||||
if l := len("Credential Store ID"); l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
|
||||
ret := []string{
|
||||
"",
|
||||
@@ -775,17 +792,22 @@ func printItemTable(result api.GenericResult) string {
|
||||
}
|
||||
}
|
||||
|
||||
if len(credentialSourceMaps) > 0 {
|
||||
if appMap := credentialSourceMaps[credential.ApplicationPurpose]; len(appMap) > 0 {
|
||||
for purpose, sources := range credentialSourceMaps {
|
||||
switch purpose {
|
||||
case credential.ApplicationPurpose:
|
||||
ret = append(ret,
|
||||
" Application Credential Sources:",
|
||||
)
|
||||
for _, m := range appMap {
|
||||
ret = append(ret,
|
||||
base.WrapMap(4, maxLength, m),
|
||||
"",
|
||||
)
|
||||
}
|
||||
case credential.EgressPurpose:
|
||||
ret = append(ret,
|
||||
" Egress Credential Sources:",
|
||||
)
|
||||
}
|
||||
for _, m := range sources {
|
||||
ret = append(ret,
|
||||
base.WrapMap(4, maxLength, m),
|
||||
"",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -951,8 +973,8 @@ func exampleOutput() string {
|
||||
HostCatalogId: "hcst_1234567890",
|
||||
},
|
||||
},
|
||||
ApplicationCredentialLibraryIds: []string{"clvlt_1234567890", "clvlt_0987654321"},
|
||||
ApplicationCredentialLibraries: []*targets.CredentialLibrary{
|
||||
ApplicationCredentialSourceIds: []string{"clvlt_1234567890", "clvlt_0987654321"},
|
||||
ApplicationCredentialSources: []*targets.CredentialSource{
|
||||
{
|
||||
Id: "clvlt_1234567890",
|
||||
CredentialStoreId: "csvlt_1234567890",
|
||||
|
||||
@@ -1631,45 +1631,56 @@ func toProto(ctx context.Context, in target.Target, hostSources []target.HostSou
|
||||
})
|
||||
}
|
||||
}
|
||||
if outputFields.Has(globals.ApplicationCredentialLibraryIdsField) {
|
||||
for _, cs := range credSources {
|
||||
out.ApplicationCredentialLibraryIds = append(out.ApplicationCredentialLibraryIds, cs.Id())
|
||||
|
||||
var appCredSources, egressCredSources []*pb.CredentialSource
|
||||
var appCredSourceIds, egressCredSourceIds []string
|
||||
var appCredLibraries []*pb.CredentialLibrary
|
||||
|
||||
for _, cs := range credSources {
|
||||
switch cs.CredentialPurpose() {
|
||||
case credential.ApplicationPurpose:
|
||||
appCredSourceIds = append(appCredSourceIds, cs.Id())
|
||||
appCredSources = append(appCredSources, &pb.CredentialSource{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
|
||||
// ApplicationCredentialLibrariesField is deprecated and should only be populated
|
||||
// for application purpose
|
||||
appCredLibraries = append(appCredLibraries, &pb.CredentialLibrary{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
|
||||
case credential.EgressPurpose:
|
||||
egressCredSources = append(egressCredSources, &pb.CredentialSource{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
egressCredSourceIds = append(egressCredSourceIds, cs.Id())
|
||||
|
||||
default:
|
||||
return nil, errors.New(ctx, errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
}
|
||||
}
|
||||
|
||||
if outputFields.Has(globals.ApplicationCredentialLibraryIdsField) {
|
||||
out.ApplicationCredentialLibraryIds = appCredSourceIds
|
||||
}
|
||||
if outputFields.Has(globals.ApplicationCredentialSourceIdsField) {
|
||||
for _, cs := range credSources {
|
||||
out.ApplicationCredentialSourceIds = append(out.ApplicationCredentialSourceIds, cs.Id())
|
||||
}
|
||||
out.ApplicationCredentialSourceIds = appCredSourceIds
|
||||
}
|
||||
if outputFields.Has(globals.ApplicationCredentialLibrariesField) {
|
||||
for _, cs := range credSources {
|
||||
switch credential.Purpose(cs.CredentialPurpose()) {
|
||||
case credential.ApplicationPurpose:
|
||||
out.ApplicationCredentialLibraries = append(out.ApplicationCredentialLibraries, &pb.CredentialLibrary{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
case credential.IngressPurpose, credential.EgressPurpose:
|
||||
// TODO: When we support other purposes add them to different fields here.
|
||||
default:
|
||||
return nil, errors.New(ctx, errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
}
|
||||
}
|
||||
out.ApplicationCredentialLibraries = appCredLibraries
|
||||
}
|
||||
if outputFields.Has(globals.ApplicationCredentialSourcesField) {
|
||||
for _, cs := range credSources {
|
||||
switch credential.Purpose(cs.CredentialPurpose()) {
|
||||
case credential.ApplicationPurpose:
|
||||
out.ApplicationCredentialSources = append(out.ApplicationCredentialSources, &pb.CredentialSource{
|
||||
Id: cs.Id(),
|
||||
CredentialStoreId: cs.CredentialStoreId(),
|
||||
})
|
||||
case credential.IngressPurpose, credential.EgressPurpose:
|
||||
// TODO: When we support other purposes add them to different fields here.
|
||||
default:
|
||||
return nil, errors.New(ctx, errors.Internal, op, fmt.Sprintf("unrecognized purpose %q for credential source on target", cs.CredentialPurpose()))
|
||||
}
|
||||
}
|
||||
out.ApplicationCredentialSources = appCredSources
|
||||
}
|
||||
if outputFields.Has(globals.EgressCredentialSourceIdsField) {
|
||||
out.EgressCredentialSourceIds = egressCredSourceIds
|
||||
}
|
||||
if outputFields.Has(globals.EgressCredentialSourcesField) {
|
||||
out.EgressCredentialSources = egressCredSources
|
||||
}
|
||||
if outputFields.Has(globals.AttributesField) {
|
||||
if err := subtypeRegistry.setAttributes(in.GetType(), in, &out); err != nil {
|
||||
|
||||
Reference in new issue
Block a user