Skip to content

Commit

Permalink
chore: Manage secret for deployement
Browse files Browse the repository at this point in the history
  • Loading branch information
cballevre committed Dec 20, 2023
1 parent 39d7590 commit dff06ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ SCW_ACCESS_KEY_ID=
SCW_SECRET_ACCESS_KEY=
SCW_PROJECT_ID=
SCW_TOKEN=
SCW_BUCKET='astrolabe-expeditions-data'
MONGO_URI=mongodb+srv://username:[email protected]/?retryWrites=true&w=majority
MONGO_DATABASE=Astrolabe
14 changes: 13 additions & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ custom:
port: 8080
timeout: 100s
env:
local: local
- name: MONGO_URI
value: ${env:MONGO_URI}
- name: MONGO_DATABASE
value: ${env:MONGO_DATABASE
- name: SCW_BUCKET
value: ${env:SCW_BUCKET}
- name: SCW_ACCESS_KEY_ID
value: ${env:SCW_ACCESS_KEY_ID}
- name: SCW_SECRET_ACCESS_KEY
value: ${env:SCW_SECRET_ACCESS_KEY}
- name: SCW_ENDPOINT
value: ${env:SCW_ENDPOINT}

10 changes: 5 additions & 5 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def root(file_id):
load_dotenv() # load environment variables from .env file

myclient = pymongo.MongoClient(os.environ['MONGO_URI'])
db = myclient["Astrolabe"]
db = myclient[os.environ['MONGO_DATABASE']]

#connexion à la collection files de mongoDB
files = db.files
Expand All @@ -49,18 +49,18 @@ def root(file_id):
#insertion de lecture et traitement du dataset
s3 = connect_to_s3()
Key= "sensor/" + information["sensor_id"]+"/"+file_id+".csv"
response = s3.get_object(Bucket='astrolabe-expeditions-data', Key = Key)
response = s3.get_object(Bucket=os.environ['SCW_BUCKET'], Key = Key)
content = response['Body'].read().decode('utf-8')
data = pd.read_csv(io.StringIO(content))
dataset = run(data)

#insertion des colonnes manquantes dans le dataset
dataset["sensor_id"]=information["sensor_id"]
dataset["id"] = file_id

#connexion à la collection records de mongoDB
records=db.records

#Insertion des données dans la BDD mongoDB
records.insert_many(dataset)

Expand All @@ -70,7 +70,7 @@ def root(file_id):

#fermeture du lien avec la BDD
myclient.close()



if __name__ == "__main__":
Expand Down

0 comments on commit dff06ee

Please sign in to comment.