Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toxophilist/sprint dev #484

Merged
merged 8 commits into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
1. Allow the creation / definition of local Users
2. Allow the creation / definition of OCI Groups
2. Bastion as a Service functionality added to main design canvas.
3. Update cache functionality to store based on Configuration & Region.
4. Add "OKIT Reference" Tag to all resources created via OKIT to allow for future expansion / reference.
### Bug Fixes
1. Add missing policy documentation to export to markdown.
2. Fix Save As Template to add .json if not specified.


## Version 0.27.1
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LABEL "provider"="Oracle" \
"version"="0.27.1" \
"description"="OKIT Web Server Container." \
"copyright"="Copyright (c) 2020, 2021, Oracle and/or its affiliates."
SHELL ["/bin/bash", "-c"]
# SHELL ["/bin/bash", "-c"]
ENV PYTHONIOENCODING=utf8 \
PYTHONPATH=":/okit/visualiser:/okit/okitweb:/okit" \
FLASK_APP=okitweb \
Expand Down
2 changes: 1 addition & 1 deletion containers/docker/8-slim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LABEL "provider"="Oracle" \
"version"="0.20.0" \
"description"="OKIT Web Server Container." \
"copyright"="Copyright (c) 2020, 2021, Oracle and/or its affiliates."
SHELL ["/bin/bash", "-c"]
# SHELL ["/bin/bash", "-c"]
ENV PYTHONIOENCODING=utf8 \
PYTHONPATH=":/okit/visualiser:/okit/okitweb:/okit" \
FLASK_APP=okitweb \
Expand Down
2 changes: 1 addition & 1 deletion containers/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LABEL "provider"="Oracle" \
"version"="0.27.1" \
"description"="OKIT Web Server Container." \
"copyright"="Copyright (c) 2020, 2021, Oracle and/or its affiliates."
SHELL ["/bin/bash", "-c"]
# SHELL ["/bin/bash", "-c"]
ENV PYTHONIOENCODING=utf8 \
PYTHONPATH=":/okit/visualiser:/okit/okitweb:/okit" \
FLASK_APP=okitweb \
Expand Down
6 changes: 3 additions & 3 deletions okitweb/okitOci.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ def resourceTypes(profile):
return 'Unknown Method', 500


@bp.route('/dropdown/<string:profile>', methods=(['GET']))
def dropdownQuery(profile):
@bp.route('/dropdown/<string:profile>/<string:region>', methods=(['GET']))
def dropdownQuery(profile, region):
if request.method == 'GET':
dropdown_query = OCIDropdownQuery(profile=profile)
dropdown_json = dropdown_query.executeQuery()
dropdown_json = dropdown_query.executeQuery([region])
return dropdown_json
else:
return 'Unknown Method', 500
Expand Down
10 changes: 6 additions & 4 deletions okitweb/okitWebDesigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,12 @@ def template_save():
instance_path = current_app.instance_path
root_dir = request.json["root_dir"].strip('/')
template_filename = request.json["template_file"].strip('/')
if not template_filename.endswith('.json'):
template_filename = f'{template_filename}.json'
okit_json = request.json["okit_json"]
git = request.json.get('git', False)
git_commit_msg = request.json.get('git_commit_msg', '')
logger.info(f'Save Template : {root_dir}')
logger.info(f'Save Template : {root_dir} {template_filename}')

template_dir = os.path.dirname(template_filename)
full_dir = os.path.join(instance_path, root_dir, template_dir)
Expand Down Expand Up @@ -577,13 +579,13 @@ def saveas(savetype):
return str(e), 500


@bp.route('/dropdown/data/<string:profile>', methods=(['GET', 'POST']))
def dropdownData(profile):
@bp.route('/dropdown/data/<string:profile>/<string:region>', methods=(['GET', 'POST']))
def dropdownData(profile, region):
dropdown_dir = os.path.abspath(os.path.join(bp.static_folder, 'json', 'dropdown'))
shipped_dropdown_file = os.path.abspath(os.path.join(dropdown_dir, 'dropdown.json'))
# shipped_dropdown_file = os.path.abspath(os.path.join(bp.static_folder, 'json', 'dropdown', 'dropdown.json'))
profile_dropdown_dir = os.path.abspath(os.path.join(dropdown_dir, 'profiles'))
profile_dropdown_file = os.path.abspath(os.path.join(profile_dropdown_dir, f'{profile}.json'))
profile_dropdown_file = os.path.abspath(os.path.join(profile_dropdown_dir, profile, f'{region}.json'))
# Check if profile specific dropdown file exists if not use the default
if request.method == 'GET':
if os.path.exists(profile_dropdown_file):
Expand Down
54 changes: 30 additions & 24 deletions okitweb/static/okit/js/okit.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,65 +75,71 @@ class OkitGITConfig {
class OkitOCIData {
key = "OkitDropdownCache";
day_milliseconds = 86400000;
constructor(profile) {
constructor(profile, region='uk-london-1') {
this.compartments = [];
this.dropdown_data = {}
this.load(profile);
this.load(profile, region);
}

clearLocalStorage() {localStorage.removeItem(this.key)}

storeLocal(profile) {
getCache() {
const local_data = localStorage.getItem(this.key)
return local_data ? JSON.parse(local_data) : {}
}

storeLocal(profile, region='') {
console.info(`Storing Local Dropdown data for ${profile}`);
const local_data = localStorage.getItem(this.key)
let cache = {}
if (local_data) cache = JSON.parse(local_data)
if (profile) cache[profile] = this.dropdown_data
if (profile && !cache.hasOwnProperty(profile)) cache[profile] = {}
if (profile) cache[profile][region] = this.dropdown_data
localStorage.setItem(this.key, JSON.stringify(cache))
}

loadLocal(profile) {
loadLocal(profile, region='') {
const local_data = localStorage.getItem(this.key)
console.info(`Loading Local Dropdown data for ${profile}`);
let cache = {}
if (local_data) cache = JSON.parse(local_data)
if (profile && cache[profile]) {
if (profile && region && cache[profile] && cache[profile][region]) {
// Add test for stale cache && cache[profile].cache_date && ((Date.now() - cache[profile].cache_date) / this.day_milliseconds) <= 7
console.info(`Found Local Dropdown Data for ${profile}`);
this.dropdown_data = cache[profile]
console.info(`Found Local Dropdown Data for ${profile} ${region}`);
this.dropdown_data = cache[profile][region]
return true;
} else {
return false;
}
}

load(profile) {
load(profile, region='') {
console.info('Loading Dropdown data for', profile);
this.compartments = [];
const self = this;
if (!this.loadLocal(profile)) {
if (!this.loadLocal(profile, region)) {
const start = new Date().getTime()
$.getJSON(`dropdown/data/${String(profile)}`, (resp) => {
$.getJSON(`dropdown/data/${String(profile)}/${String(region)}`, (resp) => {
const end = new Date().getTime()
console.info('Load Dropdown Data took', end - start, 'ms')
// $.extend(true, self, resp);
self.dropdown_data = resp;
self.storeLocal(profile);
self.storeLocal(profile, region);
if (resp.shipped && profile !== undefined) {
self.refresh(profile);
self.refresh(profile, region);
}
});
}
}

refresh(profile) {
refresh(profile, region='') {
console.info('Refreshing Dropdown data for', profile);
this.query(profile, false)
this.query(profile, false, region)
}

save(profile) {
save(profile, region='') {
console.info('Saving Dropdown data for', profile);
this.storeLocal(profile);
this.storeLocal(profile, region);
$.ajax({
type: 'post',
url: `dropdown/data/${String(profile)}`,
Expand All @@ -148,26 +154,26 @@ class OkitOCIData {
});
}

cloneForSave(profile) {
cloneForSave(profile, region='') {
let clone = JSON.clone(this);
clone.compartments = [];
return clone;
}

query(profile, save=false) {
console.info('Querying Dropdown data for', profile);
query(profile, save=false, region='') {
console.info('Querying Dropdown data for', profile, region);
const self = this;
const start = new Date().getTime()
$.getJSON(`oci/dropdown/${profile}`, (resp) => {
$.getJSON(`oci/dropdown/${profile}/${region}`, (resp) => {
// Merge with base dropdown overwriting where appropriate with new data
self.dropdown_data = {...self.dropdown_data, ...resp};
delete self.dropdown_data.default
delete self.dropdown_data.shipped
self.dropdown_data.cache_date = Date.now()
const end = new Date().getTime()
console.info('Queried Dropdown Data for', profile, 'took', end - start, 'ms')
if (save) this.save(profile)
else this.storeLocal(profile)
if (save) this.save(profile, region)
else this.storeLocal(profile, region)
});
}

Expand Down Expand Up @@ -394,7 +400,7 @@ class OkitSettings {
this.is_vcn_defaults = true;
this.is_timestamp_files = false;
this.profile = 'DEFAULT';
this.region = ''
this.region = 'uk-london-1'
this.is_always_free = false;
this.is_optional_expanded = true;
this.is_display_grid = false;
Expand Down
4 changes: 3 additions & 1 deletion okitweb/static/okit/js/okit_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function handleConfigChanged(event) {
console_header_region_select.empty()
console_header_region_select.append($('<option>').attr('value', '').text('Retrieving....'))
okitRegions.load(okitSettings.profile)
okitOciData.load(okitSettings.profile)
okitOciData.load(okitSettings.profile, okitSettings.region)
setOCILink()
}

function loadHeaderRegionsDropDown() {
Expand All @@ -141,6 +142,7 @@ function handleRegionChanged(event) {
event.stopPropagation()
okitSettings.region = $('#console_header_region_select').val()
okitSettings.save()
okitOciData.load(okitSettings.profile, okitSettings.region)
setOCILink()
}

Expand Down
3 changes: 2 additions & 1 deletion okitweb/static/okit/js/okit_designer.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ function displaySaveAsTemplateDialog(title, callback, root_dir='templates/user')
.attr('id', 'template_file_name')
.attr('name', 'template_file_name')
.attr('type', 'text')
.attr('placeholder', '<Directory Path>/<Filename>.json')
.on('keydown', (e) => {
if (d3.event.keyCode == 220) {
d3.event.preventDefault()
Expand Down Expand Up @@ -1837,5 +1838,5 @@ function handleRefreshDropdownData(event) {
okitRegions.clearLocalStorage()
okitOciData.clearLocalStorage()
okitRegions.load(okitSettings.profile)
okitOciData.load(okitSettings.profile)
okitOciData.load(okitSettings.profile, okitSettings.region)
}
2 changes: 1 addition & 1 deletion okitweb/static/okit/js/okit_designer_ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $(document).ready(function() {
okitSettings = new OkitSettings();
okitOciConfig = new OkitOCIConfig(loadHeaderConfigDropDown);
okitRegions = new OkitRegions(loadHeaderRegionsDropDown);
okitOciData = new OkitOCIData(okitSettings.profile);
okitOciData = new OkitOCIData(okitSettings.profile, okitSettings.region);
okitGitConfig = new OkitGITConfig();
okitJsonModel = new OkitJson();
okitJsonView = new OkitDesignerJsonView(okitJsonModel);
Expand Down
9 changes: 9 additions & 0 deletions okitweb/static/okit/js/okit_view_layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function handleViewSelect(e) {
else if (selected === 'tabular') handleSwitchToTabularView(e)
else if (selected === 'relationship') handleSwitchToRelationshipView(e)
else if (selected === 'json') handleSwitchToTextJsonView(e)
else if (selected === 'cache') handleSwitchToTextCacheView(e)
else if (selected === 'identity') handleSwitchToIdentityView(e)
else console.warn('Unknown View', selected)
}
Expand Down Expand Up @@ -88,3 +89,11 @@ function handleSwitchToTextJsonView(e) {
okitTextJsonView = new OkitTextJsonView(okitJsonModel, okitOciData, resource_icons);
okitTextJsonView.draw();
}

function handleSwitchToTextCacheView(e) {
hideAllViewDivs();
$("#json-text-div").removeClass('hidden');
hideSideBars();
okitCacheJsonView = new OkitCacheJsonView(okitOciData.getCache(), okitOciData, resource_icons);
okitCacheJsonView.draw();
}
11 changes: 11 additions & 0 deletions okitweb/static/okit/model/js/artefacts/file_storage_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class FileStorageSystem extends OkitArtifact {
}
})
}

// Updated Structure
// this.mount_targets = [
// {
// subnet_id: this.subnet_id ? this.subnet_id : '',
// hostname_label: this.display_name.toLowerCase(),
// nsg_ids: [],
// file_systems: [{}]
// }
// ]

this.convert();
// Expose subnet_id for the first Mount target at the top level
delete this.subnet_id;
Expand Down
72 changes: 72 additions & 0 deletions okitweb/static/okit/model/js/artefacts/file_system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
** Copyright (c) 2020, 2021, Oracle and/or its affiliates.
** Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
console.info('Loaded File System Javascript');

/*
** Define File System Class
*/
class FileSystem extends OkitArtifact {
/*
** Create
*/
constructor (data={}, okitjson={}) {
super(okitjson);
// Configure default values
this.display_name = this.generateDefaultName(okitjson.file_systems.length + 1);
this.compartment_id = data.parent_id;
/*
** TODO: Add Resource / Artefact specific parameters and default
*/
// Update with any passed data
this.merge(data);
this.convert();
// TODO: If the Resource is within a Subnet but the subnet_iss is not at the top level then raise it with the following functions if not required delete them.
// Expose subnet_id at the top level
Object.defineProperty(this, 'subnet_id', {get: function() {return this.primary_mount_target.subnet_id;}, set: function(id) {this.primary_mount_target.subnet_id = id;}, enumerable: false });
}
/*
** Clone Functionality
*/
clone() {
return new FileSystem(JSON.clone(this), this.getOkitJson());
}
/*
** Name Generation
*/
getNamePrefix() {
return super.getNamePrefix() + 'fs';
}
/*
** Static Functionality
*/
static getArtifactReference() {
return 'File System';
}
}
/*
** Dynamically Add Model Functions
*/
OkitJson.prototype.newFileSystem = function(data) {
this.getFileSystems().push(new FileSystem(data, this));
return this.getFileSystems()[this.getFileSystems().length - 1];
}
OkitJson.prototype.getFileSystems = function() {
if (!this.file_systems) {
this.file_systems = [];
}
return this.file_systems;
}
OkitJson.prototype.getFileSystem = function(id='') {
for (let artefact of this.getFileSystems()) {
if (artefact.id === id) {
return artefact;
}
}
return undefined;
}
OkitJson.prototype.deleteFileSystem = function(id) {
this.file_systems = this.file_systems ? this.file_systems.filter((r) => r.id !== id) : []
}

Loading