Esempio n. 1
0
func CreateAdminTable() {
	var svc *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()

	params := &dynamodb.CreateTableInput{
		AttributeDefinitions: []*dynamodb.AttributeDefinition{
			{
				AttributeName: aws.String("AdminID"),
				AttributeType: aws.String("S"),
			},
		},
		KeySchema: []*dynamodb.KeySchemaElement{
			{
				AttributeName: aws.String("AdminID"),
				KeyType:       aws.String("HASH"),
			},
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
			ReadCapacityUnits:  aws.Int64(1),
			WriteCapacityUnits: aws.Int64(1),
		},
		TableName: aws.String(AdminTableName),
	}

	resp, err := svc.CreateTable(params)
	if err != nil {
		log.Fatal(err)
	}

	log.Info(resp)
}
Esempio n. 2
0
func CreateAppTable() {
	var svc *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()

	params := &dynamodb.CreateTableInput{
		AttributeDefinitions: []*dynamodb.AttributeDefinition{
			{
				AttributeName: aws.String("ClientID"),
				AttributeType: aws.String("S"),
			},
			{
				AttributeName: aws.String("DeveloperEmail"),
				AttributeType: aws.String("S"),
			},
		},
		KeySchema: []*dynamodb.KeySchemaElement{
			{
				AttributeName: aws.String("ClientID"),
				KeyType:       aws.String("HASH"),
			},
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
			ReadCapacityUnits:  aws.Int64(1),
			WriteCapacityUnits: aws.Int64(1),
		},
		TableName: aws.String(ApplicationTableName),
		GlobalSecondaryIndexes: []*dynamodb.GlobalSecondaryIndex{
			{ // Required
				IndexName: aws.String("EMail-Index"),
				KeySchema: []*dynamodb.KeySchemaElement{
					{ // Required
						AttributeName: aws.String("DeveloperEmail"),
						KeyType:       aws.String("HASH"),
					},
					// More values...
				},
				Projection: &dynamodb.Projection{
					ProjectionType: aws.String("ALL"),
				},
				ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
					ReadCapacityUnits:  aws.Int64(1),
					WriteCapacityUnits: aws.Int64(1),
				},
			},
		},
	}

	resp, err := svc.CreateTable(params)
	if err != nil {
		log.Fatal(err)
	}

	log.Info(resp)
}
Esempio n. 3
0
func handleList() {
	var client *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()
	params := &dynamodb.ScanInput{
		TableName: aws.String(ddl.AdminTableName),
		AttributesToGet: []*string{
			aws.String("AdminID"),
		},
	}

	resp, err := client.Scan(params)

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(resp)
}
Esempio n. 4
0
func handleRemove(subject string) {
	fmt.Println("Remove admin", subject)

	var client *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()
	params := &dynamodb.DeleteItemInput{
		TableName: aws.String(ddl.AdminTableName),
		Key: map[string]*dynamodb.AttributeValue{
			"AdminID": {S: aws.String(subject)},
		},
	}

	_, err := client.DeleteItem(params)

	if err != nil {
		fmt.Println(err.Error())
		return
	}
}
Esempio n. 5
0
func handleAdd(subject string) {
	fmt.Println("Add admin", subject)

	var client *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()
	params := &dynamodb.PutItemInput{
		TableName: aws.String(ddl.AdminTableName),
		Item: map[string]*dynamodb.AttributeValue{
			"AdminID": {S: aws.String(subject)},
		},
		Expected: map[string]*dynamodb.ExpectedAttributeValue{
			"AdminID": {Exists: aws.Bool(false)},
		},
	}
	_, err := client.PutItem(params)

	if err != nil {
		fmt.Println(err.Error())
		return
	}
}
Esempio n. 6
0
func DeleteTable(tableName string) {

	localAddr := os.Getenv("LOCAL_DYNAMO_ADDR")
	if localAddr == "" {
		log.Info("DeleteAppTable will only attempt to delete a local dynamodb table... returning.")
		return
	}

	var svc *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()

	params := &dynamodb.DeleteTableInput{
		TableName: aws.String(tableName),
	}
	resp, err := svc.DeleteTable(params)

	if err != nil {
		log.Info(err.Error())
		return
	}

	log.Printf("Table %s deleted:\n%s\n", tableName, resp.String())
}
Esempio n. 7
0
//NewDynamoAdminRepo returns a new instance of type DynamoAppRepo
func NewDynamoAdminRepo() *DynamoAdminRepo {
	return &DynamoAdminRepo{
		client: dbutil.CreateDynamoDBClient(),
	}
}