https://github.com/gokaykucuk/elevator
A golang library to requrest and switch to superuser with one line.
https://github.com/gokaykucuk/elevator
cli sudo superuser superuser-privileges
Last synced: 6 months ago
JSON representation
A golang library to requrest and switch to superuser with one line.
- Host: GitHub
- URL: https://github.com/gokaykucuk/elevator
- Owner: gokaykucuk
- License: mit
- Created: 2018-10-29T19:16:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-30T22:57:45.000Z (over 7 years ago)
- Last Synced: 2024-06-20T12:06:25.658Z (about 2 years ago)
- Topics: cli, sudo, superuser, superuser-privileges
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# elevator
[](https://codeclimate.com/github/gokaykucuk/elevator/maintainability)
[](https://codecov.io/gh/gokaykucuk/elevator)
[](https://travis-ci.org/gokaykucuk/elevator)
[](https://coveralls.io/github/gokaykucuk/elevator)

[](https://readthedocs.org/projects/gokaykucukelevator/)
A golang library for requesting self-sudo.
Simply put, the idea is in the runtime, if the process is not started with superuser permissions, request them
and then restart the application. The only rule is, this libraries `CheckAndRequestElevation()` function *MUST* be
called as the first thing before the main application loads.
To supply the sudo username and password during development locally, just use the environment variables defined as,
ELEVATOR_SUDO_PASSWORD=12341234
As you should already know, what i described a moment ago is a terrible idea, and you should never do it. But, if
you feel like not entering the password again and again on every restart while debugging your application, it's
actually a quite useful tool. Maybe I'll provide more elegant ways of supplying a default password and username in
future.
### Installation
Just as any other go package, you can get it with `go get`
go get -u github.com/gokaykucuk/elevator
### Example
package main
import (
"github.com/gokaykucuk/elevator"
"gitlab.com/..."
)
var (
version = "No version provided"
commit = "No commit provided"
buildTime = "No build timestamp provided"
)
func main() {
elevator.CheckAndRequestElevation()
cmd.SetVersion(&cmd.Version{
Version: version,
Commit: commit,
BuildTime: buildTime,
})
cmd.Execute()
}
### Contributing
You can create a PR and as long as it makes sense, and doesn't enlarge the scope of the project by 2, it'll be merged.
### Testing
Currently there are no real tests because i don't have a good idea how to write them. If you have any good ideas please
open a pull request.
### TODO
- Make it windows compatibale?
- Make another function which will only check but not ask for permissions