def get_token(code=None): global client_id global client_secret global redirect_uri if client_id is None: client_id = loft_hvac.read_secret(path='secret/meetup/key') if client_secret is None: client_secret = loft_hvac.read_secret(path='secret/meetup/secret') if redirect_uri is None: redirect_uri = loft_hvac.read_secret(path='secret/meetup/redirect_uri') with requests.Session() as session: parameters = {} parameters['client_id'] = client_id parameters['client_secret'] = client_secret parameters['grant_type'] = 'anonymous_code' parameters['redirect_uri'] = redirect_uri parameters['code'] = code response = session.post(url="https://secure.meetup.com/oauth2/access", params=parameters) return (response.json()['access_token'])
def get_token(code): global client_id global client_secret if client_id is None: client_id = loft_hvac.read_secret(path='meetup', key='client_id') if client_secret is None: client_secret = loft_hvac.read_secret(path='meetup', key='client_secret') with requests.Session() as session: parameters = {} parameters['client_id'] = (client_id or os.environ.get('CLIENT_ID_ENV_NAME')) parameters['client_secret'] = ( client_secret or os.environ.get('CLIENT_SECRET_ENV_NAME')) parameters['grant_type'] = 'anonymous_code' parameters['redirect_uri'] = os.getenv('REDIRECT_URL_ENV_NAME') parameters['code'] = code response = session.post(url="https://secure.meetup.com/oauth2/access", params=parameters) print(response.content, file=sys.stdout) sys.stdout.flush()
def get_token(code=None): global client_id global client_secret global redirect_uri if os.getenv('ENVIRONMENT') == 'dev': provider = 'virtualbox' bucket = None elif os.getenv('ENVIRONMENT') == 'stage': provider = 'aws' bucket = os.getenv('STAGE_AWS_S3_BUCKET') elif os.getenv('ENVIRONMENT') == 'prod': provider = 'aws' bucket = os.getenv('PROD_AWS_S3_BUCKET') if client_id is None: client_id = loft_hvac.read_secret( provider=provider, bucket=bucket, path='secret/meetup/key' ) if client_secret is None: client_secret = loft_hvac.read_secret( provider=provider, bucket=bucket, path='secret/meetup/secret' ) if redirect_uri is None: redirect_uri = loft_hvac.read_secret( provider=provider, bucket=bucket, path='secret/meetup/redirect_uri' ) with requests.Session() as session: parameters = {} parameters['client_id'] = client_id parameters['client_secret'] = client_secret parameters['grant_type'] = 'anonymous_code' parameters['redirect_uri'] = redirect_uri parameters['code'] = code response = session.post( url="https://secure.meetup.com/oauth2/access", params=parameters ) return(response.json()['access_token'])
def auth(): global client_id global redirect_uri if os.getenv('ENVIRONMENT') == 'dev': provider = 'virtualbox' bucket = None elif os.getenv('ENVIRONMENT') == 'stage': provider = 'aws' bucket = os.getenv('STAGE_AWS_S3_BUCKET') elif os.getenv('ENVIRONMENT') == 'prod': provider = 'aws' bucket = os.getenv('PROD_AWS_S3_BUCKET') if client_id is None: client_id = loft_hvac.read_secret( provider=provider, bucket=bucket, path='secret/meetup/key' ) if redirect_uri is None: redirect_uri = loft_hvac.read_secret( provider=provider, bucket=bucket, path='secret/meetup/redirect_uri' ) with requests.Session() as session: parameters = {} parameters['client_id'] = client_id parameters['response_type'] = 'code' parameters['redirect_uri'] = redirect_uri response = session.get( url="https://secure.meetup.com/oauth2/authorize", params=parameters ) return(response.content)
def auth(): global client_id global redirect_uri if client_id is None: client_id = loft_hvac.read_secret(path='secret/meetup/key') if redirect_uri is None: redirect_uri = loft_hvac.read_secret(path='secret/meetup/redirect_uri') with requests.Session() as session: parameters = {} parameters['client_id'] = client_id parameters['response_type'] = 'code' parameters['redirect_uri'] = redirect_uri response = session.get( url="https://secure.meetup.com/oauth2/authorize", params=parameters) return (response.content)
def getEvents(status): try: client = meetup.api.Client(loft_hvac.read_secret(apikey='Meetup')) events = client.GetEvents({ 'group_urlname': 'DevOps-Loft', 'status': status }) events = json.dumps(events.__dict__) events = json.loads(events) return events except meetup.exceptions.HttpUnauthorized as e: print("Failed connecting to Meetup. Error: {0}".format(e)) return None
def putSlack(channel='sandbox', message='Hello World', event=None): try: sc = Slacker(loft_hvac.read_secret(path='secret/slack/apikey')) response = sc.chat.post_message(channel=channel, text=message, unfurl_links=True) if response.body['ok']: print('success') else: print("Failed publishing to slack. Error: {0}".format( response['error'])) except Exception as e: print(e)
def auth(): global client_id if client_id is None: client_id = loft_hvac.read_secret(path='meetup', key='client_id') with requests.Session() as session: parameters = {} parameters['client_id'] = (client_id or os.environ.get('CLIENT_ID_ENV_NAME')) parameters['response_type'] = 'code' parameters['redirect_uri'] = os.getenv('REDIRECT_URL_ENV_NAME') response = session.get( url="https://secure.meetup.com/oauth2/authorize", params=parameters) return (response.content)