Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12243072
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/roles/devserver/userland-software/files/url.py b/roles/devserver/userland-software/files/url.py
new file mode 100755
index 0000000..25ab017
--- /dev/null
+++ b/roles/devserver/userland-software/files/url.py
@@ -0,0 +1,207 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Operations utilities
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Author: Sébastien Santoro aka Dereckson
+# Created: 2018-09-22
+# License: BSD-2-Clause
+# Source file: roles/devserver/userland-software/files/url.py
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+
+import platform
+import os
+import sys
+import yaml
+
+
+# -------------------------------------------------------------
+# Exceptions
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+class NotFoundException(Exception):
+ pass
+
+
+# -------------------------------------------------------------
+# Configuration file locator
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def get_candidates_configuration_files():
+ candidates = []
+
+ if 'HOME' in os.environ:
+ candidates.append(os.environ['HOME'] + "/.urls.yml")
+
+ candidates.append('/usr/local/etc/urls.yml')
+ candidates.append('/etc/urls.yml')
+
+ return candidates
+
+
+def find_configuration_file():
+ for candidate in get_candidates_configuration_files():
+ if os.path.isfile(candidate):
+ return candidate
+
+
+# -------------------------------------------------------------
+# Configuration file parser
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def parse_configuration_file(filename):
+ configuration_file = open(filename, 'r')
+ configuration = yaml.safe_load(configuration_file)
+ configuration_file.close()
+
+ if 'urls' not in configuration:
+ configuration['urls'] = {}
+
+ return configuration
+
+
+def get_configuration():
+ configuration_file = find_configuration_file()
+
+ if configuration_file is None:
+ print_error("No shell configuration file found")
+ exit(2)
+
+ return parse_configuration_file(configuration_file)
+
+
+# -------------------------------------------------------------
+# URL resolver
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def extract_relative_url(base_directory, search_path):
+ n = len(base_directory) + 1
+ return search_path[n:]
+
+
+def extract_relative_user_url(base_directory, search_path):
+ return extract_relative_url_in_fragments(base_directory,
+ search_path, 1)
+
+
+def extract_relative_wwwroot_url(base_directory, search_path):
+ return extract_relative_url_in_fragments(base_directory,
+ search_path, 2)
+
+
+def extract_relative_url_in_fragments(base_directory, search_path,
+ fragments_count):
+ base_url = extract_relative_url(base_directory, search_path)
+ fragments = base_url.split("/", fragments_count)
+
+ expected_len = fragments_count + 1
+ actual_len = len(fragments)
+ delta_len = expected_len - actual_len
+
+ if delta_len > 1 or len(fragments[0]) == 0:
+ raise NotFoundException()
+
+ if delta_len == 1:
+ fragments.append("")
+
+ return tuple(fragments)
+
+
+def resolve_url(base_directory, args, search_path):
+ if 'static' in args:
+ return args['static'] + extract_relative_url(base_directory,
+ search_path)
+
+ if 'userdir' in args:
+ username, local_url = extract_relative_user_url(base_directory,
+ search_path)
+ return "https://" + platform.node() + "/~" + username + "/" + local_url
+
+ if 'wwwroot' in args:
+ domain, sub, local_url = extract_relative_wwwroot_url(base_directory,
+ search_path)
+ return "https://" + sub + "." + domain + "/" + local_url
+
+ return None
+
+
+def find_path(base_directory, search_path):
+ if os.path.isabs(search_path):
+ normalized_path = search_path
+ else:
+ normalized_path = os.path.normpath(os.path.join(base_directory,
+ search_path))
+
+ return os.path.realpath(normalized_path)
+
+
+def find_url(urls, base_directory, required_path):
+ path = find_path(base_directory, required_path)
+
+ for url_base_dir, url_args in urls.items():
+ url_base_dir = os.path.realpath(url_base_dir)
+ if path.startswith(url_base_dir):
+ try:
+ return resolve_url(url_base_dir, url_args, path)
+ except NotFoundException:
+ continue
+
+ return None
+
+
+# -------------------------------------------------------------
+# Runner code
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def get_program_name():
+ return os.path.basename(sys.argv[0])
+
+
+def print_error(err):
+ print("{}: {}".format(get_program_name(), err), file=sys.stderr)
+
+
+def usage():
+ print("usage: url [path]", file=sys.stderr)
+
+
+def parse_path_argument():
+ argc = len(sys.argv)
+
+ if argc == 1:
+ return '.'
+ elif argc == 2:
+ return sys.argv[1]
+ else:
+ usage()
+ exit(1)
+
+
+def main():
+ required_path = parse_path_argument()
+ config = get_configuration()
+
+ url = find_url(config['urls'], os.getcwd(), required_path)
+ if url is None:
+ print_error("No URL found.")
+ sys.exit(1)
+ else:
+ print(url)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/roles/devserver/userland-software/files/url.yml b/roles/devserver/userland-software/files/url.yml
new file mode 100644
index 0000000..8c77e7a
--- /dev/null
+++ b/roles/devserver/userland-software/files/url.yml
@@ -0,0 +1,7 @@
+urls:
+
+ /var/home-wwwroot:
+ userdir: {}
+
+ /var/wwwroot:
+ wwwroot: {}
diff --git a/roles/devserver/userland-software/misc.sls b/roles/devserver/userland-software/misc.sls
index 8eda6af..595a82a 100644
--- a/roles/devserver/userland-software/misc.sls
+++ b/roles/devserver/userland-software/misc.sls
@@ -1,136 +1,150 @@
# -------------------------------------------------------------
# Salt — Provision dev software
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-10-20
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
{% from "map.jinja" import dirs, packages, packages_prefixes with context %}
devserver_software_misc_vcs:
pkg.installed:
- pkgs:
# VCS
- cvs
- fossil
- subversion
# Bridges
- cvs2svn
- {{ packages_prefixes.python2 }}hg-git
devserver_software_misc_media:
pkg.installed:
- pkgs:
- ffmpeg2theora
- opencore-amr
- opus
- speex
- speexdsp
- x265
devserver_software_misc_text_processing:
pkg.installed:
- pkgs:
- antiword
- odt2txt
- texlive-full
devserver_software_misc_security:
pkg.installed:
- pkgs:
- aescrypt
- pwgen
- vault
devserver_software_misc_tools:
pkg.installed:
- pkgs:
- boxes
- cursive
- fusefs-s3fs
- gist
- p7zip
- primegen
- rsync
- unix2dos
{% if grains['os'] == 'FreeBSD' %}
- gawk
{% endif %}
{% if grains['os'] == 'FreeBSD' %}
devserver_software_misc_ports:
pkg.installed:
- pkgs:
- ccache
- portmaster
- portshaker
- porttools
- poudriere
- portsearch
portsearch_database:
cmd.run:
- name: portsearch -u
- creates: /var/db/portsearch
- require:
- pkg: devserver_software_misc_ports
/var/cache/ccache:
file.directory
/etc/make.conf:
file.managed:
- source: salt://roles/devserver/userland-software/files/make.conf
freebsd_kernel_modules:
pkg.installed:
- pkgs:
- pefs-kmod
freebsd_kernel_modules_enable:
module.wait:
- name: kmod.load
- mod: pefs
- persist: True
- watch:
- pkg: freebsd_kernel_modules
{% endif %}
devserver_software_misc_p2p:
pkg.installed:
- pkgs:
- transmission-daemon
- transmission-web
devserver_software_misc_gadgets:
pkg.installed:
- pkgs:
- asciiquarium
- binclock
- ditaa
- epte
devserver_software_misc_games:
pkg.installed:
- pkgs:
- bsdgames
- textmaze
devserver_software_misc_network:
pkg.installed:
- pkgs:
- getdns
- iftop
{% if grains['os_family'] == 'Debian' %}
- sockstat
{% endif %}
# -------------------------------------------------------------
# Custom simple binaries
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{ dirs.bin }}/shell:
file.managed:
- source: salt://roles/devserver/userland-software/files/shell.py
- mode: 755
+
+{{ dirs.bin }}/url:
+ file.managed:
+ - source: salt://roles/devserver/userland-software/files/url.py
+ - mode: 755
+
+# -------------------------------------------------------------
+# Configuration files
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{{ dirs.etc }}/url.yml:
+ file.managed:
+ - source: salt://roles/devserver/userland-software/files/url.yml
+ - mode: 644
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 11:39 (41 m, 43 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3065885
Default Alt Text
(9 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment