Skip to content

Commit

Permalink
Refactor tbot (#12855)
Browse files Browse the repository at this point in the history
* start refactoring tbot to have a core struct

* refactor tbot into lib/

* move `tbot` subpackages to `lib/tbot`

* remove mutex pointer

* move `tshwrap` to `lib/` from `/tool/tbot/`

* move new template ssh client render test to lib/

* address pr feedback

* add request changed
  • Loading branch information
strideynet committed Jun 1, 2022
1 parent a33903a commit f6ae502
Show file tree
Hide file tree
Showing 38 changed files with 480 additions and 366 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/client"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
"gopkg.in/yaml.v3"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/client/identityfile"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/client/identityfile"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/client/identityfile"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import (
"github.com/coreos/go-semver/semver"
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/trace"
"golang.org/x/crypto/ssh"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/fixtures"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/tbot/botfs"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/teleport/lib/utils/golden"
"github.com/gravitational/teleport/tool/tbot/botfs"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/stretchr/testify/require"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/lib/client/identityfile"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
"gopkg.in/yaml.v3"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/auth"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package config

import (
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/trace"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"path"
"path/filepath"

"github.com/gravitational/teleport/tool/tbot/botfs"
"github.com/gravitational/teleport/lib/tbot/botfs"
"github.com/gravitational/trace"
"gopkg.in/yaml.v3"
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package main
package tbot

import (
"bytes"
"context"
"testing"

"github.com/gravitational/teleport/api/identityfile"
"github.com/gravitational/teleport/lib/tbot/config"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tbot/testhelpers"
"github.com/gravitational/teleport/lib/tlsca"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/tool/tbot/config"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/teleport/tool/tbot/testhelpers"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -94,13 +94,15 @@ func TestDefaultTemplateRendering(t *testing.T) {
botConfig := testhelpers.MakeMemoryBotConfig(t, fc, botParams)
storage, err := botConfig.Storage.GetDestination()
require.NoError(t, err)
b := New(botConfig, utils.NewLoggerForTests(), nil)

ident, err := getIdentityFromToken(botConfig)
ident, err := b.getIdentityFromToken()
require.NoError(t, err)

botClient := testhelpers.MakeBotAuthClient(t, fc, ident)
b._ident = ident
b._client = botClient

_, _, err = renew(context.Background(), botConfig, botClient, ident, storage)
err = b.renew(context.Background(), storage)
require.NoError(t, err)

dest := botConfig.Destinations[0]
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/gravitational/teleport/api/types"
apiutils "github.com/gravitational/teleport/api/utils"
apisshutils "github.com/gravitational/teleport/api/utils/sshutils"
"github.com/gravitational/teleport/lib/tbot/destination"
"github.com/gravitational/teleport/lib/tlsca"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/tool/tbot/destination"
"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions tool/tbot/identity_test.go → lib/tbot/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Note: this lives in main to avoid import cycles since this depends on the
// Note: this lives in tbot to avoid import cycles since this depends on the
// config/identity/destinations packages.

package main
package tbot

import (
"testing"

"github.com/gravitational/teleport/tool/tbot/config"
"github.com/gravitational/teleport/tool/tbot/identity"
"github.com/gravitational/teleport/lib/tbot/config"
"github.com/gravitational/teleport/lib/tbot/identity"
"github.com/gravitational/trace"
"github.com/stretchr/testify/require"
)
Expand Down
Loading

0 comments on commit f6ae502

Please sign in to comment.