def test_create_secret(self): import json from osbot_aws.apis.Secrets import Secrets data = { "email": "..", "password": "******", "server": "https://os-summit.slack.com" } Secrets('gs_bot_slack_web_oss').create(json.dumps(data)) self.result = Secrets('gs_bot_slack_web_oss').value_from_json_string()
def test_exists(self): assert Secrets('aaaaa').exists() is False self.secrets.undelete() assert self.secrets.exists() is True self.secrets.delete() assert self.secrets.exists() is False
def secrets(self): if self._secrets is None: data = Secrets('sync-server-ngrok').value_from_json_string() username = data.get('username') password = data.get('password') self._secrets = (username, password) return self._secrets
def run(event, context): channel = event.get('channel') png_data = event.get('png_data') s3_bucket = event.get('s3_bucket') s3_key = event.get('s3_key') title = event.get('title') team_id = event.get('team_id') #aws_secrets_id = event.get('aws_secrets_id') #if team_id == 'T7F3AUXGV': aws_secrets_id = 'slack-gs-bot' # hard coded values #if team_id == 'T0SDK1RA8': aws_secrets_id = 'slack-gsbot-for-pbx' # need to move to special function aws_secrets_id = 'slack-bot-oauth' bot_token = Secrets(aws_secrets_id).value() if png_data: #(fd, tmp_file) = tempfile.mkstemp('png') tmp_file = Files.temp_file('.png') with open(tmp_file, "wb") as fh: fh.write(base64.decodebytes(png_data.encode())) else: if s3_bucket and s3_key: tmp_file = S3().file_download_and_delete(s3_bucket, s3_key) else: return None return send_file_to_slack(tmp_file, title, bot_token, channel)
def start_build_for_repo(self, repo_name, user='******', server_size='small'): aws_secret = "git__{0}".format(repo_name) data = Secrets(aws_secret).value_from_json_string() if not data: return None repo_url = data['repo_url'] kvargs = { 'projectName': self.project_name, 'timeoutInMinutesOverride': self.build_timeout, 'sourceLocationOverride': repo_url, 'computeTypeOverride': self.server_sizes[server_size], 'environmentVariablesOverride': [{ 'name': 'repo_name', 'value': repo_name, 'type': 'PLAINTEXT' }, { 'name': 'user', 'value': user, 'type': 'PLAINTEXT' }] } build_id = self.code_build.codebuild.start_build( **kvargs).get('build').get('arn') return {'status': 'ok', 'data': build_id}
def setup(self): if self.secrets_id is None: raise Exception('in Web_Slack no slack team provided') self.page = Browser_Page(headless = self.headless, new_page=self.new_page).setup() self.server_details = Secrets(self.secrets_id).value_from_json_string() self.server_url = self.server_details.get('server') return self
async def test_open_jira_page(self): from osbot_aws.apis.Secrets import Secrets self.api = API_Browser(headless=False) login_needed = False self.secrets_id = 'GS_BOT_GS_JIRA' (server, username, password) = Secrets( self.secrets_id).value_from_json_string().values() if login_needed: Dev.pprint(server, username, password) await self.api.open(server + '/login.jsp') page = await self.api.page() await page.type('#login-form-username', username) await page.type('#login-form-password', password) await page.click('#login-form-submit') #await self.api.open(server + '/browse/GSP-95') #page = await self.api.page() #await self.api.js_execute("$('#show-more-links-link').click()") #from time import sleep #sleep(1) await self.api.page_size(2000, 3000) await self.api.screenshot( file_screenshot='/tmp/tmp-jira-screenshot.png', full_page=True)
def setup(self): login_details = json.loads(Secrets(self.aws_secrets_id).value()) self.username = login_details.get('username') self.password = login_details.get('password') self.server_url = login_details.get('server_url') if self._browser is None: self._browser = API_Browser(headless=self.headless).sync__setup_browser() return self._browser
def _setup_Elastic_on_cloud_via_AWS_Secret(self, index, secret_id): credentials = json.loads(Secrets(secret_id).value()) host = credentials['host'] username = credentials['username'] password = credentials['password'] port = credentials['port'] self.index = index self._setup_Elastic_on_cloud(host, port, username, password) return self
def setup(self): self.page = Browser_Page(headless=self.headless, new_page=self.new_page).setup() self.server_details = Secrets(self.secrets_id).value_from_json_string() self.server_url = self.server_details.get('server') self.page.on_dialog__always_accept() #self.page.on_request__block_these(['glasswall.atlassian.net','jeditor','tinymce']) return self
def setup(self): if self.elastic is None: credentials = json.loads(Secrets(self.secrets_id).value()) host = credentials['host'] username = credentials['username'] password = credentials['password'] port = credentials['port'] self.elastic = Elastic_Search(self.index_id)._setup_Elastic_on_cloud(host, port, username, password) return self
def upload_png_file(channel_id, file): bot_token = Secrets('slack-gs-bot').value() my_file = {'file': ('/tmp/myfile.pdf', open(file, 'rb'), 'png')} payload = { "filename": 'image.png', "token": bot_token, "channels": [channel_id], } requests.post("https://slack.com/api/files.upload", params=payload, files=my_file) return 'image sent .... '
def login(self): (account_id, username, password) = Secrets( self.secrets_id).value_from_json_string().values() login_url = f'https://{account_id}.signin.aws.amazon.com/console' self.page.open(login_url) self.page.wait_for_element__id('username') js_code = f""" $('#username').val(''); $('#password').val(''); """ self.js_invoke(js_code) # this clears the values self.page.type('#username', username) # this triggers the js events required self.page.type('#password', password) self.page.click('#signin_button') # this submits the form self.wait(2)
def resolve_bot_token(self): return Secrets(self.secret_name).value()
def config(self): if self._config is None: data = Secrets(self.secrets_id).value_from_json_string() self._config = (data.get('server'), data.get('username'), data.get('password')) return self._config
def jira_server_details(self): data = Secrets(self.secrets_id).value_from_json_string() server = data.get('server') username = data.get('username') password = data.get('password') return server, username, password
def resolve_bot_token(team_id): # to refactor if team_id == '...': return Secrets('slack-gs-bot' ).value() if team_id == '...': return Secrets('slack-gsbot-for-pbx').value() return Secrets('slack-gs-bot').value()
def get_lambda_shell_auth(self): data = Secrets(self.secret_id).value_from_json_string() if data: return data.get('key')
def repo_url(self): data = Secrets(self.aws_secret).value_from_json_string() return 'https://{0}:{1}@github.com/{2}/{3}.git'.format( data.get('username'), data.get('password'), data.get('git_org'), self.repo_name)
def reset_lambda_shell_auth(self): value = {'key' : random_uuid() } return Secrets(self.secret_id).update_to_json_string(value)
def test_delete(self): self.secrets.delete() assert self.secrets.deleted() is True assert Secrets('aaaa').deleted() is False
def setUp(self): self.id = 'an_secret' self.value = 'goes here' self.secrets = Secrets(self.id) if self.secrets.deleted(): self.secrets.undelete()
def resolve_bot_token(self, team_id): if team_id == 'T7F3AUXGV': return Secrets('slack-gs-bot').value() if team_id == 'T0SDK1RA8': return Secrets('slack-gsbot-for-pbx').value()
def test_access_to_aws_secrets(self): secret_name = f'ssh_key_{self.key_name}.pem' assert len(Secrets('').list()) > 0 assert Secrets(secret_name).exists() is True