Skip to content

Instantly share code, notes, and snippets.

@rakodev
rakodev / aws-credentials.sh
Last active June 8, 2022 09:59
Export AWS credentials from AWS SSO
#!/bin/bash
# use another role-name if needed
role_credentials=$(aws sso get-role-credentials --role-name=AdministratorAccess --account-id=$(aws sts get-caller-identity --query "Account" --output text) --access-token=$(jq .accessToken ~/.aws/sso/cache/$(ls -1rt ~/.aws/sso/cache | tail -n1) | sed -r 's/^"|"$//g') | jq -r '.roleCredentials')
export AWS_ACCESS_KEY_ID="$(echo $role_credentials | jq -r '.accessKeyId')"
export AWS_SECRET_ACCESS_KEY="$(echo $role_credentials | jq -r '.secretAccessKey')"
export AWS_SESSION_TOKEN="$(echo $role_credentials | jq -r '.sessionToken')"
@rakodev
rakodev / api.tf
Created October 19, 2021 09:33
Give ReadOnlyAccess to this account to another AWS account. Replace <ACCOUNT_ID> by the AWS account ID you want to give access.
data "aws_iam_policy_document" "instance_assume_role_policy" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "AWS"
identifiers = ["<ACCOUNT_ID>"]
}
}
}
@rakodev
rakodev / iam.tf
Last active October 19, 2021 09:33
Give your deployment enough permission to deploy an AWS SAM application. <ACCOUNT_ID> has to be changed with the aws account ID that host the ci runners.
resource "aws_iam_role" "aws_sam_api_deployment_role" {
name = "aws-sam-api-deployment-role"
assume_role_policy = data.aws_iam_policy_document.deployment_role.json
tags = local.tags
}
data "aws_iam_policy_document" "deployment_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
@rakodev
rakodev / docker-mysql-backup.sh
Created May 12, 2020 12:49 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@rakodev
rakodev / component-template.js
Last active October 6, 2019 12:05
New react native component template
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
const ComponentName = props => {
return (
<View>
</View>
);
};
<?php
namespace App\ApiPlatform;
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
class AutoGroupResourceMetadataFactory implements ResourceMetadataFactoryInterface
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Carbon\Carbon;
use Doctrine\Common\Collections\ArrayCollection;
<?php
namespace App\Serializer\Normalizer;
use App\Entity\User;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class UserNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
@rakodev
rakodev / symfony.lock
Created August 27, 2019 20:00
API Platform temp file
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "d70bf592518f042992850c6f6dffdcfb",
"packages": [
{
"name": "api-platform/api-pack",
@rakodev
rakodev / xdebug-on-off.sh
Last active August 2, 2019 11:21
Enable or Disable xdebug with php-fpm
#!/usr/bin/env bash
phpVersion=7.3
if [[ "$1" == "status" ]]; then
if [[ -e /etc/php/${phpVersion}/fpm/conf.d/20-xdebug.ini ]]; then
echo "Xdebug is Enabled";
else
echo "Xdebug is Disabled";
fi