1
1
/* eslint-disable no-console */
2
+ 'use strict' ;
2
3
4
+ const typedefs = require ( './typedefs' ) ;
5
+
6
+ /**
7
+ * Find users who currently belong to the organization, but not who are not
8
+ * expected by config.
9
+ *
10
+ * @param {string[] } configured - An array of usernames expected to exist in the org
11
+ * @param {string[] } retrieved - An array of usernames actually belong to the org currently
12
+ * @returns {string[] } An array of usernames which are not expected to belong to the org
13
+ */
3
14
function findUndocumentedMembers ( configured , retrieved ) {
4
15
const undocumented = retrieved . filter ( member => ! configured . includes ( member ) ) ;
5
16
console . log ( `${ undocumented . length } undocumented memberships found: ` , undocumented ) ;
6
17
return undocumented ;
7
18
}
8
19
20
+ /**
21
+ * Find users who are expected by config, but who do not (yet) belong to the
22
+ * organization.
23
+ *
24
+ * @param {string[] } configured - An array of usernames expected to exist in the org
25
+ * @param {string[] } retrieved - An array of usernames actually belong to the org currently
26
+ * @returns {string[] } An array of usernames which are expected to belong to the org
27
+ */
9
28
function findNewMembers ( configured , retrieved ) {
10
29
const newMembers = configured . filter ( member => ! retrieved . includes ( member ) ) ;
11
30
console . log ( `${ newMembers . length } new memberships requested: ` , newMembers ) ;
12
31
return newMembers ;
13
32
}
14
33
34
+ /**
35
+ * Find users who are currently admins of the org, but should not be, according
36
+ * to config.
37
+ *
38
+ * @param {object.<string, string> } configured - Configured usernames and their associated roles
39
+ * @param {typedefs.MemberSet } retrieved - User list retrieved from GitHub
40
+ * @returns {string[] } An array of usernames who are admins, but should not be
41
+ */
15
42
function findDemotions ( configured , retrieved ) {
16
43
const demotions = Object . keys ( retrieved ) . filter (
17
44
( member ) => retrieved [ member ] . role === 'ADMIN' && configured [ member ] === 'MEMBER'
@@ -20,6 +47,13 @@ function findDemotions(configured, retrieved) {
20
47
return demotions ;
21
48
}
22
49
50
+ /**
51
+ * Find users who are currently regular members of the org, but are configured as admins
52
+ *
53
+ * @param {object.<string, string> } configured - Configured usernames and their associated roles
54
+ * @param {typedefs.MemberSet } retrieved - User list retrieved from GitHub
55
+ * @returns {string[] } An array of usernames who are not admins, but should be
56
+ */
23
57
function findPromotions ( configured , retrieved ) {
24
58
const promotions = Object . keys ( configured ) . filter (
25
59
( member ) => configured [ member ] === 'ADMIN' && retrieved [ member ] && retrieved [ member ] . role === 'MEMBER'
@@ -28,12 +62,24 @@ function findPromotions(configured, retrieved) {
28
62
return promotions ;
29
63
}
30
64
65
+ /**
66
+ * Find org members who do not have two-factor authentication enabled
67
+ *
68
+ * @param {typedefs.MemberSet } members - User list retrieved from GitHub
69
+ * @returns {string[] } An array of usernames who are 2FA violators.
70
+ */
31
71
function validateTwoFactor ( members ) {
32
72
const violators = Object . keys ( members ) . filter ( ( member ) => members [ member ] . twoFactorAuth === false ) ;
33
73
console . log ( `${ violators . length } two factor auth violators found: ` , violators ) ;
34
74
return violators ;
35
75
}
36
76
77
+ /**
78
+ * Ensure that the org's current settings match those expected by the config
79
+ *
80
+ * @param {object.<string, *> } organization - The full collection of org settings collected from GitHub
81
+ * @param {object.<string, *> } config - The full collection of org settings expected by config
82
+ */
37
83
function validateOrgSettings ( organization , config ) {
38
84
let failed = false ;
39
85
for ( const key of Object . keys ( config ) ) {
0 commit comments