mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-06 19:29:15 +08:00

* Use normalizer as stream source Renamed 'writer' service to 'normalizer' and dropped Cassandra facilities from it. Extracted the common dependencies to 'mainflux' package for easier sharing. Fixed the API docs and unified environment variables. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Use docker build arguments to specify build Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Remove cassandra libraries Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update go-kit version to 0.6.0 Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix manager configuration Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Refactor docker-compose Merged individual compose files and dropped external links. Remove CoAP container since it is not referenced from NginX config at the moment. Update port mapping in compose and nginx.conf. Dropped bin scripts. Updated service documentation. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Drop content-type check Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement users data access layer in PostgreSQL Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Bump version to 0.1.0 Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Use go-kit logger everywhere (except CoAP) Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Improve factory methods naming Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement clients data access layer on PostgreSQL Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Make tests stateless All tests are refactored to use map-based table-driven tests. No cross-tests dependencies is present anymore. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Remove gitignore Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix nginx proxying Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Mark client-user FK explicit Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update API documentation Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Update channel model Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Add channel PostgreSQL repository tests Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Implement PostgreSQL channels DAO Replaced update queries with raw SQL. Explicitly defined M2M table due to difficulties of ensuring the referential integrity through GORM. Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Expose connection endpoints Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix swagger docs and remove DB logging Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Fix nested query remarks Signed-off-by: Dejan Mijic <dejan@mainflux.com> * Add unique indices Signed-off-by: Dejan Mijic <dejan@mainflux.com>
117 lines
3.4 KiB
Go
117 lines
3.4 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build darwin dragonfly freebsd linux,!appengine netbsd openbsd
|
|
|
|
// Package terminal provides support functions for dealing with terminals, as
|
|
// commonly found on UNIX systems.
|
|
//
|
|
// Putting a terminal into raw mode is the most common requirement:
|
|
//
|
|
// oldState, err := terminal.MakeRaw(0)
|
|
// if err != nil {
|
|
// panic(err)
|
|
// }
|
|
// defer terminal.Restore(0, oldState)
|
|
package terminal // import "golang.org/x/crypto/ssh/terminal"
|
|
|
|
import (
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// State contains the state of a terminal.
|
|
type State struct {
|
|
termios unix.Termios
|
|
}
|
|
|
|
// IsTerminal returns true if the given file descriptor is a terminal.
|
|
func IsTerminal(fd int) bool {
|
|
_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
|
|
return err == nil
|
|
}
|
|
|
|
// MakeRaw put the terminal connected to the given file descriptor into raw
|
|
// mode and returns the previous state of the terminal so that it can be
|
|
// restored.
|
|
func MakeRaw(fd int) (*State, error) {
|
|
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
oldState := State{termios: *termios}
|
|
|
|
// This attempts to replicate the behaviour documented for cfmakeraw in
|
|
// the termios(3) manpage.
|
|
termios.Iflag &^= unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON
|
|
termios.Oflag &^= unix.OPOST
|
|
termios.Lflag &^= unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN
|
|
termios.Cflag &^= unix.CSIZE | unix.PARENB
|
|
termios.Cflag |= unix.CS8
|
|
termios.Cc[unix.VMIN] = 1
|
|
termios.Cc[unix.VTIME] = 0
|
|
if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, termios); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &oldState, nil
|
|
}
|
|
|
|
// GetState returns the current state of a terminal which may be useful to
|
|
// restore the terminal after a signal.
|
|
func GetState(fd int) (*State, error) {
|
|
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &State{termios: *termios}, nil
|
|
}
|
|
|
|
// Restore restores the terminal connected to the given file descriptor to a
|
|
// previous state.
|
|
func Restore(fd int, state *State) error {
|
|
return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios)
|
|
}
|
|
|
|
// GetSize returns the dimensions of the given terminal.
|
|
func GetSize(fd int) (width, height int, err error) {
|
|
ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
|
|
if err != nil {
|
|
return -1, -1, err
|
|
}
|
|
return int(ws.Col), int(ws.Row), nil
|
|
}
|
|
|
|
// passwordReader is an io.Reader that reads from a specific file descriptor.
|
|
type passwordReader int
|
|
|
|
func (r passwordReader) Read(buf []byte) (int, error) {
|
|
return unix.Read(int(r), buf)
|
|
}
|
|
|
|
// ReadPassword reads a line of input from a terminal without local echo. This
|
|
// is commonly used for inputting passwords and other sensitive data. The slice
|
|
// returned does not include the \n.
|
|
func ReadPassword(fd int) ([]byte, error) {
|
|
termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
newState := *termios
|
|
newState.Lflag &^= unix.ECHO
|
|
newState.Lflag |= unix.ICANON | unix.ISIG
|
|
newState.Iflag |= unix.ICRNL
|
|
if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newState); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
defer func() {
|
|
unix.IoctlSetTermios(fd, ioctlWriteTermios, termios)
|
|
}()
|
|
|
|
return readPasswordLine(passwordReader(fd))
|
|
}
|