Skip to content

Commit 5fefa3c

Browse files
committed
Move service tokens and geoip to profile
1 parent 8a8f8da commit 5fefa3c

File tree

10 files changed

+45
-15
lines changed

10 files changed

+45
-15
lines changed

cmd/profiles.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ User profiles are not overwritten on upgrade of elastic-stack, and can be freely
105105
if err != nil {
106106
return errors.Wrap(err, "error listing all profiles")
107107
}
108+
if len(profileList) == 0 {
109+
fmt.Println("There are no profiles yet.")
110+
return nil
111+
}
108112

109113
format, err := cmd.Flags().GetString(cobraext.ProfileFormatFlagName)
110114
if err != nil {

cmd/stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func setupStackCommand() *cobraext.Command {
8989
if err != nil {
9090
return errors.Wrap(err, "error listing known profiles")
9191
}
92-
return fmt.Errorf("%s is not a valid profile, known profiles are: %s", profileName, pList)
92+
return fmt.Errorf("%s is not a valid profile, known profiles are: %s", profileName, strings.Join(pList, ", "))
9393
}
9494
if err != nil {
9595
return errors.Wrap(err, "error loading profile")

internal/install/install.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"gopkg.in/yaml.v3"
1414

1515
"github.com/elastic/elastic-package/internal/configuration/locations"
16+
"github.com/elastic/elastic-package/internal/profile"
1617
)
1718

1819
const versionFilename = "version"
@@ -57,6 +58,17 @@ func EnsureInstalled() error {
5758
return errors.Wrap(err, "writing version file failed")
5859
}
5960

61+
// Create initial profile:
62+
options := profile.Options{
63+
PackagePath: elasticPackagePath.ProfileDir(),
64+
Name: profile.DefaultProfile,
65+
OverwriteExisting: false,
66+
}
67+
err = profile.CreateProfile(options)
68+
if err != nil {
69+
return errors.Wrap(err, "creation of initial profile failed")
70+
}
71+
6072
if err := createServiceLogsDir(elasticPackagePath); err != nil {
6173
return errors.Wrap(err, "creating service logs directory failed")
6274
}

internal/install/static.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,5 @@ var terraformDeployerYml string
1515
//go:embed _static/terraform_deployer_run.sh
1616
var terraformDeployerRun string
1717

18-
//go:embed _static/GeoLite2-ASN.mmdb
19-
var geoIpAsnMmdb string
20-
21-
//go:embed _static/GeoLite2-City.mmdb
22-
var geoIpCityMmdb string
23-
24-
//go:embed _static/GeoLite2-Country.mmdb
25-
var geoIpCountryMmdb string
26-
27-
//go:embed _static/service_tokens
28-
var serviceTokens string
29-
3018
//go:embed _static/docker-custom-agent-base.yml
3119
var dockerCustomAgentBaseYml string

internal/profile/_static/docker-compose-stack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ services:
1212
volumes:
1313
- "./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
1414
- "../certs/elasticsearch:/usr/share/elasticsearch/config/certs"
15-
- "../../../stack/ingest-geoip:/usr/share/elasticsearch/config/ingest-geoip"
16-
- "../../../stack/service_tokens:/usr/share/elasticsearch/config/service_tokens"
15+
- "./ingest-geoip:/usr/share/elasticsearch/config/ingest-geoip"
16+
- "./service_tokens:/usr/share/elasticsearch/config/service_tokens"
1717
ports:
1818
- "127.0.0.1:9200:9200"
1919

File renamed without changes.

internal/profile/profile.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ var (
7878
Path: ElasticsearchConfigFile,
7979
Content: staticSource.Template("_static/elasticsearch.yml.tmpl"),
8080
},
81+
&resource.File{
82+
Provider: "stack-file",
83+
Path: "service_tokens",
84+
Content: staticSource.File("_static/service_tokens"),
85+
},
86+
&resource.File{
87+
Provider: "stack-file",
88+
Path: "ingest-geoip/GeoLite2-ASN.mmdb",
89+
CreateParent: true,
90+
Content: staticSource.File("_static/GeoLite2-ASN.mmdb"),
91+
},
92+
&resource.File{
93+
Provider: "stack-file",
94+
Path: "ingest-geoip/GeoLite2-City.mmdb",
95+
CreateParent: true,
96+
Content: staticSource.File("_static/GeoLite2-City.mmdb"),
97+
},
98+
&resource.File{
99+
Provider: "stack-file",
100+
Path: "ingest-geoip/GeoLite2-Country.mmdb",
101+
CreateParent: true,
102+
Content: staticSource.File("_static/GeoLite2-Country.mmdb"),
103+
},
81104
&resource.File{
82105
Provider: "stack-file",
83106
Path: KibanaConfigFile,
@@ -259,6 +282,9 @@ func DeleteProfile(profileName string) error {
259282
// FetchAllProfiles returns a list of profile values
260283
func FetchAllProfiles(elasticPackagePath string) ([]Metadata, error) {
261284
dirList, err := os.ReadDir(elasticPackagePath)
285+
if errors.Is(err, os.ErrNotExist) {
286+
return []Metadata{}, nil
287+
}
262288
if err != nil {
263289
return []Metadata{}, fmt.Errorf("error reading from directory %s: %w", elasticPackagePath, err)
264290
}

0 commit comments

Comments
 (0)