-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first draft of install command * additional improvements to initialization for bundling compatibility * remove unnecessary extra parameter in repo collection * add appropriate absolute path handling to repo itself * working repo removal command * add test case to verify it all can work with no config file * usage improvement, bugfix, add test case to ensure that everything works without config * output formatting improvements and fixing pointer bugs * appease pre-commit * fix typo * bugfix config compatibility with test cases * fix spelling error * remove underscores * remove deprecated library usage * remove additional underscore
- Loading branch information
Showing
24 changed files
with
561 additions
and
130 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
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,35 @@ | ||
/* | ||
Copyright © 2023-present, Meta Platforms, Inc. and affiliates | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildInstallCommand() *cobra.Command { | ||
installCmd := &cobra.Command{ | ||
Use: "install", | ||
Short: "install various types of resources used by TTPForge", | ||
Long: "For now, you just want to use the 'ttpforge install repo' subcommand", | ||
TraverseChildren: true, | ||
} | ||
installCmd.AddCommand(buildInstallRepoCommand()) | ||
return installCmd | ||
} |
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,67 @@ | ||
/* | ||
Copyright © 2023-present, Meta Platforms, Inc. and affiliates | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"path/filepath" | ||
|
||
"github.com/facebookincubator/ttpforge/pkg/logging" | ||
"github.com/facebookincubator/ttpforge/pkg/repos" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildInstallRepoCommand() *cobra.Command { | ||
var newRepoSpec repos.Spec | ||
installRepoCommand := &cobra.Command{ | ||
Use: "repo --name repo_name [repo_url]", | ||
Short: "install a new repository of TTPs for use by TTPForge", | ||
TraverseChildren: true, | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
u, err := url.ParseRequestURI(args[0]) | ||
if err != nil { | ||
return fmt.Errorf("argument must be a valid URL - '%v' is not", args[0]) | ||
} | ||
newRepoSpec.Git.URL = u.String() | ||
newRepoSpec.Path = filepath.Join("repos", newRepoSpec.Name) | ||
Conf.RepoSpecs = append(Conf.RepoSpecs, newRepoSpec) | ||
_, err = Conf.loadRepoCollection() | ||
if err != nil { | ||
return fmt.Errorf("failed to add new repo: %v", err) | ||
} | ||
|
||
err = Conf.save() | ||
if err != nil { | ||
return fmt.Errorf("failed to save updated configuration: %v", err) | ||
} | ||
logging.L().Infof("New repository successfully installed!") | ||
logging.L().Infof("Name: %v", newRepoSpec.Name) | ||
logging.L().Infof("Path: %v", newRepoSpec.Path) | ||
logging.L().Infof("List TTPs from your new repository with the command:") | ||
logging.L().Infof("\tttpforge list ttps --repo %v", newRepoSpec.Name) | ||
return nil | ||
}, | ||
} | ||
installRepoCommand.PersistentFlags().StringVar(&newRepoSpec.Name, "name", "", "The name to use for the new repository") | ||
_ = installRepoCommand.MarkPersistentFlagRequired("name") | ||
return installRepoCommand | ||
} |
File renamed without changes.
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 @@ | ||
/* | ||
Copyright © 2023-present, Meta Platforms, Inc. and affiliates | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package cmd_test | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/facebookincubator/ttpforge/cmd" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestListTTPs(t *testing.T) { | ||
testConfigFilePath := filepath.Join("test-resources", "test-config.yaml") | ||
testCases := []struct { | ||
name string | ||
ttpRef string | ||
wantError bool | ||
}{ | ||
{ | ||
name: "no-filter", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
rc := cmd.BuildRootCommand() | ||
rc.SetArgs([]string{"list", "ttps", "-c", testConfigFilePath}) | ||
err := rc.Execute() | ||
if tc.wantError { | ||
require.Error(t, err) | ||
} else { | ||
require.NoError(t, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright © 2023-present, Meta Platforms, Inc. and affiliates | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func buildRemoveCommand() *cobra.Command { | ||
removeCmd := &cobra.Command{ | ||
Use: "remove", | ||
Short: "remove (uninstall) various types of resources used by TTPForge", | ||
Long: "For now, you just want to use the 'ttpforge remove repo' subcommand", | ||
TraverseChildren: true, | ||
} | ||
removeCmd.AddCommand(buildRemoveRepoCommand()) | ||
return removeCmd | ||
} |
Oops, something went wrong.