Skip to content

Commit

Permalink
Add Drone commands for updating AD group membership (SumoLogic#60)
Browse files Browse the repository at this point in the history
* make a true cli

* update messages

* rename env vars

* remove codified defaults

* add add-user pipe

* golang img

* main.go

* non-alpine

* workstash

* update commans

* update files

* ugh python

* Delete associate_groups_to_azure_apps.ps1

* Delete existing-resources.tf

* Delete pyvenv.cfg

* wording fix

Co-authored-by: Mel Cone <mel.cone@nytimes.com>
  • Loading branch information
mlclmj and melmaliacone authored Aug 18, 2020
1 parent 8334ad6 commit 9a06351
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
82 changes: 81 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,88 @@ steps:
branch:
- main

---
kind: pipeline
type: docker
name: add-user

trigger:
event:
- promote
target:
- add-user

steps:
- name: add-user-to-group
image: golang:1.14
environment:
GOPROXY: direct
GOSUMDB: off
commands:
- cd tools/adutil
- go get
- go run main.go add
- name: notify
image: plugins/slack
settings:
channel: dv-observability
username: nytimes/dv-sumologic
template: >
{{#success build.status}}
Success: ${TRIGGER} added ${email} to the ${group} AD group.
{{else}}
Failure: ${TRIGGER} attempted to add ${email} to the ${group} AD group.
{{/success}}
environment:
SLACK_WEBHOOK:
from_secret: slack_webhook
when:
status:
- success
- failure

---
kind: pipeline
type: docker
name: del-user

trigger:
event:
- promote
target:
- del-user

steps:
- name: remove-user-from-group
image: golang:1.14
environment:
GOPROXY: direct
GOSUMDB: off
commands:
- cd tools/adutil
- go get
- go run main.go remove
- name: notify
image: plugins/slack
settings:
channel: dv-observability
username: nytimes/dv-sumologic
template: >
{{#success build.status}}
Success: ${TRIGGER} removed ${email} from the ${group} AD group.
{{else}}
Failure: ${TRIGGER} attempted to remove ${email} from the ${group} AD group.
{{/success}}
environment:
SLACK_WEBHOOK:
from_secret: slack_webhook
when:
status:
- success
- failure

---
kind: signature
hmac: ef97f53ca47dddc62b35cc2a55fac99c101412cecea60de0468ad028696d6b69
hmac: 39fd1cab314c22ba9e4a203f3d94b9a4479de21621b231c20f9ed96a432d66d9

...
20 changes: 10 additions & 10 deletions tools/adutil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func main() {
Name: "group",
Required: true,
Usage: "The name (CN) of the AD group to add to.",
EnvVars: []string{"AD_GROUP"},
EnvVars: []string{"group"},
},
&cli.StringFlag{
Name: "user",
Name: "email",
Required: true,
Usage: "The email of the user to add.",
EnvVars: []string{"AD_USER_EMAIL"},
EnvVars: []string{"email"},
},
},
},
Expand All @@ -43,14 +43,14 @@ func main() {
&cli.StringFlag{
Name: "group",
Required: true,
Usage: "The name (CN) of the AD group to add to.",
EnvVars: []string{"AD_GROUP"},
Usage: "The name (CN) of the AD group to remove from.",
EnvVars: []string{"group"},
},
&cli.StringFlag{
Name: "user_email",
Name: "email",
Required: true,
Usage: "The email of the user to add.",
EnvVars: []string{"AD_USER_EMAIL"},
Usage: "The email of the user to remove from.",
EnvVars: []string{"email"},
},
},
},
Expand Down Expand Up @@ -132,7 +132,7 @@ func addUser(ctx *cli.Context) error {
// add a user
return ad.AddGroupMember(
ctx.String("group"),
ctx.String("user"),
ctx.String("email"),
)
}

Expand All @@ -143,7 +143,7 @@ func removeUser(ctx *cli.Context) error {
// remove a user
return ad.RemoveGroupMember(
ctx.String("group"),
ctx.String("user"),
ctx.String("email"),
)
}

Expand Down

0 comments on commit 9a06351

Please sign in to comment.