Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename to AzureSpringApps #17471

Merged
merged 21 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"loc.friendlyName": "Azure Spring Cloud",
"loc.helpMarkDown": "[Learn more about this task](https://aka.ms/azurespringcloud)",
"loc.description": "Deploy applications to Azure Spring Cloud and manage deployments.",
"loc.instanceNameFormat": "Azure Spring Cloud $(Action): $(AppName)",
"loc.friendlyName": "Azure Spring Apps",
"loc.helpMarkDown": "[Learn more about this task](https://aka.ms/azurespringapps)",
"loc.description": "Deploy applications to Azure Spring Apps and manage deployments.",
"loc.instanceNameFormat": "Azure Spring Apps $(Action): $(AppName)",
"loc.group.displayName.ApplicationAndConfigurationSettings": "Application and Configuration Settings",
"loc.input.label.ConnectedServiceName": "Azure subscription",
"loc.input.help.ConnectedServiceName": "Select the Azure Resource Manager subscription for the deployment.",
"loc.input.label.Action": "Action",
"loc.input.help.Action": "Action to be performed on Azure Spring Cloud.",
"loc.input.label.AzureSpringCloud": "Azure Spring Cloud Name",
"loc.input.help.AzureSpringCloud": "Select the Azure Spring Cloud service to which to deploy.",
"loc.input.help.Action": "Action to be performed on Azure Spring Apps.",
"loc.input.label.AzureSpringCloud": "Azure Spring Apps Name",
"loc.input.help.AzureSpringCloud": "Select the Azure Spring Apps service to which to deploy.",
"loc.input.label.AppName": "App",
"loc.input.help.AppName": "Select the Azure Spring Cloud app to deploy.",
"loc.input.help.AppName": "Select the Azure Spring Apps app to deploy.",
"loc.input.label.DeploymentType": "Deployment Type",
"loc.input.help.DeploymentType": "To deploy with source code or Java package, choose \"Artifacts\"; To deploy with container image, choose \"Custom Container\"",
"loc.input.label.UseStagingDeployment": "Use Staging Deployment",
Expand All @@ -21,9 +21,9 @@
"loc.input.label.DeploymentName": "Deployment",
"loc.input.help.DeploymentName": "The deployment to which this task will apply. Lowercase letters and numbers only; must start with a letter.",
"loc.input.label.Package": "Package or folder",
"loc.input.help.Package": "File path to the package or a folder containing the Spring Cloud app contents.<br />Variables ( [Build](https://docs.microsoft.com/vsts/pipelines/build/variables) | [Release](https://docs.microsoft.com/vsts/pipelines/release/variables#default-variables)), wildcards are supported. <br/> For example, $(System.DefaultWorkingDirectory)/\\*\\*/\\*.jar.",
"loc.input.help.Package": "File path to the package or a folder containing the Spring Apps app contents.<br />Variables ( [Build](https://docs.microsoft.com/vsts/pipelines/build/variables) | [Release](https://docs.microsoft.com/vsts/pipelines/release/variables#default-variables)), wildcards are supported. <br/> For example, $(System.DefaultWorkingDirectory)/\\*\\*/\\*.jar.",
"loc.input.label.Builder": "Builder",
"loc.input.help.Builder": "Select a builder of VMware Tanzu® Build Service™, this can be used in enterprise tier. <br/> For detailed description, please check [Use Tanzu Build Service](https://docs.microsoft.com/en-us/azure/spring-cloud/how-to-enterprise-build-service?tabs=azure-portal).",
"loc.input.help.Builder": "Select a builder of VMware Tanzu® Build Service™, this can be used in enterprise tier. <br/> For detailed description, please check [Use Tanzu Build Service](https://docs.microsoft.com/en-us/azure/spring-apps/how-to-enterprise-build-service?tabs=azure-portal).",
"loc.input.label.RegistryServer": "Registry Server",
"loc.input.help.RegistryServer": "The registry of the container image. Default: docker.io.",
"loc.input.label.RegistryUsername": "Registry Username",
Expand Down Expand Up @@ -52,7 +52,7 @@
"loc.messages.StartingUploadOf": "Starting upload of %s",
"loc.messages.CompletedUploadOf": "Upload of %s completed.",
"loc.messages.ResourceDoesntExist": "Resource '%s' doesn't exist. Resource should exist before deployment.",
"loc.messages.UnableToGetDeploymentUrl": "Unable to get deployment URL for Azure Spring Cloud '%s', Error: '%s'",
"loc.messages.UnableToGetDeploymentUrl": "Unable to get deployment URL for Azure Spring Apps '%s', Error: '%s'",
"loc.messages.DeploymentDoesntExist": "Deployment with name '%s' does not exist. Unable to proceed.",
"loc.messages.StagingDeploymentWithNameDoesntExist": "Staging deployment with name %s does not exist. Unable to proceed.",
"loc.messages.NoStagingDeploymentFound": "No staging deployment found.",
Expand All @@ -66,8 +66,8 @@
"loc.messages.UnableToRetrieveTestEndpointKeys": "Unable to retrieve test endpoint keys",
"loc.messages.NoDeploymentsExist": "No deployments exist.",
"loc.messages.UnableToGetDeploymentInformation": "Unable to get deployment information.",
"loc.messages.DuplicateAzureSpringCloudName": "Illegal state: multiple Azure Spring Cloud instances with same name.",
"loc.messages.InvalidAzureSpringCloudResourceId": "Invalid azure spring cloud resource identifier: %s",
"loc.messages.DuplicateAzureSpringAppsName": "Illegal state: multiple Azure Spring Apps instances with same name.",
"loc.messages.InvalidAzureSpringAppsResourceId": "Invalid Azure Spring Apps resource identifier: %s",
"loc.messages.Nopackagefoundwithspecifiedpattern": "No package found with specified pattern: %s. Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.",
"loc.messages.MorethanonepackagematchedwithspecifiedpatternPleaserestrainthesearchpattern": "More than one package matched with specified pattern: %s. Please restrain the search pattern."
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert = require('assert');
import { AzureSpringCloudDeploymentProvider } from "../deploymentProvider/AzureSpringCloudDeploymentProvider"
import { AzureSpringAppsDeploymentProvider } from "../deploymentProvider/AzureSpringCloudDeploymentProvider"
import { TaskParameters } from "../operations/taskparameters"


Expand All @@ -8,17 +8,17 @@ export class AzureSpringCloudUnitTests {
public static pathTraversalAttackTest = (done: Mocha.Done) => {
const resourceIdWithPathAttack = '/subscriptions/mocksubid/resourceGroups/mockresouorcegroup/providers/Microsoft.AppPlatform/Spring/authorized-name/../unauthorized-name';
const taskParameters: TaskParameters = {
AzureSpringCloud: resourceIdWithPathAttack,
AzureSpringApps: resourceIdWithPathAttack,
AppName: 'appName',
UseStagingDeployment: false,
Action: 'Deploy'
};

const provider = new AzureSpringCloudDeploymentProvider(taskParameters);
const provider = new AzureSpringAppsDeploymentProvider(taskParameters);
provider.PreDeploymentStep().then(() => {
done(assert.fail('Attempted path traversal attack should have failed'));
}).catch(error => {
assert.strictEqual(error.message, `loc_mock_InvalidAzureSpringCloudResourceId ${resourceIdWithPathAttack}`);
assert.strictEqual(error.message, `loc_mock_InvalidAzureSpringAppsResourceId ${resourceIdWithPathAttack}`);
done();
});
}
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureSpringCloudV0/azurespringclouddeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import tl = require('azure-pipelines-task-lib/task');
import { TaskParameters, TaskParametersUtility } from './operations/taskparameters';

import { AzureSpringCloudDeploymentProvider } from './deploymentProvider/AzureSpringCloudDeploymentProvider'
import { AzureSpringAppsDeploymentProvider } from './deploymentProvider/AzureSpringCloudDeploymentProvider'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we able to change "AzureSpringCloudDeploymentProvider"? Probably need to renam the file .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do, I was about to check with you whether this is needed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good to know that.

import path = require('path');

export async function main() {
Expand All @@ -13,7 +13,7 @@ export async function main() {
tl.setResourcePath(path.join(__dirname, 'node_modules/azure-pipelines-tasks-azure-arm-rest-v2/module.json'));
tl.setResourcePath(path.join(__dirname, 'node_modules/azure-pipelines-tasks-webdeployment-common/module.json'));
var taskParams: TaskParameters = TaskParametersUtility.getParameters();
var deploymentProvider = new AzureSpringCloudDeploymentProvider(taskParams);
var deploymentProvider = new AzureSpringAppsDeploymentProvider(taskParams);

tl.debug("Pre-deployment Step Started");
await deploymentProvider.PreDeploymentStep();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import path = require('path');
import { v4 as uuidv4 } from 'uuid';
import { Package, PackageType } from 'azure-pipelines-tasks-webdeployment-common/packageUtility';
import { Actions, DeploymentType, TaskParameters } from '../operations/taskparameters';
import { SourceType, AzureSpringCloud } from './azure-arm-spring-cloud';
import { SourceType, AzureSpringApps } from './azure-arm-spring-cloud';
import { AzureRMEndpoint } from 'azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-endpoint';
import tl = require('azure-pipelines-task-lib/task');
import tar = require('tar');
import { AzureResourceFilterUtility } from '../operations/AzureResourceFilterUtility';

const OUTPUT_VARIABLE_TEST_ENDPOINT = 'testEndpoint';

export class AzureSpringCloudDeploymentProvider {
export class AzureSpringAppsDeploymentProvider {

defaultInactiveDeploymentName = 'staging';

protected taskParameters: TaskParameters;
protected azureSpringCloud: AzureSpringCloud;
protected azureSpringApps: AzureSpringApps;

constructor(taskParameters: TaskParameters) {
this.taskParameters = taskParameters;
Expand All @@ -24,20 +24,20 @@ export class AzureSpringCloudDeploymentProvider {
public async PreDeploymentStep() {
const azureEndpoint = await new AzureRMEndpoint(this.taskParameters.ConnectedServiceName).getEndpoint();

//The Azure Spring Cloud parameter can be a resource ID (if selected from the picklist) or
//The Azure Spring Apps parameter can be a resource ID (if selected from the picklist) or
//a name (if entered manually). This is to avoid requiring the user to enter an otherwise unnecessary user
//user group name. If we have a name, we need to look up the resource ID.
var azureSpringCloudResourceId: string;
if (this.taskParameters.AzureSpringCloud.startsWith('/')) {
if (this.taskParameters.AzureSpringCloud.includes('..')){{
throw Error(tl.loc('InvalidAzureSpringCloudResourceId', 'this.taskParameters.AzureSpringCloud'));
var azureSpringAppsResourceId: string;
if (this.taskParameters.AzureSpringApps.startsWith('/')) {
if (this.taskParameters.AzureSpringApps.includes('..')){{
throw Error(tl.loc('InvalidAzureSpringAppsResourceId', 'this.taskParameters.AzureSpringApps'));
}}
azureSpringCloudResourceId = this.taskParameters.AzureSpringCloud;
azureSpringAppsResourceId = this.taskParameters.AzureSpringApps;
} else {
azureSpringCloudResourceId = await AzureResourceFilterUtility.getAzureSpringCloudResourceId(azureEndpoint, this.taskParameters.AzureSpringCloud);
azureSpringAppsResourceId = await AzureResourceFilterUtility.getAzureSpringAppsResourceId(azureEndpoint, this.taskParameters.AzureSpringApps);
}

this.azureSpringCloud = new AzureSpringCloud(azureEndpoint, azureSpringCloudResourceId);
this.azureSpringApps = new AzureSpringApps(azureEndpoint, azureSpringAppsResourceId);
}

public async DeployAppStep() {
Expand Down Expand Up @@ -72,9 +72,9 @@ export class AzureSpringCloudDeploymentProvider {

private async performDeleteStagingDeploymentAction() {
tl.debug('Delete staging deployment action');
const deploymentName = await this.azureSpringCloud.getInactiveDeploymentName(this.taskParameters.AppName);
const deploymentName = await this.azureSpringApps.getInactiveDeploymentName(this.taskParameters.AppName);
if (deploymentName) {
await this.azureSpringCloud.deleteDeployment(this.taskParameters.AppName, deploymentName);
await this.azureSpringApps.deleteDeployment(this.taskParameters.AppName, deploymentName);
} else {
throw Error(tl.loc('NoStagingDeploymentFound'));
}
Expand All @@ -86,21 +86,21 @@ export class AzureSpringCloudDeploymentProvider {
var deploymentName: string;
if (this.taskParameters.UseStagingDeployment) {
tl.debug('Targeting inactive deployment');
deploymentName = await this.azureSpringCloud.getInactiveDeploymentName(this.taskParameters.AppName);
deploymentName = await this.azureSpringApps.getInactiveDeploymentName(this.taskParameters.AppName);
if (!deploymentName) { //If no inactive deployment exists, we cannot continue as instructed.
throw Error(tl.loc('NoStagingDeploymentFound'));
}
}
else {
//Verify that the named deployment actually exists.
deploymentName = this.taskParameters.DeploymentName;
let existingStagingDeploymentName: string = await this.azureSpringCloud.getInactiveDeploymentName(this.taskParameters.AppName);
let existingStagingDeploymentName: string = await this.azureSpringApps.getInactiveDeploymentName(this.taskParameters.AppName);
if (deploymentName != existingStagingDeploymentName) {
throw Error(tl.loc('StagingDeploymentWithNameDoesntExist', deploymentName));
}
}

await this.azureSpringCloud.setActiveDeployment(this.taskParameters.AppName, deploymentName);
await this.azureSpringApps.setActiveDeployment(this.taskParameters.AppName, deploymentName);
}

private async performDeployAction() {
Expand All @@ -115,15 +115,15 @@ export class AzureSpringCloudDeploymentProvider {

const {deploymentName, createDeployment} = await this.chooseDeployment();

// Determine the sku of the Azure Spring Cloud
const serviceSkuTier = await this.azureSpringCloud.getServiceSkuTier();
// Determine the sku of the Azure Spring Apps
const serviceSkuTier = await this.azureSpringApps.getServiceSkuTier();
try {
if (serviceSkuTier == "Standard" || serviceSkuTier == "Basic") {
await this.azureSpringCloud.deploy(fileToUpload, sourceType, this.taskParameters.AppName,
await this.azureSpringApps.deploy(fileToUpload, sourceType, this.taskParameters.AppName,
deploymentName, createDeployment, this.taskParameters.RuntimeVersion, this.taskParameters.JvmOptions,
this.taskParameters.EnvironmentVariables, this.taskParameters.DotNetCoreMainEntryPath, this.taskParameters.Version);
} else if (serviceSkuTier == "Enterprise") {
await this.azureSpringCloud.deployWithBuildService(fileToUpload, sourceType, this.taskParameters.AppName,
await this.azureSpringApps.deployWithBuildService(fileToUpload, sourceType, this.taskParameters.AppName,
deploymentName, createDeployment, this.taskParameters.RuntimeVersion, this.taskParameters.JvmOptions,
this.taskParameters.EnvironmentVariables, this.taskParameters.DotNetCoreMainEntryPath, this.taskParameters.Version, this.taskParameters.Builder);
} else {
Expand All @@ -132,7 +132,7 @@ export class AzureSpringCloudDeploymentProvider {
} catch (error) {
throw error;
}
var testEndpoint = await this.azureSpringCloud.getTestEndpoint(this.taskParameters.AppName, deploymentName);
var testEndpoint = await this.azureSpringApps.getTestEndpoint(this.taskParameters.AppName, deploymentName);
tl.setVariable(OUTPUT_VARIABLE_TEST_ENDPOINT, testEndpoint);
return deploymentName;
}
Expand All @@ -143,14 +143,14 @@ export class AzureSpringCloudDeploymentProvider {
const {deploymentName, createDeployment} = await this.chooseDeployment();

try {
await this.azureSpringCloud.deployCustomContainer(this.taskParameters.AppName, deploymentName, createDeployment,
await this.azureSpringApps.deployCustomContainer(this.taskParameters.AppName, deploymentName, createDeployment,
this.taskParameters.RegistryServer, this.taskParameters.RegistryUsername, this.taskParameters.RegistryPassword,
this.taskParameters.ImageName, this.taskParameters.ImageCommand, this.taskParameters.ImageArgs, this.taskParameters.ImageLanguageFramework,
this.taskParameters.EnvironmentVariables, this.taskParameters.Version);
} catch (error) {
throw error;
}
var testEndpoint = await this.azureSpringCloud.getTestEndpoint(this.taskParameters.AppName, deploymentName);
var testEndpoint = await this.azureSpringApps.getTestEndpoint(this.taskParameters.AppName, deploymentName);
tl.setVariable(OUTPUT_VARIABLE_TEST_ENDPOINT, testEndpoint);
return deploymentName;
}
Expand All @@ -159,7 +159,7 @@ export class AzureSpringCloudDeploymentProvider {
var deploymentName: string;
var createDeployment = false;
if (this.taskParameters.UseStagingDeployment) {
deploymentName = await this.azureSpringCloud.getInactiveDeploymentName(this.taskParameters.AppName);
deploymentName = await this.azureSpringApps.getInactiveDeploymentName(this.taskParameters.AppName);
if (!deploymentName) { //If no inactive deployment exists
tl.debug('No inactive deployment exists');
if (this.taskParameters.CreateNewDeployment) {
Expand All @@ -172,7 +172,7 @@ export class AzureSpringCloudDeploymentProvider {
} else { //Deploy to deployment with specified name
tl.debug('Deploying with specified name.');
deploymentName = this.taskParameters.DeploymentName;
var deploymentNames = await this.azureSpringCloud.getAllDeploymentNames(this.taskParameters.AppName);
var deploymentNames = await this.azureSpringApps.getAllDeploymentNames(this.taskParameters.AppName);
if (!deploymentNames || !deploymentNames.includes(deploymentName)) {
tl.debug(`Deployment ${deploymentName} does not exist`);
if (this.taskParameters.CreateNewDeployment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const ASYNC_OPERATION_HEADER = 'azure-asyncoperation';
const API_VERSION = '2022-03-01-preview';
const LOCATION_HEADER = 'location';

export class AzureSpringCloud {
export class AzureSpringApps {
private _resourceId: string;
private _client: ServiceClient;

Expand Down Expand Up @@ -246,6 +246,10 @@ export class AzureSpringCloud {
throw ToError(response);
}
provisioningState = response.body.properties.provisioningState;
if (provisioningState == "Failed"){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

tl.debug('KPack build failed');
throw ToError(response);
}
} catch (error) {
throw error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AzureEndpoint } from 'azure-pipelines-tasks-azure-arm-rest-v2/azureMode
import { Resources } from 'azure-pipelines-tasks-azure-arm-rest-v2/azure-arm-resource';

export class AzureResourceFilterUtility {
public static async getAzureSpringCloudResourceId(endpoint: AzureEndpoint, resourceName: string): Promise<string> {
public static async getAzureSpringAppsResourceId(endpoint: AzureEndpoint, resourceName: string): Promise<string> {
tl.debug('Looking up Azure Spring Cloud Instance ' + resourceName);
var azureResources: Resources = new Resources(endpoint);
var filteredResources: Array<any> = await azureResources.getResources('Microsoft.AppPlatform/Spring', resourceName);
Expand All @@ -15,7 +15,7 @@ export class AzureResourceFilterUtility {
resourceId = filteredResources[0].id;
}
else { //Should never ever ever happen
throw new Error(tl.loc('DuplicateAzureSpringCloudName'));
throw new Error(tl.loc('DuplicateAzureSpringAppsName'));
}
tl.debug('Azure Spring Cloud Lookup completed');
return resourceId;
Expand Down
Loading