Skip to content

Commit

Permalink
Always show runner terms on rc creation
Browse files Browse the repository at this point in the history
Always show Runner Terms on resource creation
  • Loading branch information
jrahme-cci authored Dec 2, 2021
2 parents e367219 + c75b482 commit 5010eb7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 51 deletions.
24 changes: 3 additions & 21 deletions cmd/runner/resource_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ func newResourceClassCommand(o *runnerOpts, preRunE validator) *cobra.Command {
Args: cobra.ExactArgs(2),
PreRunE: preRunE,
RunE: func(_ *cobra.Command, args []string) error {
if err := presentTerms(args[0], o, cmd); err != nil {
return err
}
cmd.PrintErr(terms)

rc, err := o.r.CreateResourceClass(args[0], args[1])
if err != nil {
Expand Down Expand Up @@ -101,24 +99,8 @@ func appendResourceClass(table *tablewriter.Table, rc runner.ResourceClass) {

const terms = "If you have not already agreed to Runner Terms in a signed Order, " +
"then by continuing to install Runner, " +
"you are agreeing to CircleCI's Runner Terms which are found at: https://circleci.com/legal/runner-terms/.\n\n" +
"you are agreeing to CircleCI's Runner Terms which are found at: https://circleci.com/legal/runner-terms/.\n" +
"If you already agreed to Runner Terms in a signed Order, " +
"the Runner Terms in the signed Order supersede the Runner Terms in the web address above.\n\n" +
"the Runner Terms in the signed Order supersede the Runner Terms in the web address above.\n" +
"If you did not already agree to Runner Terms through a signed Order and do not agree to the Runner Terms in the web address above, " +
"please do not install or use Runner.\n\n"

func presentTerms(rc string, o *runnerOpts, cmd *cobra.Command) error {
ns, err := o.r.GetNamespaceByResourceClass(rc)
if err != nil {
return err
}
rcs, err := o.r.GetResourceClassesByNamespace(ns)
if err != nil {
return err
}
// Only present the terms on creation of the first resource class in a namespace
if len(rcs) == 0 {
cmd.PrintErr(terms)
}
return nil
}
30 changes: 0 additions & 30 deletions cmd/runner/resource_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ func Test_ResourceClass(t *testing.T) {
assert.Check(t, cmp.Equal(len(runner.tokens), 0))

assert.Check(t, cmp.Contains(stderr.String(), terms))
t.Run("don't show terms again", func(t *testing.T) {
stderr.Reset()

cmd.SetArgs([]string{
"create",
"my-namespace/my-second-resource-class",
"my-description",
})

err := cmd.Execute()
assert.NilError(t, err)

assert.Check(t, cmp.Equal(len(runner.resourceClasses), 2))
assert.Check(t, !strings.Contains(stderr.String(), terms))
})
})

t.Run("with default token", func(t *testing.T) {
Expand Down Expand Up @@ -89,21 +74,6 @@ func Test_ResourceClass(t *testing.T) {
assert.Check(t, cmp.Contains(out, "fake-token"))

assert.Check(t, cmp.Contains(stderr.String(), terms))
t.Run("don't show terms again", func(t *testing.T) {
stderr.Reset()

cmd.SetArgs([]string{
"create",
"my-namespace/my-second-resource-class",
"my-description",
})

err := cmd.Execute()
assert.NilError(t, err)

assert.Check(t, cmp.Equal(len(runner.resourceClasses), 2))
assert.Check(t, !strings.Contains(stderr.String(), terms))
})
})
})
}
Expand Down

0 comments on commit 5010eb7

Please sign in to comment.