GraphQL API server in golang to get linux system info.
- golang installed
- add $GOPATH/bin to $PATH
export PATH=$PATH:$GOPATH/bin
- install go packages
go get github.com/msteinert/pam
go get github.com/spf13/cobra
- [option] install httpie
- install go-bindata
make setup
- run server
make run
- build static binary
make
Flags:
-d, --debug debug mode
--disable-auth disable auth middleware
-h, --help help for graphql-server
-p, --port int port number (default 9527)
** graphiql is only available when disable auth middleware **
To check whether server is alive
curl http://localhost:9527/ping
Get auth token
http -v --json POST localhost:9527/login name=kevin passwd=somepassword
Refresh token before token expire
http -v -f POST localhost:9527/refresh_token "Authorization:Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NDQ2MDkwNDAsIm5hbWUiOiJyb290Iiwib3JpZ19pYXQiOjE1NDQ2MDU0NDB9.a1DZTB17HXJrC
Get user
query {
user(uid: "0") {
uid
gid
name
home
groups {
gid
name
}
}
}
Get user by user name
query {
userByName(name: "root") {
uid
gid
name
home
groups {
gid
name
}
}
}
Get users
query {
users {
uid
gid
name
home
groups {
gid
name
}
}
}
Get CPU
query {
cpu(id:"cpu1") {
id
total
user
system
idle
iowait
}
}
Get CPUs
query {
cpus {
id
total
user
system
idle
iowait
}
}
Get Memory
query {
memory {
total
free
used
shared
buffer
cache
swap
}
}
Get Iface
query {
iface(name: "eno1") {
name
mac
addrv4 {
ip
mask
}
addrv6 {
ip
mask
}
mtu
rx
tx
}
}
Get Ifaces
query {
ifaces {
name
mac
addrv4 {
ip
mask
}
addrv6 {
ip
mask
}
mtu
rx
tx
}
}
Get service
query {
service (name: "smb") {
name
mainPID
activeState
unitFileState
}
}
Start service
mutation {
startService (name: "smb") {
name
mainPID
activeState
unitFileState
}
}
Stop service
mutation {
stopService (name: "smb") {
name
mainPID
activeState
unitFileState
}
}
Enable service
mutation {
enableService (name: "smb") {
name
mainPID
activeState
unitFileState
}
}
Disable service
mutation {
disableService (name: "smb") {
name
mainPID
activeState
unitFileState
}
}
curl -X POST -H 'Content-Type: application/json' -d '{"query": "{ user(uid:\"0\") { uid, gid, name, home, groups { gid, name } } }"}' localhost:9527/graphql
- Add auth middleware (gin-jwt)