Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8bb3382
chore(android-build) Updates for eventual automation of amplify-andro…
rjuliano Nov 3, 2020
8c0a00c
Remove reference to at_auth* stack
rjuliano Nov 3, 2020
237faa8
Rename datastore tests
rjuliano Dec 14, 2020
6765c16
Make api key default auth mode
rjuliano Dec 14, 2020
18a0651
Fix dictionary
rjuliano Dec 14, 2020
513fdbd
Renamed projects and stacks
rjuliano Dec 14, 2020
af1e33e
Add forcePush
rjuliano Dec 14, 2020
6daf87b
Remove --codegen from push command
rjuliano Dec 14, 2020
abc782a
Add codegen option
rjuliano Dec 23, 2020
b9ccfe3
Add conflict detection option and push between auth and api
rjuliano Dec 28, 2020
0837ec4
Change variable name
rjuliano Dec 29, 2020
5a17034
Adding schemas for API tests
rjuliano Dec 30, 2020
ebaaafb
Renamed schema files
rjuliano Dec 30, 2020
c81bb18
Tweak to the events API schema
rjuliano Dec 31, 2020
6916b19
Merge branch 'main' into rjuliano/amplify-integ-test-backend
rjuliano Jan 5, 2021
c4ebbd2
Set expiration time for test keys
rjuliano Jan 6, 2021
a457a28
Updating READMEs
rjuliano Jan 6, 2021
0cdd502
Cleaned up warnings
rjuliano Jan 6, 2021
7aad6ba
Cleanup unused code and setup artifact buckets
rjuliano Jan 29, 2021
536ca37
Merge branch 'main' into rjuliano/amplify-integ-test-backend
rjuliano Apr 30, 2021
2e6597b
Adding schemas and changes for multiauth
rjuliano May 12, 2021
22e3c01
Adding createdAt field to datastore schema
rjuliano May 20, 2021
5421bc4
pin old version of cli for now
rjuliano May 20, 2021
699b872
chore: add oidc config to api
rjuliano Jun 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "."))
45 changes: 32 additions & 13 deletions src/integ_test_resources/android/amplify/integration/cdk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,52 @@
from aws_cdk import core
from stacks.amplify_deployer_stack import AmplifyDeployer

def build_amplify_deployer_stack_props(cb_project_name: str,
github_repo: str,
github_owner: str,
branch: str,
shell_script_name: str):
props = {}
props['cb_project_name'] = cb_project_name
props['shell_script_name'] = shell_script_name
props['github_repo'] = github_repo
if github_owner is not None:
props['github_owner'] = github_owner
if branch is not None:
props['branch'] = branch
return props

app = core.App()
github_owner=app.node.try_get_context("github_owner")
branch=app.node.try_get_context("branch")

TARGET_REGION = app.node.try_get_context("region")
TARGET_ACCOUNT = app.node.try_get_context("account")
if TARGET_ACCOUNT is None or TARGET_REGION is None:
raise Exception("Context variables region and account are required.")

TARGET_ENV = core.Environment( account=TARGET_ACCOUNT, region=TARGET_REGION)
GITHUB_REPO = 'amplify-ci-support'

BANNER_TEXT = f"AWS Account={TARGET_ACCOUNT} Region={TARGET_REGION}"
SEPARATOR = "-" * len(BANNER_TEXT)

github_owner=app.node.try_get_context("github_owner")
branch=app.node.try_get_context("branch")

print(SEPARATOR)
print(BANNER_TEXT)
print(SEPARATOR)

props = {}
props['project_name'] = "AmplifyAndroidIntegTestDeployer"
props['github_repo'] = GITHUB_REPO
if github_owner is not None:
props['github_owner'] = github_owner
if branch is not None:
props['branch'] = branch
datastore_instrumented_test_props = build_amplify_deployer_stack_props(cb_project_name="DataStoreTestsBackendDeployer",
github_repo=GITHUB_REPO,
github_owner=github_owner,
branch=branch,
shell_script_name="deploy_datastore_tests_backend.sh")

api_instrumented_test_props = build_amplify_deployer_stack_props(cb_project_name="ApiTestsBackendDeployer",
github_repo=GITHUB_REPO,
github_owner=github_owner,
branch=branch,
shell_script_name="deploy_api_tests_backend.sh")

AmplifyDeployer(app, "AndroidIntegTestInfraDeployer", props, env=TARGET_ENV)
instrumented_test_backend_stack = AmplifyDeployer(app, "DataStoreTestsBackendDeployer", datastore_instrumented_test_props, env=TARGET_ENV)
api_instrumented_test_backend_stack = AmplifyDeployer(app, "ApiTestsBackendDeployer", api_instrumented_test_props, env=TARGET_ENV)

app.synth()
app.synth()

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
type Blog @model {
id: ID!
name: String!
tags: [String]
posts: [Post] @connection(name: "BlogPosts")
}

type Rating @model {
id: ID!
stars: Int!
post: Post! @connection(name: "PostRating")
}

type Post @model {
id: ID!
title: String!
blog: Blog! @connection(name: "BlogPosts")
rating: Rating @connection(name: "PostRating")
editors: [PostEditor] @connection(keyName: "byPost", fields: ["id"])
}

# Create a join model and disable queries as you don't need them
# and can query through Post.editors and User.posts
type PostEditor
@model(queries: null)
@key(name: "byPost", fields: ["postID", "editorID"])
@key(name: "byEditor", fields: ["editorID", "postID"]) {
id: ID!
postID: ID!
editorID: ID!
post: Post! @connection(fields: ["postID"])
editor: User! @connection(fields: ["editorID"])
}

type User @model {
id: ID!
username: String!
posts: [PostEditor] @connection(keyName: "byEditor", fields: ["id"])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type Event @model {
id: ID!
name: String!
where: String!
when: String!
description: String
comments: [Comment] @connection(name: "EventComments")
}

type Comment @model {
id: ID!
eventId: String!
content: String!
createdAt: AWSTimestamp!
event: Event @connection(name: "EventComments")
}

type Subscription {
subscribeToEventComments(eventId: String!): Comment @aws_subscribe(mutations: ["createComment"])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type Person @model {
id: ID!
first_name: String!
last_name: String!
age: Int
dob: AWSDate
relationship: MaritalStatus
}

enum MaritalStatus {
single
engaged
married
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type Projectfields @model {
id: ID!
name: String
teamID: ID!
team: Team @connection(fields: ["teamID"])
}

type Team @model {
id: ID!
name: String!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
type Blog @model {
id: ID!
name: String!
posts: [Post] @connection(name: "BlogPosts")
owner: BlogOwner! @connection(name: "BlogOwner")
}

type BlogOwner @model {
name: String!
id: ID!
blog: Blog @connection(name: "BlogOwner")
wea: String
}

enum PostStatus {
ACTIVE
INACTIVE
}

type Post @model {
id: ID!
title: String!
blog: Blog @connection(name: "BlogPosts")
comments: [Comment] @connection(name: "PostComments")
authors: [PostAuthorJoin] @connection(keyName: "byPost", fields: ["id"])
status: PostStatus!
rating: Int!
}

type Comment @model {
id: ID!
content: String
post: Post @connection(name: "PostComments")
}

type Author @model {
id: ID!
name: String!
posts: [PostAuthorJoin] @connection(keyName: "byAuthor", fields: ["id"])
}

type PostAuthorJoin
@model
@key(name: "byAuthor", fields: ["authorId"])
@key(name: "byPost", fields: ["postId"]) {
id: ID!
authorId: ID!
postId: ID!
author: Author @connection(fields: ["authorId"])
post: Post @connection(fields: ["postId"])
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import json
import os
from common import (
LOGGER,
AMPLIFY_AWSSDK_CLIENT,
BASE_PATH,
run_command,
OperationType
)
from auth import *

AMPLIFY_COMMAND = "amplify"
AMPLIFY_ACTION_PULL = "pull"
AMPLIFY_ACTION_INIT = "init"
AMPLIFY_ENVIRONMENT = "main" # Static for now

AMPLIFY_PROVIDER_CONFIG = {
'awscloudformation': {
'configLevel': 'general',
'region': 'us-east-1'
}
}

AMPLIFY_FRONTEND_CONFIG = {
'frontend': 'android',
'config' : {
'ResDir': f"app/src/main/res"
}
}

AMPLIFY_CODEGEN_CONFIG_ANDROID = {
'generateCode': True,
'codeLanguage': 'java',
'generateDocs': True
}

class AmplifyApp:
backend_name = None
app_id = None
project_dir = None
amplify_meta_content = None

def __init__(self, *, backend_name:str):
self.backend_name = backend_name
self.project_dir = f"{BASE_PATH}/_amplify_{self.backend_name}"
os.system(f"mkdir -p {self.project_dir}")
self.app_id = self._get_existing_app_id()
if self.app_id is None and self._initialize_new_app() != 0:
raise Exception("Unable to initialize Amplify project.")
else:
self._pull_existing_app()
with open(f"{self.project_dir}/amplify/backend/amplify-meta.json") as amplify_meta_file:
self.amplify_meta_content = json.load(amplify_meta_file)
self._load_metadata()

def is_category_configured(self, category_name:str):
if self.amplify_meta_content is None:
return False
return category_name in self.amplify_meta_content.keys()

def config_auth(self, auth_config, op_type:OperationType):
cmd = [AMPLIFY_COMMAND,
op_type.value,
"auth",
"--headless"]
result = run_command(cmd, work_dir=self.project_dir, input=json.dumps(auth_config))
return result.returncode

def config_api(self, api_config, op_type:OperationType):
cmd = [AMPLIFY_COMMAND,
op_type.value,
"api",
"--headless"]
result = run_command(cmd, work_dir=self.project_dir, input=json.dumps(api_config))
return result.returncode

def get_category_config(self, category_name: str):
if self.amplify_meta_content is None:
return None
return category_name in self.amplify_meta_content.keys()

def push(self):
push_cmd = [AMPLIFY_COMMAND,
"push",
"--codegen", json.dumps(AMPLIFY_CODEGEN_CONFIG_ANDROID),
"--yes"]
result = run_command(push_cmd, self.project_dir)
self._load_metadata()
return result.returncode

def _get_existing_app_id(self):
try:
response = AMPLIFY_AWSSDK_CLIENT.list_apps()
existing_app_id = next(app['appId'] for app in response['apps'] if app['name'] == self.backend_name)
return existing_app_id
except StopIteration:
LOGGER.error(f"Unable to find existing Amplify app for {self.backend_name}")
return None

def _initialize_new_app(self):
init_cmd = [AMPLIFY_COMMAND,
AMPLIFY_ACTION_INIT,
"--amplify", json.dumps(self._get_amplify_config()),
"--providers", json.dumps(AMPLIFY_PROVIDER_CONFIG),
"--frontend", json.dumps(AMPLIFY_FRONTEND_CONFIG),
"--forcePush",
"--yes"]
result = run_command(init_cmd, self.project_dir)
self.app_id = self._get_existing_app_id()
return result.returncode


def _pull_existing_app(self):
amplify_params = self._get_amplify_config().copy()
amplify_params.update({'appId': self.app_id})
pull_cmd = [AMPLIFY_COMMAND,
AMPLIFY_ACTION_PULL,
"--amplify", json.dumps(amplify_params),
"--providers", json.dumps(AMPLIFY_PROVIDER_CONFIG),
"--frontend", json.dumps(AMPLIFY_FRONTEND_CONFIG),
"--yes"]
result = run_command(pull_cmd, self.project_dir)
return result.returncode

def _get_amplify_config(self):
return {
'projectName': self.backend_name,
'envName': AMPLIFY_ENVIRONMENT,
'defaultEditor': 'code'
}

def _load_metadata(self):
with open(f"{self.project_dir}/amplify/backend/amplify-meta.json") as amplify_meta_file:
self.amplify_meta_content = json.load(amplify_meta_file)
Loading