Skip to content
This repository has been archived by the owner on Feb 20, 2020. It is now read-only.

Commit

Permalink
Merge 51dfc0c into 5e4ea97
Browse files Browse the repository at this point in the history
  • Loading branch information
petemoore committed Aug 6, 2018
2 parents 5e4ea97 + 51dfc0c commit ae28f3d
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 51 deletions.
12 changes: 12 additions & 0 deletions all-unix-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ properties:
items:
title: Mount
"$ref": "#/definitions/mount"
osGroups:
type: array
title: OS Groups
description: |-
A list of OS Groups that the task user should be a member of. Not yet implemented on
non-Windows platforms, therefore this optional property may only be an empty array if
provided.
Since: generic-worker 6.0.0
items:
type: string
maxItems: 0
supersederUrl:
type: string
title: Superseder URL
Expand Down
16 changes: 16 additions & 0 deletions generated_all-unix-style.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ type (
// based on exit code of task commands.
OnExitStatus ExitCodeHandling `json:"onExitStatus,omitempty"`

// A list of OS Groups that the task user should be a member of. Not yet implemented on
// non-Windows platforms, therefore this optional property may only be an empty array if
// provided.
//
// Since: generic-worker 6.0.0
OSGroups []string `json:"osGroups,omitempty"`

// URL of a service that can indicate tasks superseding this one; the current `taskId`
// will be appended as a query argument `taskId`. The service should return an object with
// a `supersedes` key containing a list of `taskId`s, including the supplied `taskId`. The
Expand Down Expand Up @@ -572,6 +579,15 @@ func taskPayloadSchema() string {
"title": "Exit code handling",
"type": "object"
},
"osGroups": {
"description": "A list of OS Groups that the task user should be a member of. Not yet implemented on\nnon-Windows platforms, therefore this optional property may only be an empty array if\nprovided.\n\nSince: generic-worker 6.0.0",
"items": {
"type": "string"
},
"maxItems": 0,
"title": "OS Groups",
"type": "array"
},
"supersederUrl": {
"description": "URL of a service that can indicate tasks superseding this one; the current ` + "`" + `taskId` + "`" + `\nwill be appended as a query argument ` + "`" + `taskId` + "`" + `. The service should return an object with\na ` + "`" + `supersedes` + "`" + ` key containing a list of ` + "`" + `taskId` + "`" + `s, including the supplied ` + "`" + `taskId` + "`" + `. The\ntasks should be ordered such that each task supersedes all tasks appearing later in the\nlist.\n\nSee [superseding](https://docs.taskcluster.net/reference/platform/taskcluster-queue/docs/superseding) for more detail.\n\nSince: generic-worker 10.2.2",
"format": "uri",
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func initialiseFeatures() (err error) {
Features = []Feature{
&LiveLogFeature{},
&TaskclusterProxyFeature{},
&OSGroupsFeature{},
&MountsFeature{},
&SupersedeFeature{},
}
Expand Down
52 changes: 52 additions & 0 deletions os_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"github.com/taskcluster/taskcluster-base-go/scopes"
)

// one instance overall - represents feature
type OSGroupsFeature struct {
}

// one instance per task
type OSGroups struct {
Task *TaskRun
// keep track of which groups we successfully update
AddedGroups []string
}

func (feature *OSGroupsFeature) Name() string {
return "OS Groups"
}

func (feature *OSGroupsFeature) Initialise() error {
return nil
}

func (feature *OSGroupsFeature) PersistState() error {
return nil
}

func (feature *OSGroupsFeature) IsEnabled(task *TaskRun) bool {
// always enabled, since scopes protect usage at a group level
return true
}

func (feature *OSGroupsFeature) NewTaskFeature(task *TaskRun) TaskFeature {
osGroups := &OSGroups{
Task: task,
}
return osGroups
}

func (osGroups *OSGroups) ReservedArtifacts() []string {
return []string{}
}

func (osGroups *OSGroups) RequiredScopes() scopes.Required {
requiredScopes := make([]string, len(osGroups.Task.Payload.OSGroups), len(osGroups.Task.Payload.OSGroups))
for i, osGroup := range osGroups.Task.Payload.OSGroups {
requiredScopes[i] = "generic-worker:os-group:" + config.ProvisionerID + "/" + config.WorkerType + "/" + osGroup
}
return scopes.Required{requiredScopes}
}
18 changes: 18 additions & 0 deletions os_groups_all-unix-style.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build !windows

package main

import (
"fmt"
"runtime"
)

func (osGroups *OSGroups) Start() *CommandExecutionError {
if len(osGroups.Task.Payload.OSGroups) > 0 {
return MalformedPayloadError(fmt.Errorf("osGroups feature is not supported on platform %v - please modify task definition and try again", runtime.GOOS))
}
return nil
}

func (osGroups *OSGroups) Stop(err *ExecutionErrors) {
}
42 changes: 42 additions & 0 deletions os_groups_all-unix-style_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main

import (
"io/ioutil"
"path/filepath"
"strings"
"testing"
)

func TestEmptyOSGroups(t *testing.T) {
defer setup(t)()
payload := GenericWorkerPayload{
Command: helloGoodbye(),
MaxRunTime: 30,
OSGroups: []string{},
}
td := testTask(t)

_ = submitAndAssert(t, td, payload, "completed", "completed")
}

func TestNonEmptyOSGroups(t *testing.T) {
defer setup(t)()
payload := GenericWorkerPayload{
Command: helloGoodbye(),
MaxRunTime: 30,
OSGroups: []string{"abc"},
}
td := testTask(t)

_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")

// check log mentions issue
bytes, err := ioutil.ReadFile(filepath.Join(taskContext.TaskDir, logPath))
if err != nil {
t.Fatalf("Error when trying to read log file: %v", err)
}
logtext := string(bytes)
if !strings.Contains(logtext, "- osGroups: Array must have at most 0 items") {
t.Fatalf("Was expecting log file to contain '- osGroups: Array must have at most 0 items' but it doesn't")
}
}
49 changes: 0 additions & 49 deletions os_groups_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,8 @@ package main

import (
"fmt"

"github.com/taskcluster/taskcluster-base-go/scopes"
)

// one instance overall - represents feature
type OSGroupsFeature struct {
}

// one instance per task
type OSGroups struct {
Task *TaskRun
// keep track of which groups we successfully update
AddedGroups []string
}

func (feature *OSGroupsFeature) Name() string {
return "OS Groups"
}

func (feature *OSGroupsFeature) Initialise() error {
return nil
}

func (feature *OSGroupsFeature) PersistState() error {
return nil
}

func (feature *OSGroupsFeature) IsEnabled(task *TaskRun) bool {
// always enabled, since scopes protect usage at a group level
return true
}

func (feature *OSGroupsFeature) NewTaskFeature(task *TaskRun) TaskFeature {
osGroups := &OSGroups{
Task: task,
}
return osGroups
}

func (osGroups *OSGroups) ReservedArtifacts() []string {
return []string{}
}

func (osGroups *OSGroups) RequiredScopes() scopes.Required {
requiredScopes := make([]string, len(osGroups.Task.Payload.OSGroups), len(osGroups.Task.Payload.OSGroups))
for i, osGroup := range osGroups.Task.Payload.OSGroups {
requiredScopes[i] = "generic-worker:os-group:" + config.ProvisionerID + "/" + config.WorkerType + "/" + osGroup
}
return scopes.Required{requiredScopes}
}

func (osGroups *OSGroups) Start() *CommandExecutionError {
groups := osGroups.Task.Payload.OSGroups
if len(groups) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion os_groups_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestMissingScopesOSGroups(t *testing.T) {
defer setup(t)()
payload := GenericWorkerPayload{
Command: helloGoodbye(),
MaxRunTime: 1,
MaxRunTime: 30,
OSGroups: []string{"abc", "def"},
}
td := testTask(t)
Expand Down
1 change: 0 additions & 1 deletion plat_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ type TaskContext struct {
func platformFeatures() []Feature {
return []Feature{
&RDPFeature{},
&OSGroupsFeature{},
&RunAsAdministratorFeature{}, // depends on (must appear later in list than) OSGroups feature
}
}
Expand Down

0 comments on commit ae28f3d

Please sign in to comment.