Skip to content

Commit

Permalink
- packaging: restructuring all code into snafulib with adapted and so…
Browse files Browse the repository at this point in the history
…rt of working setup.py
  • Loading branch information
spio committed Apr 22, 2017
1 parent 4ea931b commit 5724a5f
Show file tree
Hide file tree
Showing 10 changed files with 735 additions and 709 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ snafu.ini
functions-local
functions-tenants
_*

build/
dist/
snafu.egg-info/
19 changes: 10 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware"
],
keywords="cloud faas serverless functions",
packages=["snafu"],
entry_points={
"console_scripts": [
"snafu=snafu:main",
"snafu-import=snafuimport:main",
"snafu-control=snafucontrol:main",
"snafu-accounts=snafuaccounts:main"
]
}
packages=["snafulib"],
scripts=["snafu", "snafu-import", "snafu-accounts", "snafu-control"]
#entry_points={
# "console_scripts": [
# "snafu=snafu:main",
# "snafu-import=snafuimport:main",
# "snafu-control=snafucontrol:main",
# "snafu-accounts=snafuaccounts:main"
# ]
#}
)
6 changes: 3 additions & 3 deletions snafu
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
#
# Snafu: Snake Functions - Command-Line Tool
# Snafu: Snake Functions - Main Command-Line Tool

import lib.snafu
import snafulib.snafu

sr = lib.snafu.SnafuRunner()
snafulib.snafu.SnafuRunner()
50 changes: 3 additions & 47 deletions snafu-accounts
Original file line number Diff line number Diff line change
@@ -1,51 +1,7 @@
#!/usr/bin/env python3
#
# Snafu: Snake Functions - Account Management
# Snafu: Snake Functions - Account Management Command-Line Tool

import sys
import os.path
import argparse
import configparser
import snafulib.snafuaccounts

class SnafuAccounts:
def __init__(self):
self.accounts = {}

def addaccount(self, key, secret, endpoint):
accdb = os.path.expanduser("~/.snafu-accounts")
if os.getenv("HOME") == "/":
accdb = "/root/.snafu-accounts"
c = configparser.ConfigParser()
try:
c.read(accdb)
except:
pass
acc = "account{}".format(len(c.sections()))
c.add_section(acc)
c.set(acc, "access_key_id", key)
c.set(acc, "secret_access_key", secret)
if endpoint:
c.set(acc, "endpoint", endpoint)
f = open(accdb, "w")
c.write(f)

def run(self):
parser = argparse.ArgumentParser(description="Snake Functions as a Service - Account Management")
parser.add_argument("-a", "--add", help="add an account", action="store_true")
parser.add_argument("-k", "--key-id", help="access key id")
parser.add_argument("-s", "--secret-access-key", help="secret access key")
parser.add_argument("-e", "--endpoint", help="tenant-specific static endpoint")
args = parser.parse_args()

if args.add:
if not args.key_id or not args.secret_access_key:
print("Error: Must specify both --key-id and --secret-access-key for --add.", file=sys.stderr)
return

self.addaccount(args.key_id, args.secret_access_key, args.endpoint)
else:
print("Error: Must specify --add.", file=sys.stderr)
return

sa = SnafuAccounts()
sa.run()
snafulib.snafuaccounts.SnafuAccountsRunner()
Loading

0 comments on commit 5724a5f

Please sign in to comment.