-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5997e4a
commit f3c0fd4
Showing
13 changed files
with
443 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@humanitec/backstage-plugin-scaffolder-backend-module': minor | ||
'@humanitec/backstage-plugin': minor | ||
--- | ||
|
||
Include scaffolding helpers from [humanitec-architecture/backstage](https://github.com/humanitec-architecture/backstage) |
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
43 changes: 43 additions & 0 deletions
43
plugins/humanitec-backend-scaffolder-module/src/actions/get-environment.ts
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,43 @@ | ||
import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; | ||
|
||
interface EnvironmentAction { | ||
orgId: string | ||
cloudProvider?: string | ||
} | ||
|
||
export function createGetEnvironmentAction({ orgId, cloudProvider }: EnvironmentAction) { | ||
return createTemplateAction({ | ||
id: 'humanitec:get-environment', | ||
schema: { | ||
output: { | ||
required: [ | ||
'orgId', | ||
], | ||
properties: { | ||
orgId: { | ||
type: 'string' | ||
}, | ||
cloudProvider: { | ||
type: 'string' | ||
}, | ||
githubOIDCCustomization: { | ||
type: 'object' | ||
} | ||
} | ||
} | ||
}, | ||
handler: async (ctx) => { | ||
ctx.output('orgId', orgId); | ||
ctx.output('cloudProvider', cloudProvider); | ||
|
||
let githubOIDCCustomization | ||
if (cloudProvider === 'azure') { | ||
githubOIDCCustomization = { | ||
"useDefault": false, | ||
"includeClaimKeys": ["repository_owner"] | ||
} | ||
} | ||
ctx.output('githubOIDCCustomization', githubOIDCCustomization); | ||
}, | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { humanitecPlugin } from './plugin'; | ||
export { HumanitecCardComponent } from './components/HumanitecCardComponent'; | ||
export { HumanitecCardComponent } from './components/HumanitecCardComponent'; | ||
export { ValidateHumanitecAppIDFieldExtension } from './scaffolder/ValidateHumanitecAppID'; |
80 changes: 80 additions & 0 deletions
80
plugins/humanitec/src/scaffolder/ValidateHumanitecAppID/ValidateHumanitecAppIDExtension.tsx
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,80 @@ | ||
import React from 'react'; | ||
import { FieldExtensionComponentProps } from '@backstage/plugin-scaffolder-react'; | ||
import type { FieldValidation } from '@rjsf/utils'; | ||
import FormControl from '@material-ui/core/FormControl'; | ||
import { | ||
InputLabel, | ||
Input, | ||
FormHelperText, | ||
List, | ||
ListItem, | ||
Link, | ||
} from '@material-ui/core'; | ||
|
||
/* | ||
Field rendered in the form | ||
*/ | ||
|
||
export const ValidateHumanitecAppID = ({ | ||
onChange, | ||
rawErrors, | ||
required, | ||
formData, | ||
}: FieldExtensionComponentProps<string>) => { | ||
return ( | ||
<FormControl | ||
margin="normal" | ||
required={required} | ||
error={rawErrors && rawErrors?.length > 0 && !formData} | ||
> | ||
<InputLabel htmlFor="validateName">Name</InputLabel> | ||
<Input | ||
id="validateName" | ||
aria-describedby="entityName" | ||
onChange={e => onChange(e.target?.value)} | ||
/> | ||
<FormHelperText id="entityName"> | ||
<List> | ||
<ListItem> | ||
Must only contain alphanumeric characters, numbers, or dashes. | ||
</ListItem> | ||
<ListItem>Must be lowercase.</ListItem> | ||
<ListItem>Must be at least 3 characters long.</ListItem> | ||
<ListItem>Must be at most 50 characters long.</ListItem> | ||
<ListItem>Cannot start or end with a dash.</ListItem> | ||
<ListItem> | ||
See | ||
<Link | ||
target="_blank" | ||
rel="noopener" | ||
href="https://developer.humanitec.com/platform-orchestrator/reference/constraints/#application-names" | ||
> | ||
https://developer.humanitec.com/platform-orchestrator/reference/constraints/#application-names | ||
</Link> | ||
for more details. | ||
</ListItem> | ||
</List> | ||
</FormHelperText> | ||
</FormControl> | ||
); | ||
}; | ||
|
||
/* | ||
This is a validation function that will run when the form is submitted. | ||
You will get the value from the `onChange` handler before as the value here to make sure that the types are aligned\ | ||
*/ | ||
|
||
export const validateHumanitecAppIDValidation = ( | ||
value: string, | ||
validation: FieldValidation, | ||
) => { | ||
const validID = /^[a-z0-9](?:-?[a-z0-9]+)+$/g.test(value); | ||
|
||
if (validID === false) { | ||
validation.addError(`Invalid Application ID`); | ||
} | ||
|
||
if (value.length > 50) { | ||
validation.addError('Application IDs can only be up to 50 characters.'); | ||
} | ||
}; |
14 changes: 14 additions & 0 deletions
14
plugins/humanitec/src/scaffolder/ValidateHumanitecAppID/extensions.ts
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,14 @@ | ||
import { scaffolderPlugin } from '@backstage/plugin-scaffolder'; | ||
import { createScaffolderFieldExtension } from '@backstage/plugin-scaffolder-react'; | ||
import { | ||
ValidateHumanitecAppID, | ||
validateHumanitecAppIDValidation, | ||
} from './ValidateHumanitecAppIDExtension'; | ||
|
||
export const ValidateHumanitecAppIDFieldExtension = scaffolderPlugin.provide( | ||
createScaffolderFieldExtension({ | ||
name: 'ValidateHumanitecAppID', | ||
component: ValidateHumanitecAppID, | ||
validation: validateHumanitecAppIDValidation, | ||
}), | ||
); |
1 change: 1 addition & 0 deletions
1
plugins/humanitec/src/scaffolder/ValidateHumanitecAppID/index.ts
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 @@ | ||
export { ValidateHumanitecAppIDFieldExtension } from './extensions'; |
Oops, something went wrong.