Skip to content

Ulauncher/ext-api.ulauncher.io

Repository files navigation

This API server is written in Python using bottle, boto3 libraries

Code Contribution

Any code contributions are welcomed as long as they are discussed in Github Issues with maintainers. Be aware that if you decided to change something and submit a PR on your own, it may not be accepted.

Setup Development Environment

  1. Sign up for auth0.com account and create an application (see instructions below)
  2. Sign up for AWS account and create a user with limited access (see below)
  3. Create .env.local file
    AUTH0_DOMAIN=<yourdomain>.auth0.com
    AUTH0_CLIENT_ID=<id>
    AUTH0_CLIENT_SECRET=<secret>
    
    GUNICORN_THREADS=1
    
    EXTENSIONS_TABLE_NAME=extensions
    EXT_IMAGES_BUCKET_NAME=<bucket-name>
    MONGODB_CONNECTION=mongodb://mongodb:27017
    DB_NAME=ulauncher
    LOG_LEVEL=10
    
    AWS_ACCESS_KEY_ID=<id>
    AWS_SECRET_ACCESS_KEY=<key>
    AWS_DEFAULT_REGION=us-east-1
    
  4. docker network create webproxy
  5. docker-compose pull (run this if you ran docker-compose up more than a day ago)
  6. docker-compose up -d
  7. docker exec -it ext-api bash
  8. ./app.py init_db
  9. ./app.py run_server
  10. Open http://localhost:8080/api-doc.html to see API docs
  11. Open http://localhost:3000, log in with your Github user and try adding an extension to make sure everything works fine

In order to access Mongodb run docker exec -it ext-mongodb mongo ulauncher

How to Create Auth0 Application

  1. After you sign up for auth0 account, click large button Create Application
  2. Choose a name (e.g. ulauncher ext-api)
  3. Choose Single Page Web App as an application type
  4. Go to app settings and copy client ID, domain, and client secret to .env file
  5. Set Allowed Callback URLs to http://localhost:3000/auth0-callback
  6. In the left sidebar menu select Connections -> Social
  7. Click on Github and turn it on
  8. In the Popup window switch to Applications tab and enable Github connection for your application

How to Create And Configure an AWS User

  1. Choose IAM in Services menu
  2. Go to Users and click Add User
  3. Pick a username (example: ext-api-developer) and check "Programmatic access"
  4. On the next step choose the last tab: Attach existing policies directly
  5. Select "AmazonS3FullAccess" or set more restrictive permissions later by using IAM policy described below
  6. Skip Tags step
  7. Click create and copy Secret Access Key. You won't be able to see it again, so make sure to save it safely
  8. Navigate to S3 service and create a bucket (example: ext-api-images)
  9. Save the bucket name to EXT_IMAGES_BUCKET_NAME variable in .env file
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1556983150000",
            "Effect": "Allow",
            "Action": [
                "s3:DeleteObject",
                "s3:DeleteObjectTagging",
                "s3:DeleteObjectVersion",
                "s3:DeleteObjectVersionTagging",
                "s3:GetAccelerateConfiguration",
                "s3:GetAnalyticsConfiguration",
                "s3:GetBucketAcl",
                "s3:GetBucketCORS",
                "s3:GetBucketLocation",
                "s3:GetBucketLogging",
                "s3:GetBucketNotification",
                "s3:GetBucketPolicy",
                "s3:GetBucketRequestPayment",
                "s3:GetBucketTagging",
                "s3:GetBucketVersioning",
                "s3:GetBucketWebsite",
                "s3:GetInventoryConfiguration",
                "s3:GetIpConfiguration",
                "s3:GetLifecycleConfiguration",
                "s3:GetMetricsConfiguration",
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:GetObjectTagging",
                "s3:GetObjectVersion",
                "s3:GetObjectVersionAcl",
                "s3:HeadBucket",
                "s3:ListBucket",
                "s3:ListObjects",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::your-bucket-name-goes-here",
                "arn:aws:s3:::your-bucket-name-goes-here/*"
            ]
        }
    ]
}