linode_api4-python icon indicating copy to clipboard operation
linode_api4-python copied to clipboard

Share config with linode-cli

Open tarqd opened this issue 6 years ago • 6 comments

I think it'd be useful if the linode-cli and linode api bindings used a common set of config files/env variables.

This would be similar to how all applications that use libmysql load ~/.my.cnf. This feature will reduce the amount of config needed to use linode with various tools. It will also make it so users can have a central place where their access tokens live.

Since the cli currently uses ~/.linode-cli, I think we may want to move the config to something like: ~/.config/linode/linode.ini

I think the MySQL method of having seperate groups for services would also be useful:

[default]
token=foo
type=g6-nanode-1

[linode-cli]
region=us-east

[linode-ansible]
token=anothertokenfordeploys

You could have a similar API as libmysql where you can define which group to load overrides from:

LinodeLoginClient(config_group="linode-cli")

tarqd avatar Dec 06 '18 03:12 tarqd

Since linode-cli doesn't seem to use this lib, it may better to lift this logic into a separate shared package (linode-api-config).

tarqd avatar Dec 06 '18 03:12 tarqd

Wrappers in other languages, and other tools, could share the token. This sounds good in theory.

token, type, and region sound like good starting points.

type is ambiguous, but instance_type would be an invention. 😖

displague avatar Dec 06 '18 04:12 displague

I'm not opposed to trying this if there consensus, but in general I find it weird when libraries attempt to load configuration from the disk when imported. If I'm invoking a library in my code, I expect to provide it the configuration it needs when I initialize it, not have it do some spooky action so that it works (apparently) without configuration.

I'd also rather not accidentally have the script I'm writing and testing use the same credentials I provided to the CLI (the CLI requests all access to everything because it does everything - I might want reduced access for my script so it doesn't destroy my whole account while I'm debugging it).

type is ambiguous, but instance_type would be an invention. 😖

I agree, but that ship has sailed already

Dorthu avatar Dec 06 '18 12:12 Dorthu

  • I might want reduced access for my script so it doesn't destroy my whole account while I'm debugging it).

By default, I would make it save the creds in a group specific for the CLI:

; you could also not have a default
[linode-cli]
token=foo

; alternatively, don't put this at all and continue using loading the config as you usually do
[my-dev-app]
token=wat

I do something similar with my mysql configs:

[development]
user=bla

[backups]
user=backups
host=bla

Another thing I like about this is as we continue to add to our ecosystem: There will be more and more tools sysadmins/devops needs to configure with API tokens for automation. With a standard like this, you can keep manage all your configs in one place and it will Just Work (TM) no matter what combination of tools you're using, even across languages, assuming other language SDKs use this as well.

tarqd avatar Dec 06 '18 14:12 tarqd

Would it be an acceptable solution to allow the LinodeClient to receive a config file instead of a token, and load values from that file if it's provided? That's more agreeable to me than a mysterious default config that I don't have to use explicitly (and more backwards-compatible)

Dorthu avatar Dec 07 '18 16:12 Dorthu

For me a lot of the utility comes from being able to use these configs without tooling needing to explicitly add support for it. Would having the auto-loading behavior be opt-in via an environment variable be a more palatable middle-ground?

Some ideas for ENV variables:

LINODE_API_USE_CONF=1
LINODE_API_CONFIG=/bla/bla/linode.ini
LINODE_API_CONFIG_GROUP=ansible

I think there's value even without the auto-loading but I personally found this workflow very nice for dealing with tools in the mysql ecosystem. I'm very taken aback when the tools don't support it (ones that don't use libmysql or libraries that don't have that behavior).

tarqd avatar Dec 08 '18 02:12 tarqd

We have decided against adding this functionality because much of the linode-cli configuration format is CLI-specific. Please let us know if you have any other feature suggestions 🙂

lgarber-akamai avatar Sep 11 '23 19:09 lgarber-akamai