Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
output = subprocess.check_output(
['security', 'find-generic-password', '-a', os.environ["USER"], '-s', 'GITLAB_TOKEN', '-w']
)
if len(output) > 0:
return output.strip()
except subprocess.CalledProcessError:
print("GITLAB_TOKEN not found in keychain...")
pass
print(
"Please create an 'api' access token at "
"https://gitlab.ddbuild.io/profile/personal_access_tokens and "
"add it as GITLAB_TOKEN in your keychain "
"or export it from your .bashrc or equivalent."
)
raise Exit(code=1)
return os.environ["GITLAB_TOKEN"]
headers = dict(headers or [])
headers["Authorization"] = "token {}".format(self.api_token)
headers["Accept"] = "application/vnd.github.v3+json"
try:
if data:
r = requests.post(url, headers=headers, data=data)
else:
r = requests.get(url, headers=headers)
if r.status_code == 401:
print(
"HTTP 401: Your GITHUB_TOKEN may have expired. You can "
"check and refresh it at "
"https://github.com/settings/tokens"
)
print("Github says: {}".format(r.json()["error_description"]))
raise Exit(code=1)
except requests.exceptions.Timeout:
print("Connection to Github ({}) timed out.".format(url))
raise Exit(code=1)
except requests.exceptions.RequestException as e:
m = errno_regex.match(str(e))
if not m:
print("Unknown error raised connecting to {}: {}".format(url, e))
# Parse errno to give a better explanation
# Requests doesn't have granularity at the level we want:
# http://docs.python-requests.org/en/master/_modules/requests/exceptions/
errno_code = int(m.group(1))
message = m.group(2)
if errno_code == errno.ENOEXEC:
print("Error resolving {}: {}".format(url, message))
def push_database_to_heroku(c, app_instance):
check_if_logged_in_to_heroku(c)
prompt_msg = 'You are about to push your local database to Heroku. ' \
'It\'s a destructive operation and will override the ' \
'database on the server. \n' \
'Please type the application name "{app_instance}" to ' \
'proceed:\n>>> '.format(app_instance=make_bold(app_instance))
if input(prompt_msg) != app_instance:
raise Exit("Aborted")
local('heroku maintenance:on --app {app}'.format(app=app_instance))
local('heroku ps:stop --app {app} web'.format(app=app_instance))
local('heroku pg:backups:capture --app {app}'.format(app=app_instance))
local('heroku pg:reset --app {app} --confirm {app}'.format(app=app_instance))
local('heroku pg:push --app {app} {local_db} DATABASE_URL'.format(
app=app_instance,
local_db=LOCAL_DATABASE_NAME
))
local('heroku ps:restart --app {app}'.format(app=app_instance))
local('heroku maintenance:off --app {app}'.format(app=app_instance))
"""
# Retrieve a list of all available vagrant images
images = {}
with open(os.path.join(KITCHEN_DIR, "platforms.json"), 'r') as f:
for platform, by_provider in json.load(f).items():
if "vagrant" in by_provider:
for image in by_provider["vagrant"][arch]:
images[image] = platform
if not (target in images):
print(
"please run inv -e system-probe.kitchen-test --target <img>, where <img> is one of the following:\n%s"
% (list(images.keys()))
)
raise Exit(code=1)
with ctx.cd(KITCHEN_DIR):
ctx.run(
"inv kitchen.genconfig --platform {platform} --osversions {target} --provider vagrant --testfiles system-probe-test".format(
target=target, platform=images[target]
),
env={"KITCHEN_VAGRANT_PROVIDER": "virtualbox"},
)
ctx.run("kitchen test")
def deploy_prompt(c, app_instance):
prompt_msg = 'You are about to do a manual deployment. You probably ' \
'should use automatic deployments on CI. \nPlease type ' \
'the application name "{app_instance}" in order to ' \
'proceed:\n>>> '.format(app_instance=make_bold(app_instance))
if input(prompt_msg) != app_instance:
raise Exit("Aborted")
def validate_kind_version():
"""Validate minimum required version of kind."""
# If kind is not installed, this first command will raise an UnexpectedExit
# exception, and inv will exit at this point making it clear running "kind"
# failed.
min_version = "0.9.0"
try:
raw = run("kind version", echo=True)
except Exception as e:
raise Exit(message="Could not determine kind version (is kind installed?)")
actual_version = re.search("v(\d*\.\d*\.\d*)", raw.stdout).group(1)
delta = semver.compare(actual_version, min_version)
if delta < 0:
raise Exit(message="kind version >= {} required".format(min_version))
def check_environment(ctx):
"""
Ensure that a .yaml file has been specified
"""
if 'namespace' not in ctx.config['kubernetes']:
print("Please specify a configuration file with -f")
raise Exit()
--config {config}
--
{f"-j {number_of_jobs}" if number_of_jobs >= 0 else ""}
{"-d keeprsp" if sys.platform.startswith("win") else ""}
""")
commands = [cmake_command, build_command]
if sys.platform.startswith('win'):
for vcvars_path in _get_vcvars_paths():
if not vcvars_path.is_file():
continue
commands.insert(0, f'"{vcvars_path}" amd64')
break
else:
raise Exit(
'Error: Commands to configure MSVC environment variables not found.',
code=1,
)
os.chdir(build_dir)
c.run("&&".join(commands))
def init_git_repo(c, repo_name, org_name='kinecosystem', remote='origin', branch='master'):
"""Make sure git repo directory is available before building."""
# clone git repo if it doesn't exist,
# otherwise checkout master branch
dir_name = '{}-git'.format(repo_name)
git_url = 'https://github.com/{}/{}.git'.format(org_name, repo_name)
if not os.path.isdir('{}/{}/volumes/{}'.format(os.getcwd(), c.cwd, dir_name)):
print('%s git repository doesn\'t exist, cloning' % repo_name)
c.run('git clone --branch {branch} {git_url} volumes/{dir_name}'.format(branch=branch, git_url=git_url, dir_name=dir_name))
else:
with c.cd('volumes/{}'.format(dir_name)):
if is_git_dir_modified(c):
raise Exit('Stopping, please clean changes and retry')
git_dir_checkout_branch(c, org_name, repo_name, remote, branch)
return dir_name