@@ -3,7 +3,6 @@ package sync
3
3
import (
4
4
"errors"
5
5
"fmt"
6
- "io"
7
6
"os"
8
7
9
8
"github.com/spf13/cobra"
@@ -14,13 +13,12 @@ import (
14
13
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
15
14
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
16
15
16
+ userv1client "github.com/openshift/client-go/user/clientset/versioned/typed/user/v1"
17
17
"github.com/openshift/origin/pkg/cmd/server/apis/config"
18
18
"github.com/openshift/origin/pkg/cmd/server/apis/config/validation/ldap"
19
19
"github.com/openshift/origin/pkg/oauthserver/ldaputil"
20
20
"github.com/openshift/origin/pkg/oauthserver/ldaputil/ldapclient"
21
21
"github.com/openshift/origin/pkg/oc/lib/groupsync"
22
- userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
23
- usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
24
22
)
25
23
26
24
const PruneRecommendedName = "prune"
@@ -53,92 +51,73 @@ var (
53
51
54
52
type PruneOptions struct {
55
53
// Config is the LDAP sync config read from file
56
- Config * config.LDAPSyncConfig
54
+ Config * config.LDAPSyncConfig
55
+ ConfigFile string
57
56
58
57
// Whitelist are the names of OpenShift group or LDAP group UIDs to use for syncing
59
- Whitelist []string
58
+ Whitelist []string
59
+ WhitelistFile string
60
60
61
61
// Blacklist are the names of OpenShift group or LDAP group UIDs to exclude
62
- Blacklist []string
62
+ Blacklist []string
63
+ BlacklistFile string
63
64
64
65
// Confirm determines whether or not to write to OpenShift
65
66
Confirm bool
66
67
67
68
// GroupInterface is the interface used to interact with OpenShift Group objects
68
- GroupInterface usertypedclient .GroupInterface
69
+ GroupInterface userv1client .GroupInterface
69
70
70
- // Stderr is the writer to write warnings and errors to
71
- Stderr io.Writer
72
-
73
- // Out is the writer to write output to
74
- Out io.Writer
71
+ genericclioptions.IOStreams
75
72
}
76
73
77
- func NewPruneOptions () * PruneOptions {
74
+ func NewPruneOptions (streams genericclioptions. IOStreams ) * PruneOptions {
78
75
return & PruneOptions {
79
- Stderr : os .Stderr ,
80
76
Whitelist : []string {},
77
+ IOStreams : streams ,
81
78
}
82
79
}
83
80
84
81
func NewCmdPrune (name , fullName string , f kcmdutil.Factory , streams genericclioptions.IOStreams ) * cobra.Command {
85
- options := NewPruneOptions ()
86
- options .Out = streams .Out
87
-
88
- whitelistFile := ""
89
- blacklistFile := ""
90
- configFile := ""
91
-
82
+ o := NewPruneOptions (streams )
92
83
cmd := & cobra.Command {
93
84
Use : fmt .Sprintf ("%s [WHITELIST] [--whitelist=WHITELIST-FILE] [--blacklist=BLACKLIST-FILE] --sync-config=CONFIG-SOURCE" , name ),
94
85
Short : "Remove old OpenShift groups referencing missing records on an external provider" ,
95
86
Long : pruneLong ,
96
87
Example : fmt .Sprintf (pruneExamples , fullName ),
97
- Run : func (c * cobra.Command , args []string ) {
98
- kcmdutil .CheckErr (options .Complete (whitelistFile , blacklistFile , configFile , args , f ))
99
- kcmdutil .CheckErr (options .Validate ())
100
- err := options .Run (c , f )
101
- if err != nil {
102
- if aggregate , ok := err .(kerrs.Aggregate ); ok {
103
- for _ , err := range aggregate .Errors () {
104
- fmt .Printf ("%s\n " , err )
105
- }
106
- os .Exit (1 )
107
- }
108
- }
109
- kcmdutil .CheckErr (err )
88
+ Run : func (cmd * cobra.Command , args []string ) {
89
+ kcmdutil .CheckErr (o .Complete (f , cmd , args ))
90
+ kcmdutil .CheckErr (o .Validate ())
91
+ kcmdutil .CheckErr (o .Run ())
110
92
},
111
93
}
112
94
113
- cmd .Flags ().StringVar (& whitelistFile , "whitelist" , whitelistFile , "path to the group whitelist file" )
95
+ cmd .Flags ().StringVar (& o . WhitelistFile , "whitelist" , o . WhitelistFile , "path to the group whitelist file" )
114
96
cmd .MarkFlagFilename ("whitelist" , "txt" )
115
- cmd .Flags ().StringVar (& blacklistFile , "blacklist" , whitelistFile , "path to the group blacklist file" )
97
+ cmd .Flags ().StringVar (& o . BlacklistFile , "blacklist" , o . BlacklistFile , "path to the group blacklist file" )
116
98
cmd .MarkFlagFilename ("blacklist" , "txt" )
117
99
// TODO(deads): enable this once we're able to support string slice elements that have commas
118
- // cmd.Flags().StringSliceVar(&options.Blacklist, "blacklist-group", options.Blacklist, "group to blacklist")
119
-
120
- cmd .Flags ().StringVar (& configFile , "sync-config" , configFile , "path to the sync config" )
100
+ // cmd.Flags().StringSliceVar(&o.Blacklist, "blacklist-group", o.Blacklist, "group to blacklist")
101
+ cmd .Flags ().StringVar (& o .ConfigFile , "sync-config" , o .ConfigFile , "path to the sync config" )
121
102
cmd .MarkFlagFilename ("sync-config" , "yaml" , "yml" )
122
-
123
- cmd .Flags ().BoolVar (& options .Confirm , "confirm" , false , "if true, modify OpenShift groups; if false, display groups" )
103
+ cmd .Flags ().BoolVar (& o .Confirm , "confirm" , o .Confirm , "if true, modify OpenShift groups; if false, display groups" )
124
104
125
105
return cmd
126
106
}
127
107
128
- func (o * PruneOptions ) Complete (whitelistFile , blacklistFile , configFile string , args []string , f kcmdutil. Factory ) error {
108
+ func (o * PruneOptions ) Complete (f kcmdutil. Factory , cmd * cobra. Command , args []string ) error {
129
109
var err error
130
-
131
- o .Config , err = decodeSyncConfigFromFile (configFile )
110
+ o .Config , err = decodeSyncConfigFromFile (o .ConfigFile )
132
111
if err != nil {
133
112
return err
134
113
}
135
114
136
- o .Whitelist , err = buildOpenShiftGroupNameList (args , whitelistFile , o .Config .LDAPGroupUIDToOpenShiftGroupNameMapping )
115
+ o .Whitelist , err = buildOpenShiftGroupNameList (args , o . WhitelistFile , o .Config .LDAPGroupUIDToOpenShiftGroupNameMapping )
137
116
if err != nil {
138
117
return err
139
118
}
140
119
141
- o .Blacklist , err = buildOpenShiftGroupNameList ([]string {}, blacklistFile , o .Config .LDAPGroupUIDToOpenShiftGroupNameMapping )
120
+ o .Blacklist , err = buildOpenShiftGroupNameList ([]string {}, o . BlacklistFile , o .Config .LDAPGroupUIDToOpenShiftGroupNameMapping )
142
121
if err != nil {
143
122
return err
144
123
}
@@ -147,11 +126,11 @@ func (o *PruneOptions) Complete(whitelistFile, blacklistFile, configFile string,
147
126
if err != nil {
148
127
return err
149
128
}
150
- userClient , err := userclientinternal .NewForConfig (clientConfig )
129
+ userClient , err := userv1client .NewForConfig (clientConfig )
151
130
if err != nil {
152
131
return err
153
132
}
154
- o .GroupInterface = userClient .User (). Groups ()
133
+ o .GroupInterface = userClient .Groups ()
155
134
156
135
return nil
157
136
}
@@ -170,7 +149,7 @@ func (o *PruneOptions) Validate() error {
170
149
171
150
// Run creates the GroupSyncer specified and runs it to sync groups
172
151
// the arguments are only here because its the only way to get the printer we need
173
- func (o * PruneOptions ) Run (cmd * cobra. Command , f kcmdutil. Factory ) error {
152
+ func (o * PruneOptions ) Run () error {
174
153
bindPassword , err := config .ResolveStringValue (o .Config .BindPassword )
175
154
if err != nil {
176
155
return err
@@ -236,7 +215,7 @@ func (o *PruneOptions) GetBlacklist() []string {
236
215
return o .Blacklist
237
216
}
238
217
239
- func (o * PruneOptions ) GetClient () usertypedclient .GroupInterface {
218
+ func (o * PruneOptions ) GetClient () userv1client .GroupInterface {
240
219
return o .GroupInterface
241
220
}
242
221
0 commit comments