Skip to content

Commit cb8e3ff

Browse files
author
Tomasz Osiński
authored
Fix OS profile to OS resource conversion (#3)
1 parent 04df7ef commit cb8e3ff

3 files changed

Lines changed: 477 additions & 8 deletions

File tree

os-resource/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.16.0
1+
0.16.1-dev

os-resource/internal/util/util.go

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,60 @@ const (
2323
var zlogUtil = logging.GetLogger(loggerName)
2424

2525
func ConvertOSProfileToOSResource(osProfile *fsclient.OSProfileManifest) (*osv1.OperatingSystemResource, error) {
26-
platformBundleData, err := json.Marshal(&osProfile.Spec.PlatformBundle)
27-
if err != nil {
28-
zlogUtil.Error().Err(err).Msg("")
29-
return nil, inv_errors.Errorf("Failed to convert OS platform bundle for profile %s", osProfile.Spec.ProfileName)
26+
platformBundle := ""
27+
28+
if len(osProfile.Spec.PlatformBundle) != 0 {
29+
pbData, err := json.Marshal(&osProfile.Spec.PlatformBundle)
30+
if err != nil {
31+
zlogUtil.Error().Err(err).Msg("")
32+
return nil, inv_errors.Errorf("Failed to convert OS platform bundle for profile %s", osProfile.Spec.ProfileName)
33+
}
34+
platformBundle = string(pbData)
35+
}
36+
37+
_osType, valid := osv1.OsType_value[osProfile.Spec.Type]
38+
if !valid {
39+
osTypeErr := inv_errors.Errorf("Invalid OS type: %s", osProfile.Spec.Type)
40+
zlogUtil.Error().Err(osTypeErr).Msg("")
41+
return nil, osTypeErr
42+
}
43+
44+
osType := osv1.OsType(_osType)
45+
46+
if osType == osv1.OsType_OS_TYPE_UNSPECIFIED {
47+
osTypeErr := inv_errors.Errorf("OS type cannot be %s", osType.String())
48+
zlogUtil.Error().Err(osTypeErr).Msg("")
49+
return nil, osTypeErr
50+
}
51+
52+
_osProvider, valid := osv1.OsProviderKind_value[osProfile.Spec.Provider]
53+
if !valid {
54+
osProviderErr := inv_errors.Errorf("Invalid OS provider: %s", osProfile.Spec.Provider)
55+
zlogUtil.Error().Err(osProviderErr).Msg("")
56+
return nil, osProviderErr
57+
}
58+
59+
osProvider := osv1.OsProviderKind(_osProvider)
60+
61+
if osProvider == osv1.OsProviderKind_OS_PROVIDER_KIND_UNSPECIFIED {
62+
osProviderErr := inv_errors.Errorf("OS provider cannot be %s", osProvider.String())
63+
zlogUtil.Error().Err(osProviderErr).Msg("")
64+
return nil, osProviderErr
65+
}
66+
67+
_securityFeature, valid := osv1.SecurityFeature_value[osProfile.Spec.SecurityFeature]
68+
if !valid {
69+
securityFeaturErr := inv_errors.Errorf("Invalid security feature: %s", osProfile.Spec.SecurityFeature)
70+
zlogUtil.Error().Err(securityFeaturErr).Msg("")
71+
return nil, securityFeaturErr
72+
}
73+
74+
securityFeature := osv1.SecurityFeature(_securityFeature)
75+
76+
if securityFeature == osv1.SecurityFeature_SECURITY_FEATURE_UNSPECIFIED {
77+
securityFeaturErr := inv_errors.Errorf("Security feature cannot be %s", securityFeature.String())
78+
zlogUtil.Error().Err(securityFeaturErr).Msg("")
79+
return nil, securityFeaturErr
3080
}
3181

3282
return &osv1.OperatingSystemResource{
@@ -37,9 +87,9 @@ func ConvertOSProfileToOSResource(osProfile *fsclient.OSProfileManifest) (*osv1.
3787
Architecture: osProfile.Spec.Architecture,
3888
ProfileName: osProfile.Spec.ProfileName,
3989
SecurityFeature: osv1.SecurityFeature(osv1.SecurityFeature_value[osProfile.Spec.SecurityFeature]),
40-
OsType: osv1.OsType(osv1.OsType_value[osProfile.Spec.Type]),
41-
OsProvider: osv1.OsProviderKind(osv1.OsProviderKind_value[osProfile.Spec.Provider]),
42-
PlatformBundle: string(platformBundleData),
90+
OsType: osType,
91+
OsProvider: osProvider,
92+
PlatformBundle: platformBundle,
4393
}, nil
4494
}
4595

0 commit comments

Comments
 (0)