File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,12 +37,38 @@ jobs:
3737 uses : elastic/elastic-github-actions/elasticsearch@master
3838 with :
3939 stack-version : 8.15.3
40- security-enabled : false
40+ security-enabled : true
41+ elasticsearch_password : elasticsearch-password
4142 plugins : analysis-kuromoji
4243
4344 - name : Elasticsearch is reachable
4445 run : |
45- curl --verbose --show-error http://localhost:9200
46+ curl --verbose --show-error --fail -k -u elastic:elasticsearch-password http://localhost:9200
47+
48+ - name : Create Elasticsearch API Key
49+ id : create_key
50+ run : |
51+ API_KEY_CREATE_RESPONSE=$(
52+ curl -u "elastic:elasticsearch-password" \
53+ -X POST "http://localhost:9200/_security/api_key" \
54+ -H "Content-Type: application/json" \
55+ -d '{
56+ "name": "main-key",
57+ "expiration": "1825d",
58+ "role_descriptors": {
59+ "main-role": {
60+ "cluster": ["monitor"],
61+ "indices": [
62+ {
63+ "names": ["test_*"],
64+ "privileges": ["write", "read", "manage"]
65+ }
66+ ]
67+ }
68+ }
69+ }')
70+ ENCODED_KEY=$(echo $API_KEY_CREATE_RESPONSE | jq -r '.encoded')
71+ echo "INAT_ES_API_KEY=$ENCODED_KEY" >> $GITHUB_ENV
4672
4773 - name : Copy config
4874 run : |
Original file line number Diff line number Diff line change 1+ const {
2+ INAT_ES_API_KEY
3+ } = process.env;
4+
15module.exports = {
26 apiURL: "http://localhost:3000",
37 currentVersionURL: "http://localhost:4000/v1",
48 elasticsearch: {
5- host: "http://localhost:9200"
9+ host: "http://localhost:9200",
10+ apiKey: INAT_ES_API_KEY
611 },
712 database: {
813 user: "postgres",
Original file line number Diff line number Diff line change 55 INAT_DB_USER ,
66 INAT_DB_PASS ,
77 INAT_ES_HOST ,
8+ INAT_ES_API_KEY ,
89 INAT_REDIS_HOST ,
910 INAT_RAILS_URL
1011} = process . env ;
@@ -17,7 +18,8 @@ module.exports = {
1718 apiHostSSL : false ,
1819 writeHostSSL : false ,
1920 elasticsearch : {
20- host : INAT_ES_HOST ? `http://${ INAT_ES_HOST } :9200` : "http://localhost:9200"
21+ host : INAT_ES_HOST ? `http://${ INAT_ES_HOST } :9200` : "http://localhost:9200" ,
22+ apiKey : INAT_ES_API_KEY || "apiKey"
2123 } ,
2224 // Note that the database name will be inferred from the NODE_ENV
2325 // environment variable, e.g. `inaturalist_${process.env.NODE_ENV}`, or it
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ const config = require( "../config" );
66const util = require ( "./util" ) ;
77
88const esClient = { connection : null } ;
9- const { host, hosts } = config . elasticsearch ;
9+ const { host, hosts, apiKey } = config . elasticsearch ;
1010
1111esClient . connect = ( ) => {
1212 if ( esClient . connection ) { return esClient . connection ; }
@@ -21,6 +21,7 @@ esClient.connect = ( ) => {
2121 clientConfig . nodeSelector = "random" ;
2222 clientConfig . requestTimeout = 60000 ;
2323 clientConfig . maxRetries = 1 ;
24+ clientConfig . auth = { apiKey } ;
2425 esClient . connection = new Client ( clientConfig ) ;
2526
2627 esClient . connection . diagnostic . on ( "response" , ( err , result ) => {
You can’t perform that action at this time.
0 commit comments