@@ -23,10 +23,60 @@ const (
2323var zlogUtil = logging .GetLogger (loggerName )
2424
2525func 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