Skip to content

Commit

Permalink
environment names are constants (part two)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Jan 4, 2025
1 parent 5ba9180 commit a9afcfa
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 79 deletions.
4 changes: 2 additions & 2 deletions ais/backend/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ var _ core.Backend = (*s3bp)(nil)
// environment variables => static defaults that can still be overridden via bck.Props.Extra.AWS
// in addition to these two (below), default bucket region = env.AwsDefaultRegion()
func NewAWS(t core.TargetPut, tstats stats.Tracker, startingUp bool) (core.Backend, error) {
s3Endpoint = os.Getenv(env.AWS.Endpoint)
awsProfile = os.Getenv(env.AWS.Profile)
s3Endpoint = os.Getenv(env.AWSEndpoint)
awsProfile = os.Getenv(env.AWSProfile)
bp := &s3bp{
t: t,
mm: t.PageMM(),
Expand Down
26 changes: 13 additions & 13 deletions ais/backend/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,39 @@ func NewOCI(t core.TargetPut, tstats stats.Tracker, startingUp bool) (core.Backe
base: base{provider: apc.OCI},
}
bp.configurationProvider = ocicmn.NewRawConfigurationProvider(
os.Getenv(env.OCI.TenancyOCID),
os.Getenv(env.OCI.UserOCID),
os.Getenv(env.OCI.Region),
os.Getenv(env.OCI.Fingerprint),
os.Getenv(env.OCI.PrivateKey),
os.Getenv(env.OCITenancyOCID),
os.Getenv(env.OCIUserOCID),
os.Getenv(env.OCIRegion),
os.Getenv(env.OCIFingerprint),
os.Getenv(env.OCIPrivateKey),
nil,
)
bp.compartmentOCID = os.Getenv(env.OCI.CompartmentOCID)
bp.compartmentOCID = os.Getenv(env.OCICompartmentOCID)

if err := bp.set(env.OCI.MaxPageSize, maxPageSizeMin, maxPageSizeMax, maxPageSizeDefault, &bp.maxPageSize); err != nil {
if err := bp.set(env.OCIMaxPageSize, maxPageSizeMin, maxPageSizeMax, maxPageSizeDefault, &bp.maxPageSize); err != nil {
return nil, err
}
if err := bp.set(env.OCI.MaxDownloadSegmentSize, mpdSegmentMaxSizeMin, mpdSegmentMaxSizeMax,
if err := bp.set(env.OCIMaxDownloadSegmentSize, mpdSegmentMaxSizeMin, mpdSegmentMaxSizeMax,
mpdSegmentMaxSizeDefault, &bp.mpdSegmentMaxSize); err != nil {
return nil, err
}
if err := bp.set(env.OCI.MultiPartDownloadThreshold, mpdThresholdMin, mpdThresholdMax,
if err := bp.set(env.OCIMultiPartDownloadThreshold, mpdThresholdMin, mpdThresholdMax,
mpdThresholdDefault, &bp.mpdThreshold); err != nil {
return nil, err
}
if err := bp.set(env.OCI.MultiPartDownloadMaxThreads, mpdMaxThreadsMin, mpdMaxThreadsMax,
if err := bp.set(env.OCIMultiPartDownloadMaxThreads, mpdMaxThreadsMin, mpdMaxThreadsMax,
mpdMaxThreadsDefault, &bp.mpdMaxThreads); err != nil {
return nil, err
}
if err := bp.set(env.OCI.MaxUploadSegmentSize, mpuSegmentMaxSizeMin, mpuSegmentMaxSizeMax,
if err := bp.set(env.OCIMaxUploadSegmentSize, mpuSegmentMaxSizeMin, mpuSegmentMaxSizeMax,
mpuSegmentMaxSizeDefault, &bp.mpuSegmentMaxSize); err != nil {
return nil, err
}
if err := bp.set(env.OCI.MultiPartUploadThreshold, mpuThresholdMin, mpuThresholdMax,
if err := bp.set(env.OCIMultiPartUploadThreshold, mpuThresholdMin, mpuThresholdMax,
mpuThresholdDefault, &bp.mpuThreshold); err != nil {
return nil, err
}
if err := bp.set(env.OCI.MultiPartUploadMaxThreads, mpuMaxThreadsMin, mpuMaxThreadsMax,
if err := bp.set(env.OCIMultiPartUploadMaxThreads, mpuMaxThreadsMin, mpuMaxThreadsMax,
mpuMaxThreadsDefault, &bp.mpuMaxThreads); err != nil {
return nil, err
}
Expand Down
35 changes: 14 additions & 21 deletions api/env/aws.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
// Package env contains environment variables
/*
* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2024-2025, NVIDIA CORPORATION. All rights reserved.
*/
package env

import "os"

func AwsDefaultRegion() (region string) {
if region = os.Getenv(AWS.Region); region == "" {
// from https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html:
// "Buckets in region `us-east-1` have a LocationConstraint of null."
region = "us-east-1"
}
return region
}

// use S3_ENDPOINT to globally override the default 'https://s3.amazonaws.com' endpoint
// NOTE: the same can be done on a per-bucket basis, via bucket prop `Extra.AWS.Endpoint`
// (bucket override will always take precedence)

// ditto non-default profile via "AWS_PROFILE" (the default one is called [default])

var (
AWS = struct {
Endpoint string
Region string
Profile string
Inventory string
}{
Endpoint: "S3_ENDPOINT",
Region: "AWS_REGION",
Profile: "AWS_PROFILE",
}
const (
AWSEndpoint = "S3_ENDPOINT"
AWSRegion = "AWS_REGION"
AWSProfile = "AWS_PROFILE"
)

func AwsDefaultRegion() (region string) {
if region = os.Getenv(AWSRegion); region == "" {
// from https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetBucketLocation.html:
// "Buckets in region `us-east-1` have a LocationConstraint of null."
region = "us-east-1"
}
return region
}
46 changes: 15 additions & 31 deletions api/env/oci.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,25 @@
// Package env contains environment variables
/*
* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2024-2025, NVIDIA CORPORATION. All rights reserved.
*/
package env

// To populate OCI_PRIVATE_KEY with the contents of a PrivateKey .PEM file:
//
// export OCI_PRIVATE_KEY=$(cat ~/.oci/prikey.pem)

var (
OCI = struct {
TenancyOCID string
CompartmentOCID string
UserOCID string
Region string
Fingerprint string
PrivateKey string
MaxPageSize string
MaxDownloadSegmentSize string
MultiPartDownloadThreshold string
MultiPartDownloadMaxThreads string
MaxUploadSegmentSize string
MultiPartUploadThreshold string
MultiPartUploadMaxThreads string
}{
TenancyOCID: "OCI_TENANCY_OCID",
CompartmentOCID: "OCI_COMPARTMENT_OCID",
UserOCID: "OCI_USER_OCID",
Region: "OCI_REGION",
Fingerprint: "OCI_FINGERPRINT",
PrivateKey: "OCI_PRIVATE_KEY",
MaxPageSize: "OCI_MAX_PAGE_SIZE",
MaxDownloadSegmentSize: "OCI_MAX_DOWNLOAD_SEGMENT_SIZE",
MultiPartDownloadThreshold: "OCI_MULTI_PART_DOWNLOAD_THRESHOLD",
MultiPartDownloadMaxThreads: "OCI_MULTI_PART_DOWNLOAD_MAX_THREADS",
MaxUploadSegmentSize: "OCI_MAX_UPLOAD_SEGMENT_SIZE",
MultiPartUploadThreshold: "OCI_MULTI_PART_UPLOAD_THRESHOLD",
MultiPartUploadMaxThreads: "OCI_MULTI_PART_UPLOAD_MAX_THREADS",
}
const (
OCITenancyOCID = "OCI_TENANCY_OCID"
OCICompartmentOCID = "OCI_COMPARTMENT_OCID"
OCIUserOCID = "OCI_USER_OCID"
OCIRegion = "OCI_REGION"
OCIFingerprint = "OCI_FINGERPRINT"
OCIPrivateKey = "OCI_PRIVATE_KEY"
OCIMaxPageSize = "OCI_MAX_PAGE_SIZE"
OCIMaxDownloadSegmentSize = "OCI_MAX_DOWNLOAD_SEGMENT_SIZE"
OCIMultiPartDownloadThreshold = "OCI_MULTI_PART_DOWNLOAD_THRESHOLD"
OCIMultiPartDownloadMaxThreads = "OCI_MULTI_PART_DOWNLOAD_MAX_THREADS"
OCIMaxUploadSegmentSize = "OCI_MAX_UPLOAD_SEGMENT_SIZE"
OCIMultiPartUploadThreshold = "OCI_MULTI_PART_UPLOAD_THRESHOLD"
OCIMultiPartUploadMaxThreads = "OCI_MULTI_PART_UPLOAD_MAX_THREADS"
)
2 changes: 1 addition & 1 deletion bench/tools/aisloader/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func listObjectNames(p *params) ([]string, error) {
func initS3Svc() error {
// '--s3profile' takes precedence
if s3Profile == "" {
if profile := os.Getenv(env.AWS.Profile); profile != "" {
if profile := os.Getenv(env.AWSProfile); profile != "" {
s3Profile = profile
}
}
Expand Down
2 changes: 1 addition & 1 deletion bench/tools/aisloader/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func addCmdLine(f *flag.FlagSet, p *params) {
func _init(p *params) (err error) {
// '--s3endpoint' takes precedence
if s3Endpoint == "" {
if ep := os.Getenv(env.AWS.Endpoint); ep != "" {
if ep := os.Getenv(env.AWSEndpoint); ep != "" {
s3Endpoint = ep
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NVIDIA/aistore/cmd/cli
go 1.23.2

require (
github.com/NVIDIA/aistore v1.3.26-0.20250104164615-22715625e065
github.com/NVIDIA/aistore v1.3.26-0.20250104165201-5ba918095b38
github.com/fatih/color v1.18.0
github.com/json-iterator/go v1.1.12
github.com/onsi/ginkgo/v2 v2.21.0
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/NVIDIA/aistore v1.3.26-0.20250104164615-22715625e065 h1:rdNRrRxOpjQYkVCHxY0cP8HKT+PTxujZcK1jrbCbwTM=
github.com/NVIDIA/aistore v1.3.26-0.20250104164615-22715625e065/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/NVIDIA/aistore v1.3.26-0.20250104165201-5ba918095b38 h1:lQioqvz7kmF+VtBTvOwjKv2AY2go4tRmUqWXaGeAuBc=
github.com/NVIDIA/aistore v1.3.26-0.20250104165201-5ba918095b38/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
Expand Down
2 changes: 1 addition & 1 deletion cmd/ishard/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NVIDIA/aistore/cmd/ishard
go 1.23.2

require (
github.com/NVIDIA/aistore v1.3.26-0.20250104000959-257daaf15171
github.com/NVIDIA/aistore v1.3.26-0.20250104165201-5ba918095b38
github.com/json-iterator/go v1.1.12
github.com/vbauerster/mpb/v4 v4.12.2
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ishard/go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
code.cloudfoundry.org/bytefmt v0.0.0-20190710193110-1eb035ffe2b6/go.mod h1:wN/zk7mhREp/oviagqUXY3EwuHhWyOvAdsn5Y4CzOrc=
github.com/NVIDIA/aistore v1.3.26-0.20250104000959-257daaf15171 h1:PyKm6G564xu62j1Wo9aTwQaKQa2UxZbrlNfKW3zQfYI=
github.com/NVIDIA/aistore v1.3.26-0.20250104000959-257daaf15171/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/NVIDIA/aistore v1.3.26-0.20250104165201-5ba918095b38 h1:lQioqvz7kmF+VtBTvOwjKv2AY2go4tRmUqWXaGeAuBc=
github.com/NVIDIA/aistore v1.3.26-0.20250104165201-5ba918095b38/go.mod h1:mjhY9OGIZULaC79+iRfzEUvUZw7aIWklJ8um321QVpw=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
Expand Down
9 changes: 5 additions & 4 deletions cmd/ishard/ishard/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Package config provides types and functions to configure ishard executable.
/*
* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved.
* Copyright (c) 2024-2025, NVIDIA CORPORATION. All rights reserved.
*/
package config

Expand Down Expand Up @@ -125,11 +125,12 @@ func (alg *SortFlag) Set(value string) error {
case "alpha", "alphanumeric":
alg.Kind = "alphanumeric"
if len(parts) > 1 {
if parts[1] == "inc" {
switch {
case parts[1] == "inc":
alg.Decreasing = false
} else if parts[1] == "dec" {
case parts[1] == "dec":
alg.Decreasing = true
} else {
default:
return errors.New("invalid alphanumeric sort option, expected 'inc' or 'dec'")
}
}
Expand Down

0 comments on commit a9afcfa

Please sign in to comment.