Skip to content

Commit

Permalink
Move feature flag to main package to be reused
Browse files Browse the repository at this point in the history
  • Loading branch information
vapopov committed Oct 17, 2024
1 parent e635b85 commit b019206
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
38 changes: 38 additions & 0 deletions lib/autoupdate/feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Teleport
* Copyright (C) 2024 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package autoupdate

const (
// FlagEnt represents enterprise version.
FlagEnt = 1 << iota
// FlagFips represents enterprise version with fips feature enabled.
FlagFips
)

var (
// featureFlag stores information about enabled feature to define which package needs
// to be downloaded for auto update (e.g. Enterprise, or package with FIPS).
featureFlag int
)

// FeatureFlag returns information about enabled feature to identify which package needs
// to be downloaded for auto update (e.g. Enterprise, or package with FIPS).
func FeatureFlag() int {
return featureFlag
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package tools
package autoupdate

func init() {
featureFlag |= FlagEnt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package tools
package autoupdate

func init() {
featureFlag |= FlagFips
Expand Down
17 changes: 3 additions & 14 deletions lib/autoupdate/tools/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,10 @@ import (
"github.com/gravitational/trace"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/autoupdate"
"github.com/gravitational/teleport/lib/utils"
)

const (
// FlagEnt represents enterprise version.
FlagEnt = 1 << iota
// FlagFips represents enterprise version with fips feature enabled.
FlagFips
)

var (
// featureFlag stores information about enable
featureFlag int
)

// Dir returns the path to client tools in $TELEPORT_HOME/bin.
func Dir() (string, error) {
home := os.Getenv(types.HomeEnvVar)
Expand Down Expand Up @@ -142,11 +131,11 @@ func teleportPackageURLs(baseURL, toolsVersion string) ([]packageURL, error) {
case "linux":
var b strings.Builder
b.WriteString(baseURL + "/teleport-")
if featureFlag&(FlagEnt|FlagFips) != 0 {
if autoupdate.FeatureFlag()&(autoupdate.FlagEnt|autoupdate.FlagFips) != 0 {
b.WriteString("ent-")
}
b.WriteString("v" + toolsVersion + "-" + runtime.GOOS + "-" + runtime.GOARCH + "-")
if featureFlag&FlagFips != 0 {
if autoupdate.FeatureFlag()&autoupdate.FlagFips != 0 {
b.WriteString("fips-")
}
b.WriteString("bin.tar.gz")
Expand Down

0 comments on commit b019206

Please sign in to comment.