Skip to content

feat: add options loading from .ini file#4

Open
0xHericles wants to merge 1 commit into
digital-dream-labs:mainfrom
OhMyVector:feat/sdk-ini
Open

feat: add options loading from .ini file#4
0xHericles wants to merge 1 commit into
digital-dream-labs:mainfrom
OhMyVector:feat/sdk-ini

Conversation

@0xHericles
Copy link
Copy Markdown

@0xHericles 0xHericles commented Aug 21, 2021

Description

Create a loader that reuses the existing format from the python SDK.
It's loading the options from the ~/.anki_vector/sdk_config.ini path.

To ensure it will work well for Linux, macOS, and Windows, the loader uses os.UserHomeDir() to get the user home directory and filepath.Join to create a compatible file path.

Linked Issues

Write a configuration loader that reuses the existing format from the python sdk #1

Notes

This code is not actually supporting 100% of the existing .ini format (for python SDK). It's only loading the information from the DEFAULT section, and mapping to a struct, like:

[DEFAULT]
cert = location_of_bot_cert.cert
ip = bot_ip_address
name = bot_name
guid = guid_aka_token

The code for getting the section is:

sec, _ := initData.GetSection(ini.DefaultSection)

A suggestion to handle this is to add a "profile" that targets the wanted section, similar to AWS profiles in the CLI, and pass it as a parameter in vector.New() or something like this. So we could do something like:

sdk_config.ini

[DEFAULT]
cert = location_of_bot_cert.cert
ip = bot_ip_address
name = bot_name
guid = guid_aka_token

[00507778]
cert = location_of_another_bot_cert.cert
ip = another_bot_ip_address
name = another_bot_name
guid = another_guid_aka_token

section targeting in vector.go

sec, _ := initData.GetSection(profile) // where profile is 00507778 (example)

And then it wil load the information about the another bot.

Additionally

What do you think about add logging to the SDK? There are some blank identifiers ("_") for errors that should not crash the function, but it might be a good idea to display them.

Thoughts? @dietb @bussardrobbie

@0xHericles
Copy link
Copy Markdown
Author

About the new deps:

I'm using the gopkg.in/ini.v1 package to parse the sdk_config.ini file.
You can find it here: https://github.com/go-ini/ini

@0xHericles
Copy link
Copy Markdown
Author

@markoxley, I saw you've tried something on this issue. Do you have any thoughts or suggestions too? ^^

@markoxley
Copy link
Copy Markdown

@markoxley, I saw you've tried something on this issue. Do you have any thoughts or suggestions too? ^^

It would be quite simple to adapt my code to handle multiple Vectors.

https://github.com/markoxley/vutils

If a new struct was added to store the configurations, then the regex would also need to be amended to something like:
^\s*(([^\s=]+)\s*=\s*(\S+)|\[(.+)\])$

The loop will then need to be amended. I'm not at my development machine right now, but when I get a chance, I'll amend the utils module to handle multiple Vectors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants