Allow importing environment variables via Postman environment json files
This commit is contained in:
@@ -119,15 +119,28 @@ export default {
|
|||||||
let reader = new FileReader()
|
let reader = new FileReader()
|
||||||
reader.onload = event => {
|
reader.onload = event => {
|
||||||
let content = event.target.result
|
let content = event.target.result
|
||||||
let environments = JSON.parse(content)
|
let importFileObj = JSON.parse(content)
|
||||||
let confirmation = this.$t("file_imported")
|
if (importFileObj["_postman_variable_scope"] === "environment") {
|
||||||
this.$store.commit("postwoman/importAddEnvironments", {
|
this.importFromPostman(importFileObj)
|
||||||
environments,
|
} else {
|
||||||
confirmation,
|
this.importFromPostwoman(importFileObj)
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0])
|
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0])
|
||||||
},
|
},
|
||||||
|
importFromPostwoman(environments) {
|
||||||
|
let confirmation = this.$t("file_imported")
|
||||||
|
this.$store.commit("postwoman/importAddEnvironments", {
|
||||||
|
environments,
|
||||||
|
confirmation,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
importFromPostman(importFileObj) {
|
||||||
|
let environment = { name: importFileObj.name, variables: [] }
|
||||||
|
importFileObj.values.forEach(element => environment.variables.push({ key: element.key, value: element.value }));
|
||||||
|
let environments = [ environment ]
|
||||||
|
this.importFromPostwoman(environments)
|
||||||
|
},
|
||||||
exportJSON() {
|
exportJSON() {
|
||||||
let text = this.environmentJson
|
let text = this.environmentJson
|
||||||
text = text.replace(/\n/g, "\r\n")
|
text = text.replace(/\n/g, "\r\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user