Skip to content

Commit

Permalink
fixup! pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Nov 28, 2023
1 parent 84991fe commit 810d7e3
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ func (d *AttestationDataSource) Read(ctx context.Context, req datasource.ReadReq
resp.Diagnostics.AddError("Fetching SNP Version numbers", err.Error())
return
}
tfSnpVersions := convertSNPAttestationTfStateCompatible(resp, attestationVariant, snpVersions)
if resp.Diagnostics.HasError() {
return
tfSnpAttestation, err := convertSNPAttestationTfStateCompatible(attestationVariant, snpVersions)
if err != nil {
resp.Diagnostics.AddError("Converting SNP attestation", err.Error())
}
diags := resp.State.SetAttribute(ctx, path.Root("attestation"), tfSnpVersions)
diags := resp.State.SetAttribute(ctx, path.Root("attestation"), tfSnpAttestation)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -229,9 +229,9 @@ func (d *AttestationDataSource) Read(ctx context.Context, req datasource.ReadReq
tflog.Trace(ctx, "read constellation attestation data source")
}

func convertSNPAttestationTfStateCompatible(resp *datasource.ReadResponse, attestationVariant variant.Variant,
func convertSNPAttestationTfStateCompatible(attestationVariant variant.Variant,
snpVersions attestationconfigapi.SEVSNPVersionAPI,
) sevSnpAttestation {
) (tfSnpAttestation sevSnpAttestation, err error) {
var cert config.Certificate
switch attestationVariant.(type) {
case variant.AWSSEVSNP:
Expand All @@ -241,9 +241,9 @@ func convertSNPAttestationTfStateCompatible(resp *datasource.ReadResponse, attes
}
certBytes, err := cert.MarshalJSON()
if err != nil {
resp.Diagnostics.AddError("Marshalling AMD Root Key", err.Error())
return tfSnpAttestation, err
}
tfSnpVersions := sevSnpAttestation{
tfSnpAttestation = sevSnpAttestation{
BootloaderVersion: snpVersions.Bootloader,
TEEVersion: snpVersions.TEE,
SNPVersion: snpVersions.SNP,
Expand All @@ -254,19 +254,19 @@ func convertSNPAttestationTfStateCompatible(resp *datasource.ReadResponse, attes
firmwareCfg := config.DefaultForAzureSEVSNP().FirmwareSignerConfig
keyDigestAny, err := firmwareCfg.AcceptedKeyDigests.MarshalYAML()
if err != nil {
resp.Diagnostics.AddError("Marshalling Accepted Key Digests", err.Error())
return tfSnpAttestation, err
}
keyDigest, ok := keyDigestAny.([]string)
if !ok {
resp.Diagnostics.AddError("Reading Accepted Key Digests", "Could not convert to []string")
return tfSnpAttestation, errors.New("reading Accepted Key Digests: could not convert to []string")
}
tfSnpVersions.AzureSNPFirmwareSignerConfig = azureSnpFirmwareSignerConfig{
tfSnpAttestation.AzureSNPFirmwareSignerConfig = azureSnpFirmwareSignerConfig{
AcceptedKeyDigests: keyDigest,
EnforcementPolicy: firmwareCfg.EnforcementPolicy.String(),
MAAURL: firmwareCfg.MAAURL,
}
}
return tfSnpVersions
return tfSnpAttestation, nil
}

func convertMeasurementsTfStateCompatible(m measurements.M) map[string]measurement {
Expand Down

0 comments on commit 810d7e3

Please sign in to comment.