Created
March 5, 2023 01:30
-
-
Save ryochin/7d30d91c6d8d4a190ccb59b7bc342057 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Main | |
require 'aws-sdk-appconfigdata' | |
def initialize(application:, environment:, profile:) | |
@application = application | |
@environment = environment | |
@profile = profile | |
@client = Aws::AppConfigData::Client.new( | |
region: 'ap-northeast-1', | |
access_key_id: 'XXXX', | |
secret_access_key: 'XXXXXXXX' | |
) | |
end | |
def toggle_value(key) | |
# TODO: cache the result | |
config = JSON.parse(configuration.configuration.read) | |
if config.key?(key) | |
config.dig(key, 'enabled') | |
else | |
raise 'no such key!' | |
end | |
end | |
private | |
def configuration | |
@client.get_latest_configuration( | |
configuration_token: session.initial_configuration_token | |
) | |
end | |
def session | |
@client.start_configuration_session({ | |
application_identifier: @application, | |
environment_identifier: @environment, | |
configuration_profile_identifier: @profile, | |
required_minimum_poll_interval_in_seconds: 15 | |
}) | |
end | |
end | |
client = Main.new( | |
application: 'novelly', | |
environment: 'development', | |
profile: 'default' | |
) | |
puts client.toggle_value('use_macos_fonts') # -> true/false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment