Skip to content

Commit

Permalink
Add token subcommand to keys
Browse files Browse the repository at this point in the history
The keys command gets a subcommand for token generation.
  • Loading branch information
Blackjacx committed Aug 28, 2023
1 parent 0ac5c7b commit 7da6d4c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/blackjacx/ASCKit",
"state" : {
"revision" : "bf8165371166baf312ee202361df4e25c4c0bce2",
"version" : "0.2.1"
"revision" : "66450c6527d737a2bd26be11c19d6b951e221ad1",
"version" : "0.2.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/blackjacx/Engine", from: "0.0.3"),
.package(url: "https://github.com/blackjacx/ASCKit", from: "0.2.1"),
.package(url: "https://github.com/blackjacx/ASCKit", from: "0.2.2"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "4.1.0"),
.package(url: "https://github.com/kareman/SwiftShell", from: "5.1.0")
Expand Down
35 changes: 20 additions & 15 deletions Sources/ASC/commands/sub/Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension ASC {

static var configuration = CommandConfiguration(
abstract: "Lists, registers and deletes App Store Connect API keys on your Mac.",
subcommands: [List.self, Activate.self, Register.self, Delete.self],
subcommands: [List.self, Activate.self, Register.self, Delete.self, Token.self],
defaultSubcommand: List.self)
}
}
Expand All @@ -28,8 +28,6 @@ extension ASC.Keys {
struct List: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "List locally stored App Store Connect API keys.")

// The `@OptionGroup` attribute includes the flags, options, and arguments defined by another
// `ParsableArguments` type.
@OptionGroup()
var options: Options

Expand All @@ -42,16 +40,14 @@ extension ASC.Keys {
struct Activate: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Makes a registered API key the default one.")

// The `@OptionGroup` attribute includes the flags, options, and arguments defined by another
// `ParsableArguments` type.
@OptionGroup()
var options: Options

@Option(name: .shortAndLong, help: "The key's id.")
var id: String
var keyId: String

func run() throws {
let activatedKey = try ASCService.activateApiKey(id: id)
let activatedKey = try ASCService.activateApiKey(id: keyId)
print(activatedKey)
}
}
Expand All @@ -60,13 +56,11 @@ extension ASC.Keys {
struct Register: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Registers App Store Connect API keys locally.")

// The `@OptionGroup` attribute includes the flags, options, and arguments defined by another
// `ParsableArguments` type.
@OptionGroup()
var options: Options

@Option(name: .shortAndLong, help: "The key's id.")
var id: String
var keyId: String

@Option(name: .shortAndLong, help: "The key's name you. You can choose freely.")
var name: String
Expand All @@ -78,7 +72,7 @@ extension ASC.Keys {
var issuerId: String

func run() throws {
let key = ApiKey(id: id, name: name, source: .localFilePath(path: path), issuerId: issuerId)
let key = ApiKey(id: keyId, name: name, source: .localFilePath(path: path), issuerId: issuerId)
let registeredKey = try ASCService.registerApiKey(key: key)
print(registeredKey)
}
Expand All @@ -88,17 +82,28 @@ extension ASC.Keys {
struct Delete: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Delete locally stored App Store Connect API keys.")

// The `@OptionGroup` attribute includes the flags, options, and arguments defined by another
// `ParsableArguments` type.
@OptionGroup()
var options: Options

@Option(name: .shortAndLong, help: "The key's id.")
var id: String
var keyId: String

func run() throws {
let deletedKey = try ASCService.deleteApiKey(id: id)
let deletedKey = try ASCService.deleteApiKey(id: keyId)
print(deletedKey)
}
}

/// Generate a token from a locally stored App Store Connect API keys.
struct Token: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Generate a token from a locally stored App Store Connect API keys.")

@OptionGroup()
var options: ApiKeyOptions

func run() throws {
let token = try ASCService.createAccessToken(keyId: options.keyId)
print(token)
}
}
}

0 comments on commit 7da6d4c

Please sign in to comment.