2021-03-04 20:44:49 -05:00
|
|
|
package registry
|
|
|
|
|
|
|
|
|
|
import (
|
2021-08-05 01:12:10 -04:00
|
|
|
"bytes"
|
2021-03-04 20:44:49 -05:00
|
|
|
"errors"
|
2023-12-22 01:59:22 +08:00
|
|
|
"io"
|
2021-03-04 20:44:49 -05:00
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/dokku/dokku/plugins/common"
|
|
|
|
|
)
|
|
|
|
|
|
2021-03-19 16:31:07 -04:00
|
|
|
// CommandLogin logs a user into the specified server
|
2021-03-04 20:44:49 -05:00
|
|
|
func CommandLogin(server string, username string, password string, passwordStdin bool) error {
|
|
|
|
|
if passwordStdin {
|
2023-12-22 01:59:22 +08:00
|
|
|
stdin, err := io.ReadAll(os.Stdin)
|
2021-03-04 20:44:49 -05:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
password = strings.TrimSpace(string(stdin))
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 22:16:40 -05:00
|
|
|
if server == "" {
|
|
|
|
|
return errors.New("Missing server argument")
|
|
|
|
|
}
|
|
|
|
|
if username == "" {
|
|
|
|
|
return errors.New("Missing username argument")
|
|
|
|
|
}
|
|
|
|
|
if password == "" {
|
|
|
|
|
return errors.New("Missing password argument")
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 20:44:49 -05:00
|
|
|
command := []string{
|
|
|
|
|
common.DockerBin(),
|
|
|
|
|
"login",
|
|
|
|
|
"--username",
|
|
|
|
|
username,
|
|
|
|
|
"--password-stdin",
|
|
|
|
|
server,
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-05 01:12:10 -04:00
|
|
|
buffer := bytes.Buffer{}
|
|
|
|
|
buffer.Write([]byte(password + "\n"))
|
|
|
|
|
|
2021-03-04 20:44:49 -05:00
|
|
|
loginCmd := common.NewShellCmd(strings.Join(command, " "))
|
2021-08-05 01:12:10 -04:00
|
|
|
loginCmd.Command.Stdin = &buffer
|
2021-03-04 20:44:49 -05:00
|
|
|
if !loginCmd.Execute() {
|
|
|
|
|
return errors.New("Failed to log into registry")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandReport displays a registry report for one or more apps
|
|
|
|
|
func CommandReport(appName string, format string, infoFlag string) error {
|
|
|
|
|
if len(appName) == 0 {
|
|
|
|
|
apps, err := common.DokkuApps()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
for _, appName := range apps {
|
|
|
|
|
if err := ReportSingleApp(appName, format, infoFlag); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ReportSingleApp(appName, format, infoFlag)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CommandSet set or clear a registry property for an app
|
|
|
|
|
func CommandSet(appName string, property string, value string) error {
|
|
|
|
|
common.CommandPropertySet("registry", appName, property, value, DefaultProperties, GlobalProperties)
|
|
|
|
|
return nil
|
|
|
|
|
}
|