Ejemplo n.º 1
0
def get_client(instance: LookerInstance):
    base_url = f'https://{instance.name}:19999/api/3.0'
    logger.info(f'base_url: {base_url}')
    logger.info(f'client_id: {instance.client_id}')
    logger.info(f'client_secret: {instance.client_secret}')

    # instantiate Auth API
    unauthenticated_client = looker.ApiClient(base_url)
    unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)

    # TODO: Catch situation where default instance key is updated .. but isn't updated in the Admin UI
    # authenticate client
    try:
        token = unauthenticated_authApi.login(
            client_id=instance.client_id, client_secret=instance.client_secret)
    except Exception as e:
        logger.error('get_client() failed to get token', exc_info=True)
        return None

    try:
        client = looker.ApiClient(base_url,
                                  header_name='Authorization',
                                  header_value='token ' + token.access_token)
    except Exception as e:
        logger.error('get_client() failed to authenticate with token',
                     exc_info=True)
        return None

    logger.info(f'client: {client}')

    return client
Ejemplo n.º 2
0
def usr_gen():
    if request.method == 'POST':
        data = request.get_json()
        # I have zapier parse out the fields I want and send them pre-named
        firstname = data['name'].split(' ', 1)[0]
        lastname = data['name'].split(' ', 1)[1]
        email = data['email']

        # API creation process
        base_url = 'https://your.looker.com:19999/api/3.0/'
        #secrets are stored in environment variables
        client_id = os.environ['apikey']
        client_secret = os.environ['apisecret']

        unauthenticated_client = looker.ApiClient(base_url)
        unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)
        token = unauthenticated_authApi.login(client_id=client_id,
                                              client_secret=client_secret)
        client = looker.ApiClient(base_url, 'Authorization',
                                  'token ' + token.access_token)

        #User Creation Process
        user_id = create_user(client, firstname, lastname, email)
        apply_role(client, user_id, role_id)
        # If you want to add user attributes, add the user to groups, etc
        # you'll probably want to add another function here
        reset_url = get_email_setup(client, user_id)
        send_mail(reset_url, email)

        #Email send
        print('User Created')
        return '', 200
    else:
        abort(400)
Ejemplo n.º 3
0
 def login(self):
     # authenticate client
     self.unauthenticated_client = looker.ApiClient(self.base_url)
     self.unauthenticated_authApi = looker.ApiAuthApi(
         self.unauthenticated_client)
     self.token = self.unauthenticated_authApi.login(
         client_id=self.client_id, client_secret=self.client_secret)
     self.client = looker.ApiClient(self.base_url, 'Authorization',
                                    'token ' + self.token.access_token)
Ejemplo n.º 4
0
 def __init__(self, base_url, client_id, client_secret):
     self.base_url = base_url
     self.client_id = client_id
     self.client_secret = client_secret
     self.unauthenticated_client = looker.ApiClient(base_url)
     self.unauthenticated_authApi = looker.ApiAuthApi(
         unauthenticated_client)
     self.token = None
     self.client = None
     self.api = None
Ejemplo n.º 5
0
def _get_look_from_looker(look_number):
    """ Return the result of executing the look """
    unauthenticated_client = looker.ApiClient(LOOKER_BASE_URL)
    unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)
    token = unauthenticated_authApi.login(client_id=LOOKER_CLIENT_ID,
                                          client_secret=LOOKER_CLIENT_SECRET)
    client = looker.ApiClient(LOOKER_BASE_URL, "Authorization",
                              "token " + token.access_token)
    lookApi = looker.LookApi(client)
    return lookApi.run_look(look_number, "csv")
Ejemplo n.º 6
0
 def auth(self):
     print("--->Autenticating against Looker Server...")
     unauthenticated_client = looker.ApiClient(self.host)
     unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)
     try:
         token = unauthenticated_authApi.login(client_id=self.token,
                                               client_secret=self.secret)
         lClient = looker.ApiClient(self.host, 'Authorization',
                                    'token ' + token.access_token)
         print("--->CLIENT:{0}".format(lClient))
         userApi = looker.UserApi(lClient)
         me = userApi.me()
         self.client = lClient
         print("--->WELCOME {0}!".format(me.display_name))
     except:
         print("!--->Auth error")
def authenticate_to_looker(host_base_url, token, secret) -> object:
    """Run Looker authentication and obtain client.

    :param host_base_url: String representing the URL for given Looker instance with the port and API version. For
     example - https://devdealerware.looker.com:19999/api/3.0
    :param token: Looker API user client ID
    :param secret: API user client secret.
    :return: Looker API client for given Looker instance.
    """
    unauthenticated_client = lookerapi.ApiClient(host_base_url)
    unauthenticated_auth_api = lookerapi.ApiAuthApi(unauthenticated_client)
    token = unauthenticated_auth_api.login(client_id=token,
                                           client_secret=secret)
    client = lookerapi.ApiClient(host_base_url, 'Authorization',
                                 'token ' + token.access_token)

    return client
Ejemplo n.º 8
0
def looker_connection(base_url, client_id, client_secret):
    """
    Execute query on Athena.
    :param base_url: URL for looker.
    :param client_id: API3 client id for looker.
    :param client_secret: API3 client secret for looker.
    """
    try:
        # instantiate Auth API
        unauthenticated_client = lookerapi.ApiClient(base_url)
        unauthenticated_authapi = lookerapi.ApiAuthApi(unauthenticated_client)

        # authenticate client
        token = unauthenticated_authapi.login(client_id=client_id,
                                              client_secret=client_secret)
        client = lookerapi.ApiClient(base_url, 'Authorization',
                                     'token ' + token.access_token)

        # instantiate Look API
        looks = lookerapi.LookApi(client)
        return looks
    except Exception as e:
        print("There is some issue with the API3 credentials. " + str(e))
Ejemplo n.º 9
0
import time
import make_airline_dashboard
from lookerapi.rest import ApiException
import lookerapi as looker
import config

# replace with your custom Looker API Host domain and port, if applicable.
base_url = 'https://hack.looker.com:19999/api/3.0/'
#Looker admins can create API3 credentials on Looker's **Admin/Users** page

# instantiate Auth API
unauthenticated_client = looker.ApiClient(base_url)
unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)

# authenticate client
token = unauthenticated_authApi.login(client_id=config.client_id, client_secret=config.client_secret)
client = looker.ApiClient(base_url, 'Authorization', 'token ' + token.access_token)

# instantiate Look API client
queryAPI = looker.QueryApi(client)

# Retreive all airlines (or customers, or users, etc)
# Edit here:
body = {
  "model":"faa_redshift",
  "view":"flights",
  "fields":["carriers.name"],
  "limit":"500",
}

resp = queryAPI.run_inline_query("json",body)