Skip to content

Commit

Permalink
[Release Tooling] xcprivacy generation tooling (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Nov 27, 2023
1 parent 8fe1ddc commit 3f97ad0
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
8 changes: 8 additions & 0 deletions ReleaseTooling/Sources/PrivacyKit/PrivacyManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import Foundation

/// Represents a Privacy Manifest as described in
/// https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
// TODO(ncooke3): Add example of Privacy Manifest.
public struct PrivacyManifest {
public init() {}
public class Builder {
public init() {}
public func build() -> PrivacyManifest? {
// TODO(ncooke3): Implement.
nil
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,34 @@ import PrivacyKit
/// Provides an API to walk the client through the creation of a Privacy
/// Manifest via a series of questions.
final class PrivacyManifestWizard {
private let xcframework: URL
private let builder: PrivacyManifest.Builder
private var questionnaire: Questionnaire

init(xcframework: URL) {
self.xcframework = xcframework
static func makeWizard(xcframework: URL) -> Self {
let builder = PrivacyManifest.Builder()
let privacyQuestionnaire = Questionnaire.makePrivacyQuestionnaire(
for: xcframework,
with: builder
)
return Self(builder: builder, questionnaire: privacyQuestionnaire)
}

private init(builder: PrivacyManifest.Builder,
questionnaire: Questionnaire) {
self.builder = builder
self.questionnaire = questionnaire
}

func nextQuestion() -> String? {
// TODO(ncooke3): Implement.
nil
questionnaire.nextQuestion()?.question
}

func processAnswer(_ answer: String) throws {
// TODO(ncooke3): Implement.
try questionnaire.processAnswer(answer)
}

func createManifest() throws -> PrivacyManifest {
// TODO(ncooke3): Implement.
return PrivacyManifest()
builder.build()!
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import PrivacyKit

extension Questionnaire {
/// Creates a questionnaire that, when complete, can be used to generate a Privacy Manifest.
///
/// - Parameters:
/// - xcframework: The xcframework to generate the Privacy Manifest for.
/// - builder: The Privacy Manifest builder to mutate in each question's answer handler closure.
/// - Returns: A questionnaire that can be used to generate a Privacy Manifest.
static func makePrivacyQuestionnaire(for xcframework: URL,
with builder: PrivacyManifest.Builder) -> Self {
// TODO(ncooke3): Implement.
Questionnaire()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation

/// A structure representing a series of questions.
struct Questionnaire {
/// A structure representing a question within a questionnaire.
struct Question {
/// The question's string query, for example, _What is your name?_.
let question: String
/// A closure to be invoked with the answer to the question.
let answerHandler: (_ answer: Any) throws -> Void
}

/// Moves to and returns the next question in the questionnaire.
/// - Returns: The next question in the questionnaire, if any.
mutating func nextQuestion() -> Question? {
// TODO(ncooke3): Implement.
nil
}

/// Calls the current question's answer handling closure with the given answer.
/// - Parameter answer: The answer to pass to the current question's answer handling closure.
func processAnswer(_ answer: String) throws {
// TODO(ncooke3): Implement.
}
}
2 changes: 1 addition & 1 deletion ReleaseTooling/Sources/PrivacyManifestGenerator/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct PrivacyManifestGenerator: ParsableCommand {
}

func run() throws {
let wizard = PrivacyManifestWizard(xcframework: xcframework)
let wizard = PrivacyManifestWizard.makeWizard(xcframework: xcframework)

while let question = wizard.nextQuestion() {
print(question)
Expand Down

0 comments on commit 3f97ad0

Please sign in to comment.