packer/internal/hcp/env/env.go
hashicorp-copywrite[bot] 19055df3ec
[COMPLIANCE] License changes (#12568)
* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-10 15:53:29 -07:00

64 lines
1.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
// Package env provides HCP Packer environment variables.
package env
import (
"os"
"strings"
)
func HasProjectID() bool {
return hasEnvVar(HCPProjectID)
}
func HasOrganizationID() bool {
return hasEnvVar(HCPOrganizationID)
}
func HasClientID() bool {
return hasEnvVar(HCPClientID)
}
func HasClientSecret() bool {
return hasEnvVar(HCPClientSecret)
}
func HasPackerRegistryBucket() bool {
return hasEnvVar(HCPPackerBucket)
}
func hasEnvVar(varName string) bool {
val, ok := os.LookupEnv(varName)
if !ok {
return false
}
return val != ""
}
func HasHCPCredentials() bool {
checks := []func() bool{
HasClientID,
HasClientSecret,
}
for _, check := range checks {
if !check() {
return false
}
}
return true
}
func IsHCPDisabled() bool {
hcp, ok := os.LookupEnv(HCPPackerRegistry)
return ok && strings.ToLower(hcp) == "off" || hcp == "0"
}
// IsHCPExplicitelyEnabled returns true if the client enabled HCP_PACKER_REGISTRY explicitely, i.e. it is defined and not 0 or off
func IsHCPExplicitelyEnabled() bool {
_, ok := os.LookupEnv(HCPPackerRegistry)
return ok && !IsHCPDisabled()
}