Created
December 21, 2017 14:49
-
-
Save omerlh/4186ce201eea01f5949e4b1643873021 to your computer and use it in GitHub Desktop.
Generating ACS autoscaler secrets.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: Secret | |
metadata: | |
name: autoscaler | |
data: | |
azure-sp-app-id: <%= @app_id %> | |
azure-sp-secret: <%= @app_secret %> | |
azure-sp-tenant-id: <Replace wiht your Tenant Id base64 encoded> | |
kubeconfig-private-key: <%= @kubeconfig_private_key %> | |
client-private-key: <%= @client_private_key %> | |
ca-private-key: <%= @ca_private_key %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
# With the help from the following SO answers: | |
# https://stackoverflow.com/a/2621023/4792970 | |
# https://stackoverflow.com/questions/25817007/how-do-i-save-the-text-of-puts-in-ruby-to-a-txt-file | |
require 'json' | |
require 'base64' | |
if (ARGV.length < 1) | |
puts "usages: ruby secret_generator.rb <path_to_azure_deployment>" | |
end | |
json = File.read(ARGV[0]) | |
obj = JSON.parse(json)["parameters"] | |
@app_id = Base64.strict_encode64(obj["servicePrincipalClientId"]["value"]) | |
@app_secret = Base64.strict_encode64(obj["servicePrincipalClientSecret"]["value"]) | |
@kubeconfig_private_key = Base64.strict_encode64(obj["kubeConfigPrivateKey"]["value"]) | |
@client_private_key = Base64.strict_encode64(obj["clientPrivateKey"]["value"]) | |
@ca_private_key = Base64.strict_encode64(obj["caPrivateKey"]["value"]) | |
template = File.read('./secret.yaml.erb') | |
renderer = ERB.new(template).result( binding ) | |
File.open("secrets.yaml","w") do |f| | |
f.puts renderer | |
end | |
puts "done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment