@@ -11,6 +11,7 @@ import (
1111 "os"
1212 "runtime"
1313
14+ "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1415 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
1516 "github.com/sirupsen/logrus"
1617 corev1 "k8s.io/api/core/v1"
@@ -20,15 +21,17 @@ import (
2021 "sigs.k8s.io/controller-runtime/pkg/client/config"
2122 "sigs.k8s.io/controller-runtime/pkg/log"
2223 "sigs.k8s.io/controller-runtime/pkg/log/zap"
24+ "sigs.k8s.io/yaml"
2325
2426 "github.com/replicatedhq/helmvm/pkg/preflights"
2527)
2628
2729// ParsedSection holds the parsed section from the binary. We only care about the
28- // application object and whatever HostPreflight we can find.
30+ // application object, whatever HostPreflight we can find, and the app License .
2931type ParsedSection struct {
3032 Application []byte
3133 HostPreflights [][]byte
34+ License []byte
3235}
3336
3437// AdminConsoleCustomization is a struct that contains the actions to create and update
@@ -84,10 +87,12 @@ func (a *AdminConsoleCustomization) processSection(section *elf.Section) (*Parse
8487 return nil , fmt .Errorf ("unable to copy file out of tar: %w" , err )
8588 }
8689 if bytes .Contains (content .Bytes (), []byte ("apiVersion: kots.io/v1beta1" )) {
87- if ! bytes .Contains (content .Bytes (), []byte ("kind: Application" )) {
88- continue
90+ if bytes .Contains (content .Bytes (), []byte ("kind: Application" )) {
91+ result .Application = content .Bytes ()
92+ }
93+ if bytes .Contains (content .Bytes (), []byte ("kind: License" )) {
94+ result .License = content .Bytes ()
8995 }
90- result .Application = content .Bytes ()
9196 continue
9297 }
9398 if bytes .Contains (content .Bytes (), []byte ("apiVersion: troubleshoot.sh/v1beta2" )) {
@@ -188,3 +193,22 @@ func (a *AdminConsoleCustomization) hostPreflights() (*v1beta2.HostPreflightSpec
188193 }
189194 return all , nil
190195}
196+
197+ // license reads the kots license from the embedded Kots Application Release. If no license is found,
198+ // returns nil and no error.
199+ func (a * AdminConsoleCustomization ) license () (* v1beta1.License , error ) {
200+ if runtime .GOOS != "linux" {
201+ return nil , nil
202+ }
203+ section , err := a .extractCustomization ()
204+ if err != nil {
205+ return nil , err
206+ } else if section == nil {
207+ return nil , nil
208+ }
209+ var license v1beta1.License
210+ if err := yaml .Unmarshal (section .License , & license ); err != nil {
211+ return nil , fmt .Errorf ("failed to unmarshal license: %w" , err )
212+ }
213+ return & license , nil
214+ }
0 commit comments