Skip to content

Commit

Permalink
Merge pull request #12 from rhatdan/Makefile
Browse files Browse the repository at this point in the history
Add support for golint
  • Loading branch information
runcom authored Mar 22, 2017
2 parents e220759 + 9504d4e commit ba1aefe
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 105 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,14 @@ go:
- tip
- master

env:
global:
- BUILDTAGS="selinux linux"

before_install:
- go get -u github.com/golang/lint/golint
- go get -u github.com/vbatts/git-validation

script:
- go test -v -tags "selinux linux" ./...
- git-validation -run DCO,short-subject -v -range ${TRAVIS_COMMIT_RANGE}
- make BUILDTAGS="${BUILDTAGS}" lint test
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ BUILDTAGS := selinux

check-gopath:
ifndef GOPATH
$(error GOPATH is not set)
$(error GOPATH is not set)
endif

.PHONY: test
test: check-gopath
go test -timeout 3m -tags "${BUILDTAGS}" ${TESTFLAGS} -v ./...

.PHONY:
lint:
golint go-selinux
2 changes: 1 addition & 1 deletion go-selinux/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ReserveLabel(label string) error {
return nil
}

func UnreserveLabel(label string) error {
func ReleaseLabel(label string) error {
return nil
}

Expand Down
44 changes: 22 additions & 22 deletions go-selinux/label/label_selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ var ErrIncompatibleLabel = fmt.Errorf("Bad SELinux option z and Z can not be use
// the labels. The labels returned will include a random MCS String, that is
// guaranteed to be unique.
func InitLabels(options []string) (string, string, error) {
if !selinux.SelinuxEnabled() {
if !selinux.GetEnabled() {
return "", "", nil
}
processLabel, mountLabel := selinux.GetLxcContexts()
processLabel, mountLabel := selinux.ContainerLabels()
if processLabel != "" {
pcon := selinux.NewContext(processLabel)
mcon := selinux.NewContext(mountLabel)
Expand All @@ -55,8 +55,8 @@ func InitLabels(options []string) (string, string, error) {
return processLabel, mountLabel, nil
}

func GetROMountLabel() string {
return selinux.GetROFileLabel()
func ROMountLabel() string {
return selinux.ROFileLabel()
}

// DEPRECATED: The GenLabels function is only to be used during the transition to the official API.
Expand Down Expand Up @@ -88,33 +88,33 @@ func SetProcessLabel(processLabel string) error {
if processLabel == "" {
return nil
}
return selinux.Setexeccon(processLabel)
return selinux.SetExecLabel(processLabel)
}

// GetProcessLabel returns the process label that the kernel will assign
// ProcessLabel returns the process label that the kernel will assign
// to the next program executed by the current process. If "" is returned
// this indicates that the default labeling will happen for the process.
func GetProcessLabel() (string, error) {
return selinux.Getexeccon()
func ProcessLabel() (string, error) {
return selinux.ExecLabel()
}

// GetFileLabel returns the label for specified path
func GetFileLabel(path string) (string, error) {
return selinux.Getfilecon(path)
func FileLabel(path string) (string, error) {
return selinux.FileLabel(path)
}

// SetFileLabel modifies the "path" label to the specified file label
func SetFileLabel(path string, fileLabel string) error {
if selinux.SelinuxEnabled() && fileLabel != "" {
return selinux.Setfilecon(path, fileLabel)
if selinux.GetEnabled() && fileLabel != "" {
return selinux.SetFileLabel(path, fileLabel)
}
return nil
}

// SetFileCreateLabel tells the kernel the label for all files to be created
func SetFileCreateLabel(fileLabel string) error {
if selinux.SelinuxEnabled() {
return selinux.Setfscreatecon(fileLabel)
if selinux.GetEnabled() {
return selinux.SetFSCreateLabel(fileLabel)
}
return nil
}
Expand All @@ -123,7 +123,7 @@ func SetFileCreateLabel(fileLabel string) error {
// It changes the MCS label to s0 if shared is true.
// This will allow all containers to share the content.
func Relabel(path string, fileLabel string, shared bool) error {
if !selinux.SelinuxEnabled() {
if !selinux.GetEnabled() {
return nil
}

Expand All @@ -147,14 +147,14 @@ func Relabel(path string, fileLabel string, shared bool) error {
return nil
}

// GetPidLabel will return the label of the process running with the specified pid
func GetPidLabel(pid int) (string, error) {
return selinux.Getpidcon(pid)
// PidLabel will return the label of the process running with the specified pid
func PidLabel(pid int) (string, error) {
return selinux.PidLabel(pid)
}

// Init initialises the labeling system
func Init() {
selinux.SelinuxEnabled()
selinux.GetEnabled()
}

// ReserveLabel will record the fact that the MCS label has already been used.
Expand All @@ -165,11 +165,11 @@ func ReserveLabel(label string) error {
return nil
}

// UnreserveLabel will remove the reservation of the MCS label.
// ReleaseLabel will remove the reservation of the MCS label.
// This will allow InitLabels to use the MCS label in a newly created
// containers
func UnreserveLabel(label string) error {
selinux.FreeLxcContexts(label)
func ReleaseLabel(label string) error {
selinux.ReleaseLabel(label)
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions go-selinux/label/label_selinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestInit(t *testing.T) {
if !selinux.SelinuxEnabled() {
if !selinux.GetEnabled() {
return
}
var testNull []string
Expand All @@ -21,9 +21,9 @@ func TestInit(t *testing.T) {
t.Fatal(err)
}
testDisabled := []string{"disable"}
roMountLabel := GetROMountLabel()
roMountLabel := ROMountLabel()
if roMountLabel == "" {
t.Errorf("GetROMountLabel Failed")
t.Errorf("ROMountLabel Failed")
}
plabel, mlabel, err = InitLabels(testDisabled)
if err != nil {
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestDuplicateLabel(t *testing.T) {
}
}
func TestRelabel(t *testing.T) {
if !selinux.SelinuxEnabled() {
if !selinux.GetEnabled() {
return
}
testdir := "/tmp/test"
Expand Down
Loading

0 comments on commit ba1aefe

Please sign in to comment.