Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to make License status CLI executable by non-root user #8610

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions components/automate-cli/cmd/chef-automate/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ var licenseCmd = &cobra.Command{
}

var licenseStatusCmd = &cobra.Command{
Use: "status",
Short: "Retrieve Chef Automate license status",
RunE: runLicenseStatusCmd,
PersistentPreRunE: preLicenseCmd,
Use: "status",
Short: "Retrieve Chef Automate license status",
RunE: runLicenseStatusCmd,
// PersistentPreRunE: preLicenseCmd,
Annotations: map[string]string{
docs.Tag: docs.BastionHost,
NoRequireRootAnnotation: NoRequireRootAnnotation,
docs.Tag: docs.BastionHost,
},
}

Expand Down Expand Up @@ -144,6 +145,14 @@ Deployment Date: %s
License Type: %s
Grace Period: %t
`
var licenseInfoFmtNonRoot = `

Licensed to: %s
License ID: %s
Expiration Date: %s
License Type: %s
Grace Period: %t
`

var startTimeFormat = "start time of the report in yyyy-mm-dd format"
var endTimeFormat = "end time of the report in yyyy-mm-dd format"
Expand Down Expand Up @@ -187,6 +196,16 @@ func runLicenseStatusCmd(cmd *cobra.Command, args []string) error {
if response.Set {
status.GlobalResult = response

//if os.Geteuid() != 0 {
// // License information for a current license for Non-root user
// writer.Printf(licenseInfoFmtNonRoot,
// response.CustomerName,
// response.LicenseId,
// time.Unix(response.ExpirationDate.GetSeconds(), 0).UTC().Format(time.RFC3339),
// response.LicenseType,
// response.GracePeriod,
// )
//} else {
// License information for a current license
writer.Printf(licenseInfoFmt,
response.CustomerName,
Expand All @@ -196,6 +215,7 @@ func runLicenseStatusCmd(cmd *cobra.Command, args []string) error {
response.LicenseType,
response.GracePeriod,
)
//}

// Add notice if license is expired
if !response.GracePeriod && time.Now().Unix() > response.ExpirationDate.GetSeconds() {
Expand Down
Loading