-
-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ add a new credential type: Apple Developer Profile
- Loading branch information
Wei Li
committed
Jun 27, 2017
1 parent
faf92c9
commit 20134e1
Showing
9 changed files
with
219 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ job-dsl:1.41 | |
config-file-provider:2.10.0 | ||
testng-plugin:1.10 | ||
cloudbees-folder: 5.12 | ||
xcode-plugin: 2.0.0 |
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
107 changes: 107 additions & 0 deletions
107
...src/main/java/com/offbytwo/jenkins/model/credentials/AppleDeveloperProfileCredential.java
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,107 @@ | ||
package com.offbytwo.jenkins.model.credentials; | ||
|
||
import net.sf.json.JSONObject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Apple developer profile credential type. | ||
* | ||
* NOTE: this type is only available on Jenkins after the xcode plugin (https://wiki.jenkins.io/display/JENKINS/Xcode+Plugin) is installed. | ||
*/ | ||
public class AppleDeveloperProfileCredential extends Credential { | ||
public static final String TYPENAME = "Apple Developer Profile"; | ||
|
||
private static final String BASECLASS = "au.com.rayh.DeveloperProfile"; | ||
private static final String FILE_ZERO_FIELD_NAME = "file0"; | ||
private static final String FILE_ONE_FIELD_NAME = "file1"; | ||
|
||
private String password; | ||
private byte[] developerProfileContent; | ||
|
||
public String getPassword() { | ||
return password; | ||
} | ||
|
||
/** | ||
* Set the password of the developer profile | ||
* @param password | ||
*/ | ||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
|
||
public byte[] getDeveloperProfileContent() { | ||
return developerProfileContent; | ||
} | ||
|
||
/** | ||
* Set the content of the developer profile. A developer profile file is a zip with the following structure: | ||
* | ||
* developerprofile/ | ||
* - account.keychain (can be empty. Required for validation. The plugin will create a new keychain before build) | ||
* - identities | ||
* |- <name>.p12 (A exported P12 file. Should contain both certificate and private key) | ||
* - profiles | ||
* |- <name>.mobileprovision (A mobile provisioning profile) | ||
* @param developerProfileContent | ||
*/ | ||
public void setDeveloperProfileContent(byte[] developerProfileContent) { | ||
this.developerProfileContent = developerProfileContent; | ||
} | ||
|
||
@Override | ||
public boolean useMultipartForm() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> dataForCreate() { | ||
Map<String, String> credentialMap = new HashMap<String, String>(); | ||
credentialMap.put("image", FILE_ZERO_FIELD_NAME); | ||
credentialMap.put("password", this.getPassword()); | ||
credentialMap.put("id", this.getId()); | ||
credentialMap.put("description", this.getDescription()); | ||
credentialMap.put("stapler-class", BASECLASS); | ||
credentialMap.put("$class", BASECLASS); | ||
|
||
|
||
Map<String, Object> jsonData = new HashMap<>(); | ||
jsonData.put("", "1"); | ||
jsonData.put("credentials", credentialMap); | ||
|
||
Map<String, Object> formFields = new HashMap<String, Object>(); | ||
formFields.put(FILE_ZERO_FIELD_NAME, this.getDeveloperProfileContent()); | ||
formFields.put("_.scope", SCOPE_GLOBAL); | ||
formFields.put("_.password", this.getPassword()); | ||
formFields.put("_.id", this.getId()); | ||
formFields.put("_.description", this.getDescription()); | ||
formFields.put("stapler-class", BASECLASS); | ||
formFields.put("$class", BASECLASS); | ||
formFields.put("json", JSONObject.fromObject(jsonData).toString()); | ||
return formFields; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> dataForUpdate() { | ||
Map<String, Object> credentialMap = new HashMap<String, Object>(); | ||
credentialMap.put("image", FILE_ONE_FIELD_NAME); | ||
credentialMap.put("password", this.getPassword()); | ||
credentialMap.put("id", this.getId()); | ||
credentialMap.put("description", this.getDescription()); | ||
credentialMap.put("stapler-class", BASECLASS); | ||
credentialMap.put("", true); | ||
|
||
|
||
Map<String, Object> formFields = new HashMap<String, Object>(); | ||
formFields.put(FILE_ONE_FIELD_NAME, this.getDeveloperProfileContent()); | ||
formFields.put("_.", "on"); | ||
formFields.put("_.password", this.getPassword()); | ||
formFields.put("_.id", this.getId()); | ||
formFields.put("_.description", this.getDescription()); | ||
formFields.put("stapler-class", BASECLASS); | ||
formFields.put("json", JSONObject.fromObject(credentialMap).toString()); | ||
return formFields; | ||
} | ||
} |
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