Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] When using tilde ~ on credentials_file it does not expand to home directory #317

Closed
fernando-villalba opened this issue Aug 13, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@fernando-villalba
Copy link
Contributor

Description

Using tilde for the home directory in the configuration for credentials_file does not work:

provider "civo" {
  region = "LON1"
  credentials_file = "~/token"
}

This is because os.ReadFile(path) does not expand the tilde.

Proposed solution

We can use the go-homedir function here is an example

Any other solution with minimal code required would do, there is a built-in function called os/user but according to Mitchell Hashimoto, the create of the go-homedir function above:

Why not just use os/user? The built-in os/user package requires cgo on Darwin systems. This means that any Go code that uses that package cannot cross compile. But 99% of the time the use for os/user is just to retrieve the home directory, which we can do for the current user without cgo. This library does that, enabling cross-compilation.

Or that was the case 6 years ago, it may be different today, haven't done the research.

Acceptance Criteria

  • Ensure that the tilde (~) gets expanded properly. Don't use too much code for this.
@fernando-villalba fernando-villalba added the bug Something isn't working label Aug 13, 2024
@Praveen005
Copy link
Contributor

Hi @fernando-villalba,

homedir.Expand() works well for our use case. As for os/user, it doesn't directly help us expand tilde (~).

I tested the change and it works fine.

@Praveen005
Copy link
Contributor

Praveen005 commented Aug 14, 2024

Hi @uzaxirr

#322 fixes this as well.

I used homedir.Expand() to expand the tilde.

Reason:

  1. The current version is stable.
  2. It was wide adoption.
  3. homedir itself doesn't depend on any other third-party library.
  4. Currently we are also using it in our Civo CLI repository.

https://github.com/civo/cli/blob/8a5fa361e070a817a5d07d71d582badf9a274f38/config/config.go#L48

Result:

Screenshot 2024-08-14 164836

Before:
Throwing error:

Screenshot 2024-08-14 163052

After:

works fine:

Screenshot 2024-08-14 163202

@uzaxirr
Copy link
Member

uzaxirr commented Aug 15, 2024

Resolved via: #322

@uzaxirr uzaxirr closed this as completed Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants