Skip to content

Commit 7501c1a

Browse files
authored
Merge pull request #414 from ukmda/markmac99
Merge in a bunch of updates from my dev branch
2 parents 465c91f + a995ce6 commit 7501c1a

34 files changed

Lines changed: 51 additions & 2896 deletions

.github/workflows/build_tools.yml

Lines changed: 0 additions & 125 deletions
This file was deleted.
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@
33
vars_files:
44
- /mnt/c/Users/{{ lookup('env','USER' )}}/apikeys/mqvariables.enc
55
vars:
6-
srcdir: "/mnt/c/Users/{{ lookup('env','USER' )}}/OneDrive/dev/ukmda-dataprocessing/usermgmt/server"
6+
srcdir: "/mnt/c/Users/{{ lookup('env','USER' )}}/OneDrive/dev/meteorhunting/ukmda-dataprocessing/archive/usermgmt"
7+
destdir: /home/ec2-user/keymgmt
78
tasks:
8-
- name: import dev variables
9-
include_vars: ./dev-vars.yml
10-
tags: dev
11-
- name: import prod variables
12-
include_vars: ./prod-vars.yml
13-
tags: prod
149
- name: Ensures {{destdir}} exists
1510
file: path={{destdir}} state=directory
16-
tags: [dev,prod]
1711

1812
- name: Copy files
19-
tags: [dev,prod]
2013
copy: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode }}
2114
with_items:
2215
- {src: '{{srcdir}}/addSftpUser.sh', dest: '{{destdir}}/', mode: '744', backup: yes, directory_mode: no }
2316
- {src: '{{srcdir}}/updateAwsKey.sh', dest: '{{destdir}}/', mode: '744', backup: yes, directory_mode: no }
24-
- {src: '{{srcdir}}/ukmon.ini', dest: '{{destdir}}/', mode: '644', backup: yes, directory_mode: no }
17+
- {src: '{{srcdir}}/addAdminUser.sh', dest: '{{destdir}}/', mode: '744', backup: yes, directory_mode: no }
18+
- {src: '{{srcdir}}/addFBApiKey.sh', dest: '{{destdir}}/', mode: '744', backup: yes, directory_mode: no }

archive/ukmon_pylib/reports/createSearchableFormat.py

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,27 @@
99
import os
1010
import pandas as pd
1111
import datetime
12+
import boto3
13+
14+
15+
def checkUrl(s3, url):
16+
siteroot = os.getenv('WEBSITEBUCKET', default='s3://ukmda-website')
17+
retval = url
18+
tmpurl = url
19+
if url[0]==',':
20+
tmpurl = url[1:]
21+
try:
22+
_ = s3.head_object(Bucket=siteroot[5:], Key=tmpurl[1:])
23+
except Exception:
24+
#print(e)
25+
retval = '/img/missing-white.png'
26+
print(url, retval)
27+
return retval
1228

1329

1430
def convertSingletoSrchable(datadir, year, newonly=True):
1531
print(datetime.datetime.now(), 'single-detection searchable index start')
32+
s3 = boto3.client('s3')
1633

1734
# load the single-station combined data
1835
if newonly is False:
@@ -34,6 +51,10 @@ def convertSingletoSrchable(datadir, year, newonly=True):
3451
uadata['fn']=[f'/img/single/{y}/{y}{m:02d}/'+f.replace('.fits','.jpg')
3552
for f,y,m in zip(uadata.Filename, uadata.Y, uadata.M)]
3653

54+
print(datetime.datetime.now(), 'checking target urls exist')
55+
uadata['targfn'] = [checkUrl(s3, x) for x in uadata.fn]
56+
print(datetime.datetime.now(), 'done')
57+
3758
# create array for source
3859
print(datetime.datetime.now(), 'add source column')
3960
srcs = ['2Single']*len(uadata.Filename)
@@ -44,41 +65,13 @@ def convertSingletoSrchable(datadir, year, newonly=True):
4465
print(datetime.datetime.now(), 'create interim dataframe')
4566
hdr=['eventtime','source','shower','Mag','loccam','url','imgs', 'loctime', 'Y','M']
4667
resdf = pd.DataFrame(zip(uadata.Dtstamp, srcs, uadata.Shwr,
47-
uadata.Mag, uadata.ID, uadata.fn, uadata.fn, uadata.LocalTime,
68+
uadata.Mag, uadata.ID, uadata.targfn, uadata.targfn, uadata.LocalTime,
4869
uadata.Y, uadata.M), columns=hdr)
4970

5071
# fix up some mangled historical data
5172
resdf.loc[resdf.loccam=='Ringwood_N_UK000S', 'loccam'] = 'UK000S'
5273
resdf.loc[resdf.loccam=='Tackley_SW_UK0006', 'loccam'] = 'UK0006'
5374

54-
# select the RMS data out, its good now
55-
# FIXME - needs to select for "not FF_UK9" so we can include non-UK cameras
56-
rmsdata=resdf[resdf.url.str.contains('FF_UK0')]
57-
rmsdata = rmsdata.drop(columns=['Y','M','loctime'])
58-
59-
# now select out the UFO dta and fix it up
60-
ufodata=resdf[resdf.url.str.contains('FF_UK9')]
61-
#fix up Clanfield cameras
62-
ufodata.loc[ufodata.loccam=='UK9990', 'loccam'] = 'Clanfield_NE'
63-
ufodata.loc[ufodata.loccam=='UK9989', 'loccam'] = 'Clanfield_NW'
64-
ufodata.loc[ufodata.loccam=='UK9988', 'loccam'] = 'Clanfield_SE'
65-
ufodata = ufodata.drop(columns=['url','imgs'])
66-
67-
# create the URL and imgs fields
68-
ufodata['url']=[f'/img/single/{y}/{y}{m:02d}/M{lt}_{f}P.jpg'
69-
for f,y,m,lt in zip(ufodata.loccam, ufodata.Y, ufodata.M, ufodata.loctime)]
70-
ufodata['imgs'] = ufodata.url
71-
ufodata = ufodata.drop(columns=['loctime','Y','M'])
72-
73-
# annoying special case for UK0001, H and S which do not upload JPGs
74-
rmsdata.loc[rmsdata.loccam=='UK0001','url']='/img/missing-white.png'
75-
rmsdata.loc[rmsdata.loccam=='UK0001','imgs']='/img/missing-white.png'
76-
rmsdata.loc[rmsdata.loccam=='UK000H','url']='/img/missing-white.png'
77-
rmsdata.loc[rmsdata.loccam=='UK000H','imgs']='/img/missing-white.png'
78-
rmsdata.loc[rmsdata.loccam=='UK000S','url']='/img/missing-white.png'
79-
rmsdata.loc[rmsdata.loccam=='UK000S','imgs']='/img/missing-white.png'
80-
81-
resdf = pd.concat([rmsdata,ufodata])
8275
if newonly is True:
8376
return resdf, rmsuafile
8477
else:
@@ -114,19 +107,22 @@ def convertMatchToSrchable(datadir, year, newonly=True):
114107

115108
if __name__ == '__main__':
116109
if len(sys.argv) < 3:
117-
print('usage: python createSearchableFormat.py year dest mode')
110+
print('usage: python createSearchableFormat.py year mode outdir')
118111
exit(1)
119112
else:
120113
datadir = os.getenv('DATADIR', default='/home/ec2-user/prod/data')
121114

122115
year = sys.argv[1]
123116
mode = sys.argv[2]
117+
outdir = os.path.join(datadir, 'searchidx')
118+
if len(sys.argv) > 3:
119+
outdir = sys.argv[3]
124120

125121
# create a set of single-station data and merge with last match set
126122
if mode == 'singles':
127123
print(datetime.datetime.now(), 'converting single-station data')
128124
newsingles, fname = convertSingletoSrchable(datadir, year, True)
129-
outfile = os.path.join(datadir, 'searchidx', '{:s}-singles-new.csv'.format(year))
125+
outfile = os.path.join(outdir, '{:s}-singles-new.csv'.format(year))
130126
if newsingles is not None:
131127
newsingles.to_csv(outfile, index=False, header=False)
132128
if fname is not None:
@@ -136,11 +132,11 @@ def convertMatchToSrchable(datadir, year, newonly=True):
136132
elif mode == 'matches':
137133
print(datetime.datetime.now(), 'converting match data')
138134
newmatches, fname = convertMatchToSrchable(datadir, year, True)
139-
outfile = os.path.join(datadir, 'searchidx', '{:s}-matches-new.csv'.format(year))
135+
outfile = os.path.join(outdir, '{:s}-matches-new.csv'.format(year))
140136
if newmatches is not None:
141137
newmatches.to_csv(outfile, index=False, header=False)
142138
if fname is not None:
143139
os.remove(fname)
144140

145141
else:
146-
print('usage: createSearchableFormat yyyy matches_or_singles')
142+
print('usage: createSearchableFormat year mode outdir')
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# simple script to create a new user-maintenance account
2-
# and save the access key locally. Can only be used by an account with IAM Admin permissions.
3-
$username = $args[0]
4-
aws iam create-user --user-name $username --profile ukmda_admin
5-
aws iam add-user-to-group --user-name $username --user-group Administrators --profile ukmda_admin
1+
#!/bin/bash
2+
# simple script to create a new user-maintenance account
3+
# and save the access key locally. Can only be used by an account with IAM Admin permissions.
4+
$username = $args[0]
5+
aws iam create-user --user-name $username --profile ukmda_admin
6+
aws iam add-user-to-group --user-name $username --user-group Administrators --profile ukmda_admin
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# copyright Mark McIntyre, 2024-
2-
3-
# script to add an api key for a user
4-
5-
$username = $args[0]
6-
aws apigateway create-api-key --name "$username" --region eu-west-1 --profile ukmda_admin --description "key for $username" --enabled
1+
#!/bin/bash
2+
# copyright Mark McIntyre, 2024-
3+
4+
# script to add an api key for a user
5+
6+
$username = $1
7+
aws apigateway create-api-key --name "$username" --region eu-west-1 --description "key for $username" --enabled --profile ukmda_admin
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if [ ! -f $keydir/keys/$shortid_l.key ] ; then
4444
fi
4545

4646
# add a unix user and set their homedir to /var/sftp/userid
47-
grep $userid /etc/passwd
47+
grep -w $userid /etc/passwd
4848
if [ $? -eq 1 ] ; then
4949
dt=$(date +%Y-%m-%d)
5050
logger -s -t addSftpUser "Creating unix user $userid"
@@ -91,6 +91,10 @@ if [ ! -z $oldloc ] ; then
9191
logger -s -t addSftpUser "Moving $oldloc to $userid"
9292
sudo cp /var/sftp/$oldloc/ukmon.ini /var/sftp/$oldloc/ukmon.ini.bkp
9393
sudo cp $keydir/inifs/$userid.ini /var/sftp/$oldloc/ukmon.ini
94+
# and copy the ssh authorized keys file
95+
sudo cp $oldloc/.ssh/authorized_keys /var/sftp/$userid/.ssh/
96+
sudo chown -R $userid:$userid /var/sftp/$userid/.ssh/authorized_keys
97+
sudo chmod 644 /var/sftp/$userid/.ssh/authorized_keys
9498
fi
9599

96100
logger -s -t addSftpUser "Finished"

0 commit comments

Comments
 (0)