Enterprise Framework

Software Solutions in the Enterprise

ElasticSearch 5.6 Template To Apply Dynamic Template Mapping or Properties to Any Index and Type

Problem:  Have an ElasticSearch Dynamic Template that will apply Templates and/or new properties to any new Index or Type created.  

Anytime an Index is created with a new type it should

  • Have a default DynamicTemplate
  • Add the properties "timestamp" and "creation_date". 

First use the following resources:

https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html

https://www.elastic.co/guide/en/elasticsearch/reference/current/default-mapping.html

That only gets you part way.  

Solution:

This was not easy to find, But what you will need to is set (Examples below):

  • "index_patterns": ["*"]  /* this will match all indexes created */
  • "mappings"."{type}".  This should be set to "_default_"

Note: this does not effect existing Templates.

PUT _template/template_1

{ 
    "index_patterns": ["*"],
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    },
    "mappings": {
        "_default_": {
            "_source": {
                "enabled": true
            },
            "dynamic_templates": [
                {
                    "id_integers": {
                        "match": "*_id",
                        "match_mapping_type": "long",
                        "mapping": {
                            "type": "long"
                        }
                    }
                },
                {
                    "date_fields": {
                        "match": "*_date",
                        "match_mapping_type": "date",
                        "mapping": {
                            "type": "date"
                        }
                    }
                },
                {
                    "json_fields": {
                        "match": "*_json",
                        "match_mapping_type": "*",
                        "mapping": {
                            "type": "text"
                        }
                    }
                },
                {
                    "int_template": {
                        "match": "_*",
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                }                
            ],
            "properties": {
                "creation_date": {
                    "type": "date",
                    "format": "yyyy-MM-dd"
                },              
                "timestamp": {
                    "type": "date",
                    "format": "epoch_millis"
                }
            }
        }
    }
}

Test:  POST /school/student/1

{ 
  "title": "The quick brown fox", 
  "price": 5, 
  "colors": ["red","green","blue"],
  "do_something":"hello world"
}

Validation:  POST /school/student/_mapping

{
  "school": {
    "mappings": {
      "student": {
        "dynamic_templates": [
          {
            "id_integers": {
              "match": "*_id",
              "match_mapping_type": "long",
              "mapping": {
                "type": "long"
              }
            }
          },
          {
            "date_fields": {
              "match": "*_date",
              "match_mapping_type": "date",
              "mapping": {
                "type": "date"
              }
            }
          },
          {
            "json_fields": {
              "match": "*_json",
              "mapping": {
                "type": "text"
              }
            }
          },
          {
            "int_template": {
              "match": "_*",
              "match_mapping_type": "string",
              "mapping": {
                "type": "keyword"
              }
            }
          }
        ],
        "properties": {
          "creation_date": {
            "type": "date",
            "format": "yyyy-MM-dd"
          },
          "timestamp": {
            "type": "date",
            "format": "epoch_millis"
          }
        }
      }
    }
  }
}

Mac Sierra - Amazon AWS CLI Easy Installer and Setup

http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-bundle.html

    Switch to the download folder

    $ cd ~/Downloads

    Download the AWS CLI Bundled Installer.

    $ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"

    Unzip the package.

    $ unzip awscli-bundle.zip

    Note

    If you don't have unzip, use your Linux distribution's built in package manager to install it.

    Run the install executable.

    $ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

    Note

    By default, the install script runs under the system default version of Python. If you have installed an alternative version of Python and want to use that to install the AWS CLI, run the install script with that version by absolute path to the Python executable. For example:

    $ sudo /usr/local/bin/python2.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

After you install, you must configure it.  

    $ aws configure

    AWS Access Key ID [None]: {PASTE YOUR ACCESS KEY ID IN}

    AWS Secret Access Key [None]: {PASTE YOUR SECRET ACCESS KEY IN}

    Default region name [None]: us-east-1

    Default output format [None]:  

Your CLI should be configured:

    $ aws s3 ls

Node.js - HTTP with Error, Done, Data, End, Timeout example


var https = require('https');
var querystring = require('querystring');
var postData = { data : "something" };
var options = {
hostname: 'www.yourdomain.com',
path: '/api/book',
method: 'POST',
headers: {
"Content-Type": "application/json",
"Content-Length": postData.length
}
};

var req = https.request(options, function (res) {
res.setEncoding('utf8');

res.on('data', function (chunk) {
console.log("[RESPONSE DATA]", chunk);
});

res.on('end', function (data) {

if (res.statusCode >= 200 && res.statusCode < 300) {
console.log("[SUCCESS]");
} else {
console.log("[HTTP RESPONSE STATUS CODE ERROR]", res.statusCode);
console.log("[HTTP RESPONSE STATUS MESSAGE ERROR]", res.statusMessage);
}
});
});
req.setNoDelay(true);
req.setTimeout(28000, function(e) {
console.log("Timeout Fired at 29000 ms");
});

req.on('error', function (e) {
console.log("[FORWARD ERROR]", e);

if (e.statusCode === "ECONNRESET") {
console.log("Timeout received");
}
});

req.write(postData);
req.end();

Lambda Node.js Callback

http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html


Using the Callback Parameter

The Node.js runtimes v4.3 and v6.10 support the optional callback parameter. You can use it to explicitly return information back to the caller. The general syntax is:

callback(Error error, Object result);



Where:

  • error – is an optional parameter that you can use to provide results of the failed Lambda function execution. When a Lambda function succeeds, you can pass null as the first parameter.

  • result – is an optional parameter that you can use to provide the result of a successful function execution. The result provided must be JSON.stringify compatible. If an error is provided, this parameter is ignored.

Note

Using the callback parameter is optional. If you don't use the optional callback parameter, the behavior is same as if you called the callback() without any parameters. You can specify the callback in your code to return information to the caller.

AWS Gateway Resource Expression Format

http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html

The API-executing Resource expression has the following general format:

where:

  • region is the AWS region (such as us-east-1 or * for all AWS regions) that corresponds to the deployed API for the method.

  • account-id is the 12-digit AWS account Id of the REST API owner.

  • api-id is the identifier API Gateway has assigned to the API for the method. (* can be used for all APIs, regardless of the API's identifier.)

  • stage-name is the name of the stage associated with the method (* can be used for all stages, regardless of the stage's name.)

  • HTTP-VERB is the HTTP verb for the method. It can be one of the following: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.

  • resource-path-specifier is the path to the desired method. (* can be used for all paths).

Some example resource expressions include:

  • arn:aws:execute-api:*:*:* for any resource path in any stage, for any API in any AWS region. (This is equivalent to *).

  • arn:aws:execute-api:us-east-1:*:* for any resource path in any stage, for any API in the AWS region of us-east-1.

  • arn:aws:execute-api:us-east-1:*:api-id/* for any resource path in any stage, for the API with the identifier of api-id in the AWS region of us-east-1.

  • arn:aws:execute-api:us-east-1:*:api-id/test/* for resource path in the stage of test, for the API with the identifier of api-id in the AWS region of us-east-1.

  • arn:aws:execute-api:us-east-1:*:api-id/test/*/mydemoresource/* for any resource path along the path of mydemoresource, for any HTTP method in the stage of test, for the API with the identifier of api-id in the AWS region of us-east-1.

  • arn:aws:execute-api:us-east-1:*:api-id/test/GET/mydemoresource/* for GET methods under any resource path along the path of mydemoresource, in the stage of test, for the API with the identifier of api-id in the AWS region of us-east-1.


Virtual Box - Resize VMDK by Changing Type To VDI and Converting Back to VMDK

 Found a great article on stack overflow for increasing Virtual Box VMDK Storage Size.  It's by converting to another type VDI  and then converting back to VMDK


VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifyhd "cloned.vdi" --resize 51200
VBoxManage clonehd "cloned.vdi" "resized.vmdk" --format vmdk


Stripe Events Switch Statement


switch ($event)

{

    case "account.updated": //describes an account, Occurs whenever an account status or property has changed.

    case "account.application.deauthorized": //describes an application, Occurs whenever a user deauthorizes an application. Sent to the related application only., child parameters

    case "account.external_account.created": //describes an external account (e.g., card or bank account), Occurs whenever an external account is created.

    case "account.external_account.deleted": //describes an external account (e.g., card or bank account), Occurs whenever an external account is deleted.

    case "account.external_account.updated": //describes an external account (e.g., card or bank account), Occurs whenever an external account is updated.

    case "application_fee.created": //describes an application fee, Occurs whenever an application fee is created on a charge.

    case "application_fee.refunded": //describes an application fee, Occurs whenever an application fee is refunded, whether from refunding a charge or from refunding the application fee directly, including partial refunds.

    case "application_fee.refund.updated": //describes a fee refund, Occurs whenever an application fee refund is updated.

    case "balance.available": //describes a balance, Occurs whenever your Stripe balance has been updated (e.g., when a charge is available to be paid out). By default, Stripe automatically transfers funds in your balance to your bank account on a daily basis.

    case "bitcoin.receiver.created": //describes a bitcoin receiver, Occurs whenever a receiver has been created.

    case "bitcoin.receiver.filled": //describes a bitcoin receiver, Occurs whenever a receiver is filled (i.e., when it has received enough bitcoin to process a payment of the same amount).

    case "bitcoin.receiver.updated": //describes a bitcoin receiver, Occurs whenever a receiver is updated.

    case "bitcoin.receiver.transaction.created": //describes a bitcoin receiver, Occurs whenever bitcoin is pushed to a receiver., Occurs whenever an account capability is updated.

    case "charge.captured": //describes a charge, Occurs whenever a previously uncaptured charge is captured.

    case "charge.failed": //describes a charge, Occurs whenever a failed charge attempt occurs.

    case "charge.pending": //describes a charge, Occurs whenever a pending charge is created.

    case "charge.refunded": //describes a charge, Occurs whenever a charge is refunded, including partial refunds.

    case "charge.succeeded": //describes a charge, Occurs whenever a new charge is created and is successful.

    case "charge.updated": //describes a charge, Occurs whenever a charge description or metadata is updated.

    case "charge.dispute.closed": //describes a dispute, Occurs when a dispute is closed and the dispute status changes to charge_refunded, lost, warning_closed, or won.

    case "charge.dispute.created": //describes a dispute, Occurs whenever a customer disputes a charge with their bank.

    case "charge.dispute.funds_reinstated": //describes a dispute, Occurs when funds are reinstated to your account after a dispute is won.

    case "charge.dispute.funds_withdrawn": //describes a dispute, Occurs when funds are removed from your account due to a dispute.

    case "charge.dispute.updated": //describes a dispute, Occurs when the dispute is updated (usually with evidence).

    case "charge.refund.updated": //describes a refund, Occurs whenever a refund is updated on selected payment methods.

    case "coupon.created": //describes a coupon, Occurs whenever a coupon is created.

    case "coupon.deleted": //describes a coupon, Occurs whenever a coupon is deleted.

    case "coupon.updated": //describes a coupon, Occurs whenever a coupon is updated.

    case "customer.created": //describes a customer, Occurs whenever a new customer is created.

    case "customer.deleted": //describes a customer, Occurs whenever a customer is deleted.

    case "customer.updated": //describes a customer, Occurs whenever any property of a customer changes.

    case "customer.discount.created": //describes a discount, Occurs whenever a coupon is attached to a customer.

    case "customer.discount.deleted": //describes a discount, Occurs whenever a coupon is removed from a customer.

    case "customer.discount.updated": //describes a discount, Occurs whenever a customer is switched from one coupon to another.

    case "customer.source.created": //describes a source (e.g., card), Occurs whenever a new source is created for a customer.

    case "customer.source.deleted": //describes a source (e.g., card), Occurs whenever a source is removed from a customer.

    case "customer.source.updated": //describes a source (e.g., card), Occurs whenever a source's details are changed.

    case "customer.subscription.created": //describes a subscription, Occurs whenever a customer is signed up for a new plan.

    case "customer.subscription.deleted": //describes a subscription, Occurs whenever a customer's subscription ends.

    case "customer.subscription.trial_will_end": //describes a subscription, Occurs three days before the trial period of a subscription is scheduled to end.

    case "customer.subscription.updated": //describes a subscription, Occurs whenever a subscription changes (e.g., switching from one plan to another or changing the status from trial to active).

    case "invoice.created": //describes an invoice, Occurs whenever a new invoice is created. See Using Webhooks with Subscriptions to learn how webhooks can be used with, and affect, this event.

    case "invoice.payment_failed": //describes an invoice, Occurs whenever an invoice payment attempt fails, either due to a declined payment or the lack of a stored payment method.

    case "invoice.payment_succeeded": //describes an invoice, Occurs whenever an invoice payment attempt succeeds.

    case "invoice.sent": //describes an invoice, Occurs whenever an invoice email is sent out.

    case "invoice.upcoming": //describes an invoice, Occurs X number of days before a subscription is scheduled to create an invoice that is charged automatically, where X is determined by your subscriptions settings.

    case "invoice.updated": //describes an invoice, Occurs whenever an invoice changes (e.g., the invoice amount).

    case "invoiceitem.created": //describes an invoiceitem, Occurs whenever an invoice item is created.

    case "invoiceitem.deleted": //describes an invoiceitem, Occurs whenever an invoice item is deleted.

    case "invoiceitem.updated": //describes an invoiceitem, Occurs whenever an invoice item is updated.

    case "order.created": //describes an order, Occurs whenever an order is created.

    case "order.payment_failed": //describes an order, Occurs whenever an order payment attempt fails.

    case "order.payment_succeeded": //describes an order, Occurs whenever an order payment attempt succeeds.

    case "order.updated": //describes an order, Occurs whenever an order is updated.

    case "order_return.created": //describes an order return, Occurs whenever an order return is created.

    case "payout.canceled": //describes a payout, Occurs whenever a payout is canceled.

    case "payout.created": //describes a payout, Occurs whenever a payout is created.

    case "payout.failed": //describes a payout, Occurs whenever a payout attempt fails.

    case "payout.paid": //describes a payout, Occurs whenever a payout is expected to be available in the destination account. If the payout fails, a payout.failed notification is additionally sent at a later time.

    case "payout.updated": //describes a payout, Occurs whenever the metadata of a payout is updated.

    case "plan.created": //describes a plan, Occurs whenever a plan is created.

    case "plan.deleted": //describes a plan, Occurs whenever a plan is deleted.

    case "plan.updated": //describes a plan, Occurs whenever a plan is updated.

    case "product.created": //describes a product, Occurs whenever a product is created.

    case "product.deleted": //describes a product, Occurs whenever a product is deleted.

    case "product.updated": //describes a product, Occurs whenever a product is updated.

    case "recipient.created": //describes a recipient, Occurs whenever a recipient is created.

    case "recipient.deleted": //describes a recipient, Occurs whenever a recipient is deleted.

    case "recipient.updated": //describes a recipient, Occurs whenever a recipient is updated.

    case "review.closed": //describes a review, Occurs whenever a review is closed. The review's reason field indicates why (e.g., approved, refunded, refunded_as_fraud, disputed.

    case "review.opened": //describes a review, Occurs whenever a review is opened.

    case "scheduled_query_run.created": //describes a scheduled query run, Occurs whenever a sigma scheduled query run completes.

    case "sku.created": //describes a sku, Occurs whenever a SKU is created.

    case "sku.deleted": //describes a sku, Occurs whenever a SKU is deleted.

    case "sku.updated": //describes a sku, Occurs whenever a SKU is updated.

    case "source.canceled": //describes a source (e.g., card), Occurs whenever a source is canceled.

    case "source.chargeable": //describes a source (e.g., card)    case "capability.updated": //describes a capability, Occurs whenever a source transitions to chargeable.

    case "source.failed": //describes a source (e.g., card)" Occurs whenever a source fails.

    case "source.transaction.created": //describes a transaction    

    case "capability.updated": //describes a capability    

    case "source.failed": //describes a source (e.g., card)" Occurs whenever a source fails., Occurs whenever a source transaction is created.

    case "transfer.created": //describes a transfer": //, Occurs whenever a transfer is created.

    case "transfer.reversed": //describes a transfer": //    

    case "capability.updated": //describes a capability, Occurs whenever a transfer is reversed, including partial reversals.

    case "transfer.updated": // describes a transfer, Occurs whenever the description or metadata of a transfer is updated.

    case "ping": //has no descriptionm May be sent by Stripe at any time to see if a provided webhook URL is working.

      break;

  }


Azure Application Gateway with SSL Offloading - IIS Url Rewrite from HTTP to HTTPS Redirect

<rewrite> 

<rules> 

<rule name="HTTP To HTTPS Redirect Behind App Gtwy" stopProcessing="true"> 

<match url="^(.*)$" ignoreCase="false" /> 

<conditions logicalGrouping="MatchAny"> 

<add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" /> 

</conditions> 

<action type="Redirect" url="https://{SERVER_NAME}{URL}" redirectType="Found" /> 

</rule> 

</rules> 

</rewrite>


You can also do this HTTP to HTTPS redirect through the Application Gateway using PowerShell.

https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-configure-redirect-powershell