In Troposphere, how do I add CustomOriginConfig object - amazon-cloudfront

Using troposhphere, I am trying to add CustomOriginConfig to my CloudFront distribution.
.....
Origins = [Origin(
Id = Join("", ["cloudfront-", Ref("ParamOriginName")]),
DomainName = Ref("ParamOriginName"),
CustomOriginConfig(
OriginProtocolPolicy = "https-only",
OriginSSLProtocols = ["TLSv1.1"]
)
)],
.....
This fails to build, giving the following error:
CustomOriginConfig(
^
SyntaxError: positional argument follows keyword argument
I have looked at this and this and I think that my syntax is correct.
What do I need to do to fix this?

You need to create a variable, whose value is the CustomOriginConfig object
Origins = [Origin(
Id = Join("", ["cloudfront-", Ref("ParamOriginName")]),
DomainName = Ref("ParamOriginName"),
CustomOriginConfig = CustomOriginConfig(
OriginProtocolPolicy = "https-only",
OriginSSLProtocols = ["TLSv1.1"]
)
)],

Related

Create sublist from list

I have following list named svc_tk_input
['4505/tcp', '4506/tcp', '80/tcp', '4505/udp', '4506/udp', '80/udp']
and i have following service so defined:
svc_a = [port_x/udp]
svc_b = [port_y/tcp]
svc_c = [port_x/udp, port_x/tcp]
svc_d = [port_x/tcp, port_x/udp]
svc_e = [port_y/udp, port_y/tcp]
svc_f = [port_y/tcp, port_y/udp]
svc_g = [port_x/tcp, port_y/tcp]
svc_h = [port_x/udp, port_y/udp]
svc_i = [port_y/tcp, port_x/tcp]
svc_l = [port_y/udp, port_x/udp]
svc_m = [port_x/tcp, port_y/udp]
svc_n = [port_x/udp, port_y/tcp]
svc_o = [port_y/tcp, port_x/udp]
svc_p = [port_y/udp, port_x/tcp]
Final target is to see if any service is defined given the port/protocol in svc_tk_input.
Idea:
create a second list svc_tk_input_mod
svc_tk_input_mod list has all combination of input port/protocol
svc_tk_input_mod = [('4505/tcp'), ('4505/udp'), ('4506/tcp'), ('4506/udp'),...,('4505/tcp' ,'4505/udp'), ('4505/tcp' ,'80/udp'),... ]
check at the end if any service is defined (out of scope here and this part is already covered)
I try to create the list svc_tk_input_mod by using itertools permutations but list that i get contains such combination
[('4505/tcp', '4506/tcp', '4505/udp', '4506/udp'), ('4505/tcp', '4506/tcp', '4506/udp', '4505/udp'), ('4505/tcp', '4505/udp', '4506/tcp', '4506/udp'), (...)]
As you can see each single element never can match the definition of service (service is a list of max 2 element)
Any suggestion on how can i improve the above?
Update here my code
list_protocols = str(policy_dict[term_name]["protocol"]).split(",") # (udp tcp)
list_ports = str(policy_dict[term_name][port_item]).split(",") # (53, 22, 1024-65535)
svc_tk_val_input = [ ]
svc_tk_val_input = build_svc_tk_val_input.build_svc_tk_val(list_protocols, list_ports,svc_tk_val_input)
svc_tk_val_input_permutation = [ ]
svc_tk_val_input_permutation = build_svc_tk_val_input.build_svc_tk_val_permutation(svc_tk_val_input, svc_tk_val_input_permutation)
svc_tk_val_input_permutation_2 = [ ]
if len(list_ports)>2:
svc_tk_val_input_permutation_2 =
build_svc_tk_val_input.build_svc_tk_val_permutation_with_len(svc_tk_val_input, svc_tk_val_input_permutation,2)
def build_svc_tk_val(list_protocols, list_ports,svc_tk_val_input):
for protocol in list_protocols:
for port in list_ports:
ppp_item = port+"/"+protocol
print(ppp_item)
# Token that we want
svc_tk_val_input.append(ppp_item)
return svc_tk_val_input
def build_svc_tk_val_permutation(svc_tk_val_input,svc_tk_val_input_permutation):
svc_tk_val_permutation = permutations(svc_tk_val_input)
for svc_tk_id_item_permutation in list(svc_tk_val_permutation):
#print(f"Combination {svc_tk_id_item_permutation}")
svc_tk_val_input_permutation.append(svc_tk_id_item_permutation)
return svc_tk_val_input_permutation
def build_svc_tk_val_permutation_with_len(svc_tk_val_input,svc_tk_val_input_permutation,permutation_len):
svc_tk_val_permutation = permutations(svc_tk_val_input,permutation_len)
for svc_tk_id_item_permutation in list(svc_tk_val_permutation):
#print(f"Combination {svc_tk_id_item_permutation}")
svc_tk_val_input_permutation.append(svc_tk_id_item_permutation)
return svc_tk_val_input_permutation

MongoDB Atlas Provider - Terraform

I am not able to figure out below in Terraform (>= 0.13) using MongoDB Atlas provider (version >= 0.9.1)
How to set below 2 properties. Did a lot of google search with no luck
As per the documentation here:
https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster
I would like to set below 2 properties:
providerSettings.autoScaling.compute.maxInstanceSize
providerSettings.autoScaling.compute.minInstanceSize
I have not tried above keys as it has . in it
tried below with no luck
providerAutoScalingComputeMaxInstanceSize = "M20"
providerAutoScalingComputeMinInstanceSize = "M10"
provider_autoScaling_compute_maxInstanceSize = "M20"
provider_autoScaling_compute_minInstanceSize = "M10"
On terraform plan. I see error:
Error: Unsupported argument
on .terraform/modules/mongodb_test_b/main.tf line 10, in resource "mongodbatlas_cluster" "mongodbatlas_cluster":
10: providerAutoScalingComputeMaxInstanceSize = var.providerAutoScalingComputeMaxInstanceSize
An argument named "providerAutoScalingComputeMaxInstanceSize" is not expected
here.
Error: Unsupported argument
on .terraform/modules/mongodb_test_b/main.tf line 12, in resource "mongodbatlas_cluster" "mongodbatlas_cluster":
12: providerAutoScalingComputeMinInstanceSize = var.providerAutoScalingComputeMinInstanceSize
An argument named "providerAutoScalingComputeMinInstanceSize" is not expected
here.
Code snippet
resource "mongodbatlas_cluster" "mongodbatlas_cluster" {
project_id = var.project_id
provider_name = var.provider_name
name = var.name
provider_instance_size_name = var.provider_instance_size_name
provider_disk_type_name = var.provider_disk_type_name
auto_scaling_compute_enabled = var.auto_scaling_compute_enabled
providerAutoScalingComputeMaxInstanceSize = var.providerAutoScalingComputeMaxInstanceSize
auto_scaling_compute_scale_down_enabled = var.auto_scaling_compute_scale_down_enabled
providerAutoScalingComputeMinInstanceSize = var.providerAutoScalingComputeMinInstanceSize
pit_enabled = var.pit_enabled
cluster_type = var.cluster_type
replication_specs {
num_shards = var.replication_specs_num_shards
regions_config {
region_name = var.region_name
electable_nodes = var.replication_specs_regions_config_electable_nodes
priority = var.replication_specs_regions_config_priority
read_only_nodes = var.replication_specs_regions_config_read_only_nodes
analytics_nodes = var.analytics_nodes
}
}
mongo_db_major_version = var.mongo_db_major_version
provider_backup_enabled = var.provider_backup_enabled
auto_scaling_disk_gb_enabled = var.auto_scaling_disk_gb_enabled
}
Any assistance. Much appreciated.
You are using the wrong argument names, you need these two:
provider_auto_scaling_compute_min_instance_size [1]
provider_auto_scaling_compute_max_instance_size [2]
Your code should look like this:
provider_auto_scaling_compute_max_instance_size = var.providerAutoScalingComputeMaxInstanceSize
provider_auto_scaling_compute_min_instance_size = var.providerAutoScalingComputeMinInstanceSize
You might also consider naming your variables differently, i.e., using the same names for those as for the argument names as that helps with mapping between what an argument is and what value will it have.
[1] https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster#provider_auto_scaling_compute_min_instance_size
[2] https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/resources/cluster#provider_auto_scaling_compute_max_instance_size

Turn a formatted PowerShell hash table/array definition into a single line (and vice versa) via hot key in Visual Studio Code

In Visual Studio Code I am trying to work out a way to convert a piece of PowerShell (which defines a collection of hash tables and arrays) into a single line of code, and also a way to perform the same operation but the other way (i.e. take a single line and make it more readable). I need to do this because the YAML variable I am defining needs to be done on a single line (the PowerShell gets passed to another PowerShell script via this variable).
So, for example, I need to be able to turn:
#{
TestData = #{
Connections = #(
#{
ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01';
SourceVmName = 'D3ZUKS342APP01';
Targets = #(
#{
DestinationVmName = 'D3ZUKS342SQL01';
DestinationVmResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01';
DestinationPort = 1433;
Status = 'Reachable'
}
)
}
)
};
IPFlows = #(
#{
ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01';
TargetVmName = 'D3ZUKS342SQL01';
InboundFlows = #(
#{
Description = 'Application Server D3ZUKS342APP01';
Protocol = 'TCP';
LocalPorts = 1433;
RemoteIpAddress = '10.124.36.132';
RemotePort = 0;
}
);
OutboundFlows = #()
}
)
}
into:
#{TestData = #{Connections = #(#{ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01';SourceVmName= 'D3ZUKS342APP01';Targets = #(#{DestinationVmName= 'D3ZUKS342SQL01';DestinationVmResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01';DestinationPort= 1433;Status = 'Reachable' })});IPFlows = #(#{ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01';TargetVmName= 'D3ZUKS342SQL01';InboundFlows= #(#{Description = 'Application Server D3ZUKS342APP01';Protocol= 'TCP';LocalPorts= 1433;RemoteIpAddress = '10.124.36.132';RemotePort= 0;});OutboundFlows = #()})}}
And more importantly, do the same in reverse (i.e. take the single line and make it readable/editable). Ideally I'd love to be able to do both by mapping a hotkey to both operations.
The multi line > single line seems easier - a regex replace of \s+( ) with nothing, followed by a replace of carriage returns with nothing, but how can I map that to a hotkey?
The single line > multi line seems much harder :( I have searched for an extension that might help, but to no avail. Does anyone have any suggestions, either native Visual Studio Code functionality or an extension that I could use?
Although I do not understand why you need this either, specific to the request for a oneliner: you might use this ConvertTo-Expression cmdlet to rebuild your expression from an object using several expansion levels:
$Object = #{
TestData = #{ ...
# Oneliner
$Object | ConvertTo-Expression -Expand 0
#{IPFlows = ,#{ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01'; TargetVmName = 'D3ZUKS342SQL01'; InboundFlows = ,#{Description = 'Application Server D3ZUKS342APP01'; RemoteIpAddress = '10.124.36.132'; RemotePort = 0; Protocol = 'TCP'; LocalPorts = 1433}; OutboundFlows = #()}; TestData = #{Connections = ,#{ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01'; SourceVmName = 'D3ZUKS342APP01'; Targets = ,#{DestinationVmName = 'D3ZUKS342SQL01'; DestinationPort = 1433; DestinationVmResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01'; Status = 'Reachable'}}}}
# Compressed
$Object | ConvertTo-Expression -Expand -1
#{IPFlows=,#{ResourceGroup='d3zuks-bussvc-342-brimig-rgrp01';TargetVmName='D3ZUKS342SQL01';InboundFlows=,#{Description='Application Server D3ZUKS342APP01';RemoteIpAddress='10.124.36.132';RemotePort=0;Protocol='TCP';LocalPorts=1433};OutboundFlows=#()};TestData=#{Connections=,#{ResourceGroup='d3zuks-bussvc-342-brimig-rgrp01';SourceVmName='D3ZUKS342APP01';Targets=,#{DestinationVmName='D3ZUKS342SQL01';DestinationPort=1433;DestinationVmResourceGroup='d3zuks-bussvc-342-brimig-rgrp01';Status='Reachable'}}}}
# Expanded (to any level)
$Object | ConvertTo-Expression # -Expand to any level
#{
IPFlows = ,#{
ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01'
TargetVmName = 'D3ZUKS342SQL01'
InboundFlows = ,#{
Description = 'Application Server D3ZUKS342APP01'
RemoteIpAddress = '10.124.36.132'
RemotePort = 0
Protocol = 'TCP'
LocalPorts = 1433
}
OutboundFlows = #()
}
TestData = #{Connections = ,#{
ResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01'
SourceVmName = 'D3ZUKS342APP01'
Targets = ,#{
DestinationVmName = 'D3ZUKS342SQL01'
DestinationPort = 1433
DestinationVmResourceGroup = 'd3zuks-bussvc-342-brimig-rgrp01'
Status = 'Reachable'
}
}}
}

Python PonyORM One to one mapping

I am trying to create a one-to-one mapping using Pony ORM.
class ApplierIngress(ApplierObjectMapper.db.Entity):
correlation_id = orm.PrimaryKey(str)
ticket_number = orm.Required(str)
username = orm.Required(str)
status = orm.Required(str)
request_date = orm.Required(datetime)
class ApplierResult(ApplierObjectMapper.db.Entity):
correlation_id = orm.Required(ApplierIngress)
result = orm.Required(orm.LongStr)
request_date = orm.Required(datetime)
It throws error while generating the mapping
pony.orm.core.ERDiagramError: Reverse attribute for ApplierResult.correlation_id not found
I want correlation_id in ApplierResult table be the foreign key referencing to correlation_id in ApplierIngress table
Please let me know what am I doing wrong?
As error said you need to specify reverse attribute. Entities is not just Tables.
class ApplierIngress(ApplierObjectMapper.db.Entity):
correlation_id = orm.PrimaryKey(str)
ticket_number = orm.Required(str)
username = orm.Required(str)
status = orm.Required(str)
request_date = orm.Required(datetime)
result_id = orm.Optional('ApplierResult') # this attribute should be added
class ApplierResult(ApplierObjectMapper.db.Entity):
correlation_id = orm.Required(ApplierIngress)
result = orm.Required(orm.LongStr)
request_date = orm.Required(datetime)
Since this class is not yet declared you should use it as string or lambda
result_id = orm.Optional('ApplierResult')
result_id = orm.Optional(lambda: ApplierResult)
See here

Can't get HTTP headers from request

I'm trying to get the headers from a HTTP request. I've tried echoing them, only to get a compile error. I've tried looping through the headers as well. My code is:
var packet = newMultipartData()
packet["username"] = username
packet["password"] = password
var response = post(BASE & "users/login", multipart=packet)
echo response.headers
And the error I'm getting is: Error: type mismatch: got (HttpHeaders)
Figured it out - Turns out I can call the one I want from the list. Ex: response.headers["X-CSRF-TOKEN"]
The reason your code does not work because there is no $ proc defined for HttpHeaders:
let headers = newHttpHeaders()
headers["foo"] = "bar"
headers["foo2"] = "bar2"
echo headers["foo"] # compiles
echo headers # does _not_ compile
We can quickly implement an own $ proc ourselves:
proc `$`(h: HttpHeaders): string =
result = "{"
for key, value in h:
if result.len > 1: result.add(", ")
result.add(key)
result.add(": ")
result.add(value)
result.add("}")
The implementation is based on https://github.com/nim-lang/Nim/blob/master/lib/pure/collections/tables.nim#L333. Because HttpHeaders is just a type to a table, we can simply reuse the existing proc.
type
HttpHeaders* = ref object
table*: TableRef[string, seq[string]]

Resources