-
Notifications
You must be signed in to change notification settings - Fork 117
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
Add location library to elastic-package #303
Merged
fearful-symmetry
merged 18 commits into
elastic:master
from
fearful-symmetry:locations-refactor
Apr 6, 2021
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bd31ebb
add location library to elastic-package
fearful-symmetry a9d08f6
Merge branch 'master' into locations-refactor
mtojek 3193627
reove newline
fearful-symmetry 578725e
Merge branch 'locations-refactor' of github.com:fearful-symmetry/elas…
fearful-symmetry f12196b
Merge remote-tracking branch 'upstream/master' into locations-refactor
fearful-symmetry 5d90e76
migrate locations, fix formatting
fearful-symmetry babf379
remove old code from install
fearful-symmetry bea000a
make fmt
fearful-symmetry fd3fa4d
write config.yml in correct location
fearful-symmetry 6e21b0f
fix locations path
fearful-symmetry a969937
fix root paths
fearful-symmetry 12b31ff
remove duplicated functions
fearful-symmetry 4eff1a2
Merge remote-tracking branch 'upstream/master' into locations-refactor
fearful-symmetry 3da8346
Merge remote-tracking branch 'upstream/master' into locations-refactor
fearful-symmetry 4a71a58
Merge remote-tracking branch 'upstream/master' into locations-refactor
fearful-symmetry c89b776
fix bug in install check
fearful-symmetry 0b44bdb
Merge remote-tracking branch 'upstream/master' into locations-refactor
fearful-symmetry 4798ca1
fix case
fearful-symmetry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
// Package locations manages base file and directory locations from within the elastic-package config | ||
package locations | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
const ( | ||
elasticPackageDir = ".elastic-package" | ||
stackDir = "stack" | ||
packagesDir = "development" | ||
|
||
temporaryDir = "tmp" | ||
deployerDir = "deployer" | ||
|
||
kubernetesDeployerElasticAgentYmlFile = "elastic-agent.yml" | ||
terraformDeployerYmlFile = "terraform-deployer.yml" | ||
) | ||
|
||
var ( | ||
serviceLogsDir = filepath.Join(temporaryDir, "service_logs") | ||
kubernetesDeployerDir = filepath.Join(deployerDir, "kubernetes") | ||
terraformDeployerDir = filepath.Join(deployerDir, "terraform") | ||
) | ||
|
||
//LocationManager maintains an instance of a config path location | ||
type LocationManager struct { | ||
stackPath string | ||
} | ||
|
||
// NewLocationManager returns a new manager to track the Configuration dir | ||
func NewLocationManager() (*LocationManager, error) { | ||
cfg, err := configurationDir() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "error getting config dir") | ||
} | ||
|
||
return &LocationManager{stackPath: cfg}, nil | ||
|
||
} | ||
|
||
// RootDir returns the root elastic-package dir | ||
func (loc LocationManager) RootDir() string { | ||
return loc.stackPath | ||
} | ||
|
||
// TempDir returns the temp directory location | ||
func (loc LocationManager) TempDir() string { | ||
return filepath.Join(loc.stackPath, temporaryDir) | ||
} | ||
|
||
// DeployerDir returns the deployer directory location | ||
func (loc LocationManager) DeployerDir() string { | ||
return filepath.Join(loc.stackPath, deployerDir) | ||
} | ||
|
||
// StackDir returns the stack directory location | ||
func (loc LocationManager) StackDir() string { | ||
return filepath.Join(loc.stackPath, stackDir) | ||
} | ||
|
||
// PackagesDir returns the packages directory location | ||
func (loc LocationManager) PackagesDir() string { | ||
return filepath.Join(loc.stackPath, stackDir, packagesDir) | ||
} | ||
|
||
// KubernetesDeployerDir returns the Kubernetes Deployer directory location | ||
func (loc LocationManager) KubernetesDeployerDir() string { | ||
return filepath.Join(loc.stackPath, kubernetesDeployerDir) | ||
} | ||
|
||
// KubernetesDeployerAgentYml returns the Kubernetes Deployer Elastic Agent yml | ||
func (loc LocationManager) KubernetesDeployerAgentYml() string { | ||
return filepath.Join(loc.stackPath, kubernetesDeployerDir, kubernetesDeployerElasticAgentYmlFile) | ||
} | ||
|
||
// TerraformDeployerDir returns the Terraform Directory | ||
func (loc LocationManager) TerraformDeployerDir() string { | ||
return filepath.Join(loc.stackPath, terraformDeployerDir) | ||
} | ||
|
||
// TerraformDeployerYml returns the Terraform deployer yml file | ||
func (loc LocationManager) TerraformDeployerYml() string { | ||
return filepath.Join(loc.stackPath, terraformDeployerDir, terraformDeployerYmlFile) | ||
} | ||
|
||
// ServiceLogDir returns the log directory | ||
func (loc LocationManager) ServiceLogDir() string { | ||
return filepath.Join(loc.stackPath, serviceLogsDir) | ||
} | ||
|
||
// ConfigurationDir returns the configuration directory location | ||
func configurationDir() (string, error) { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return "", errors.Wrap(err, "reading home dir failed") | ||
} | ||
return filepath.Join(homeDir, elasticPackageDir), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.