-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure we don't break the role editor for some preset roles
Adds a test that verifies that the built-in roles, as pulled from our Go source codes, can be unambiguously translated to the standard editor model. Also adds one currently missing field (`github_organizations`).
- Loading branch information
Showing
12 changed files
with
318 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Teleport | ||
// Copyright (C) 2025 Gravitational, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
// A tool that dumps preset roles in a temporary JSON file that will later be | ||
// used in TypeScript tests to make sure that the standard role editor can | ||
// unambiguously represent a preset role. | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
|
||
"github.com/gravitational/teleport/api/types" | ||
"github.com/gravitational/teleport/lib/auth" | ||
"github.com/gravitational/teleport/lib/services" | ||
) | ||
|
||
func main() { | ||
roles := auth.GetPresetRoles() | ||
rolesByName := make(map[string]types.Role) | ||
for _, role := range roles { | ||
services.CheckAndSetDefaults(role) | ||
rolesByName[role.GetName()] = role | ||
} | ||
|
||
rolesJSON, err := json.Marshal(rolesByName) | ||
if err != nil { | ||
log.Fatalf("Could not marshal preset roles as JSON: %s", err) | ||
} | ||
|
||
err = os.MkdirAll("./tmp", 0755) | ||
if err != nil { | ||
log.Fatalf("Could not create the ./tmp directory: %s", err) | ||
} | ||
|
||
if err = os.WriteFile("./tmp/preset-roles.json", rolesJSON, 0744); err != nil { | ||
log.Fatalf("Could not write JSON for preset roles: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.