Compare commits

...
7 Commits
10 changed files with 59 additions and 96 deletions

No files matched your search

+25
View File
@@ -1,5 +1,30 @@
## Changelog
### Version [2.1.3](https://github.com/majd/ipatool/releases/tag/v2.1.3)
- Fixed a bug where temporary files were not removed after downloading the app package.
- Fixed a bug where the `--keychain-passphrase` flag was marked as invalid.
### Version [2.1.2](https://github.com/majd/ipatool/releases/tag/v2.1.2)
- `FileBackend` keyring is now used when other options are not available.
### Version [2.1.1](https://github.com/majd/ipatool/releases/tag/v2.1.1)
- Fixed an issue when creating the config directory for the tool.
### Version [2.1.0](https://github.com/majd/ipatool/releases/tag/v2.1.0)
- Implemented `Lookup` API.
- Implemented `AccountInfo` API.
- Implemented `ReplicateSinf` API.
- Added storefront code for Georgia (GE).
- Build version is now set using linker flags.
- Refactored API interfaces.
- Improved tests for http package.
- Integrated `golangci-lint` linter.
- Added v2 suffix to module path.
### Version [2.0.3](https://github.com/majd/ipatool/releases/tag/v2.0.3)
- Added support for downloading Apple Arcade games.
-5
View File
@@ -8,7 +8,6 @@ import (
"strings"
"time"
"github.com/99designs/keyring"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/majd/ipatool/v2/pkg/util"
@@ -22,10 +21,6 @@ func authCmd() *cobra.Command {
Short: "Authenticate with the App Store",
}
if keyringBackendType() == keyring.FileBackend {
cmd.PersistentFlags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
cmd.AddCommand(loginCmd())
cmd.AddCommand(infoCmd())
cmd.AddCommand(revokeCmd())
+17 -34
View File
@@ -19,7 +19,6 @@ import (
"github.com/majd/ipatool/v2/pkg/util/operatingsystem"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"golang.org/x/term"
)
@@ -27,13 +26,12 @@ var dependencies = Dependencies{}
var keychainPassphrase string
type Dependencies struct {
Logger log.Logger
OS operatingsystem.OperatingSystem
Machine machine.Machine
CookieJar http.CookieJar
Keychain keychain.Keychain
AppStore appstore.AppStore
KeyringBackendType keyring.BackendType
Logger log.Logger
OS operatingsystem.OperatingSystem
Machine machine.Machine
CookieJar http.CookieJar
Keychain keychain.Keychain
AppStore appstore.AppStore
}
// newLogger returns a new logger instance.
@@ -62,10 +60,12 @@ func newCookieJar(machine machine.Machine) http.CookieJar {
}
// newKeychain returns a new keychain instance.
func newKeychain(machine machine.Machine, logger log.Logger, backendType keyring.BackendType, interactive bool) keychain.Keychain {
func newKeychain(machine machine.Machine, logger log.Logger, interactive bool) keychain.Keychain {
ring := util.Must(keyring.Open(keyring.Config{
AllowedBackends: []keyring.BackendType{
backendType,
keyring.KeychainBackend,
keyring.SecretServiceBackend,
keyring.FileBackend,
},
ServiceName: KeychainServiceName,
FileDir: filepath.Join(machine.HomeDirectory(), ConfigDirectoryName),
@@ -96,22 +96,6 @@ func newKeychain(machine machine.Machine, logger log.Logger, backendType keyring
return keychain.New(keychain.Args{Keyring: ring})
}
// keyringBackendType returns the backend type for the keyring.
func keyringBackendType() keyring.BackendType {
allowedBackends := []keyring.BackendType{
keyring.KeychainBackend,
keyring.SecretServiceBackend,
}
for _, backend := range allowedBackends {
if slices.Contains(keyring.AvailableBackends(), backend) {
return backend
}
}
return keyring.FileBackend
}
// initWithCommand initializes the dependencies of the command.
func initWithCommand(cmd *cobra.Command) {
verbose := cmd.Flag("verbose").Value.String() == "true"
@@ -122,8 +106,7 @@ func initWithCommand(cmd *cobra.Command) {
dependencies.OS = operatingsystem.New()
dependencies.Machine = machine.New(machine.Args{OS: dependencies.OS})
dependencies.CookieJar = newCookieJar(dependencies.Machine)
dependencies.KeyringBackendType = keyringBackendType()
dependencies.Keychain = newKeychain(dependencies.Machine, dependencies.Logger, dependencies.KeyringBackendType, interactive)
dependencies.Keychain = newKeychain(dependencies.Machine, dependencies.Logger, interactive)
dependencies.AppStore = appstore.NewAppStore(appstore.Args{
CookieJar: dependencies.CookieJar,
OperatingSystem: dependencies.OS,
@@ -131,16 +114,16 @@ func initWithCommand(cmd *cobra.Command) {
Machine: dependencies.Machine,
})
util.Must("", createConfigDirectory())
util.Must("", createConfigDirectory(dependencies.OS, dependencies.Machine))
}
// createConfigDirectory creates the configuration directory for the CLI tool, if needed.
func createConfigDirectory() error {
configDirectoryPath := filepath.Join(dependencies.Machine.HomeDirectory(), ConfigDirectoryName)
_, err := dependencies.OS.Stat(configDirectoryPath)
func createConfigDirectory(os operatingsystem.OperatingSystem, machine machine.Machine) error {
configDirectoryPath := filepath.Join(machine.HomeDirectory(), ConfigDirectoryName)
_, err := os.Stat(configDirectoryPath)
if err != nil && dependencies.OS.IsNotExist(err) {
err = dependencies.OS.MkdirAll(configDirectoryPath, 0700)
if err != nil && os.IsNotExist(err) {
err = os.MkdirAll(configDirectoryPath, 0700)
if err != nil {
return fmt.Errorf("failed to create config directory: %w", err)
}
-6
View File
@@ -5,7 +5,6 @@ import (
"os"
"time"
"github.com/99designs/keyring"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/schollz/progressbar/v3"
@@ -112,11 +111,6 @@ func downloadCmd() *cobra.Command {
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "The bundle identifier of the target iOS app (required)")
cmd.Flags().StringVarP(&outputPath, "output", "o", "", "The destination path of the downloaded app package")
cmd.Flags().BoolVar(&acquireLicense, "purchase", false, "Obtain a license for the app if needed")
if keyringBackendType() == keyring.FileBackend {
cmd.Flags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
_ = cmd.MarkFlagRequired("bundle-identifier")
return cmd
-6
View File
@@ -4,7 +4,6 @@ import (
"errors"
"time"
"github.com/99designs/keyring"
"github.com/avast/retry-go"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/spf13/cobra"
@@ -66,11 +65,6 @@ func purchaseCmd() *cobra.Command {
}
cmd.Flags().StringVarP(&bundleID, "bundle-identifier", "b", "", "Bundle identifier of the target iOS app (required)")
if keyringBackendType() == keyring.FileBackend {
cmd.Flags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
_ = cmd.MarkFlagRequired("bundle-identifier")
return cmd
+1
View File
@@ -39,6 +39,7 @@ func rootCmd() *cobra.Command {
}, enumflag.EnumCaseSensitive), "format", "", "sets output format for command; can be 'text', 'json'")
cmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "enables verbose logs")
cmd.PersistentFlags().BoolVarP(&nonInteractive, "non-interactive", "", false, "run in non-interactive session")
cmd.PersistentFlags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
cmd.AddCommand(authCmd())
cmd.AddCommand(downloadCmd())
-5
View File
@@ -1,7 +1,6 @@
package cmd
import (
"github.com/99designs/keyring"
"github.com/majd/ipatool/v2/pkg/appstore"
"github.com/spf13/cobra"
)
@@ -40,9 +39,5 @@ func searchCmd() *cobra.Command {
cmd.Flags().Int64VarP(&limit, "limit", "l", 5, "maximum amount of search results to retrieve")
if keyringBackendType() == keyring.FileBackend {
cmd.PersistentFlags().StringVar(&keychainPassphrase, "keychain-passphrase", "", "passphrase for unlocking keychain")
}
return cmd
}
+2 -1
View File
@@ -29,7 +29,6 @@ func (t *appstore) ReplicateSinf(input ReplicateSinfInput) error {
if err != nil {
return errors.New("failed to open zip reader")
}
defer zipReader.Close()
tmpPath := fmt.Sprintf("%s.tmp", input.PackagePath)
tmpFile, err := t.os.OpenFile(tmpPath, os.O_CREATE|os.O_WRONLY, 0644)
@@ -71,6 +70,8 @@ func (t *appstore) ReplicateSinf(input ReplicateSinfInput) error {
return fmt.Errorf("failed to replicate sinf: %w", err)
}
zipReader.Close()
err = t.os.Remove(input.PackagePath)
if err != nil {
return fmt.Errorf("failed to remove original file: %w", err)
+13 -37
View File
@@ -1,7 +1,6 @@
package operatingsystem
import (
"fmt"
"os"
)
@@ -27,60 +26,37 @@ func (operatingSystem) Getenv(key string) string {
return os.Getenv(key)
}
// nolint:wrapcheck
func (operatingSystem) Stat(name string) (os.FileInfo, error) {
info, err := os.Stat(name)
if err != nil {
return nil, fmt.Errorf("failed to describe file '%s': %w", name, err)
}
return info, nil
return os.Stat(name)
}
// nolint:wrapcheck
func (operatingSystem) Getwd() (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to get current directory: %w", err)
}
return wd, nil
return os.Getwd()
}
// nolint:wrapcheck
func (operatingSystem) OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
file, err := os.OpenFile(name, flag, perm)
if err != nil {
return nil, fmt.Errorf("failed to open file '%s': %w", name, err)
}
return file, nil
return os.OpenFile(name, flag, perm)
}
// nolint:wrapcheck
func (operatingSystem) Remove(name string) error {
err := os.Remove(name)
if err != nil {
return fmt.Errorf("failed to remove file '%s': %w", name, err)
}
return nil
return os.Remove(name)
}
// nolint:wrapcheck
func (operatingSystem) IsNotExist(err error) bool {
return os.IsNotExist(err)
}
// nolint:wrapcheck
func (operatingSystem) MkdirAll(path string, perm os.FileMode) error {
err := os.MkdirAll(path, perm)
if err != nil {
return fmt.Errorf("failed to create directory '%s': %w", path, err)
}
return nil
return os.MkdirAll(path, perm)
}
// nolint:wrapcheck
func (operatingSystem) Rename(oldPath, newPath string) error {
err := os.Rename(oldPath, newPath)
if err != nil {
return fmt.Errorf("failed to rename '%s' to '%s': %w", oldPath, newPath, err)
}
return nil
return os.Rename(oldPath, newPath)
}
@@ -1,7 +1,6 @@
package operatingsystem
import (
"errors"
"fmt"
"io/fs"
"math/rand"
@@ -70,7 +69,7 @@ var _ = Describe("OperatingSystem", func() {
Expect(err).ToNot(HaveOccurred())
_, err = sut.Stat(file.Name())
Expect(os.IsNotExist(errors.Unwrap(err))).To(BeTrue())
Expect(os.IsNotExist(err)).To(BeTrue())
})
It("renames file", func() {