Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ export class Git {
fileMap: FileMap,
unsetBlankAttributes?: boolean,
): Promise<Promise<void>> {
const jsonPathsValuesPublic = jsonpath.nodes(config, fileMap.jsonPathExpression)
let jsonPathsValuesPublic
if (fileMap.kind === 'AplTeamPolicy') {
jsonPathsValuesPublic = jsonpath.nodes(config, '$.teamConfig.*.*')
} else {
jsonPathsValuesPublic = jsonpath.nodes(config, fileMap.jsonPathExpression)
}
await Promise.all(
jsonPathsValuesPublic.map(async (node) => {
const nodePath = node.path
Expand Down
23 changes: 4 additions & 19 deletions src/otomi-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,24 +759,10 @@ export default class OtomiStack {
await this.git.saveConfig(repo, fileMap)
}

async saveTeamPolicies(teamId: string, data: AplPolicyResponse[]): Promise<void> {
async saveTeamPolicy(teamId: string, data: AplPolicyResponse): Promise<void> {
debug(`Saving AplTeamPolicy for team ${teamId}`)
const teamPolicies = {}
data.forEach((policy) => {
teamPolicies[policy.metadata.name] = policy.spec
})
const manifest = {
kind: 'AplTeamPolicy',
metadata: {
name: teamId,
labels: {
'apl.io/teamId': teamId,
},
},
spec: teamPolicies,
}
const configKey = 'policies'
const repo = this.createTeamConfigInRepo(teamId, configKey, manifest)
const configKey = data.metadata.name
const repo = this.createTeamConfigInRepo(teamId, configKey, data)
const fileMap = getFileMaps('').find((fm) => fm.kind === 'AplTeamPolicy')!
await this.git.saveConfig(repo, fileMap)
}
Expand Down Expand Up @@ -1586,8 +1572,7 @@ export default class OtomiStack {
const policy = patch
? this.repoService.getTeamConfigService(teamId).patchPolicies(policyId, data)
: this.repoService.getTeamConfigService(teamId).updatePolicies(policyId, data as AplPolicyRequest)
const teamPolicies = this.getTeamAplPolicies(teamId)
await this.saveTeamPolicies(teamId, teamPolicies)
await this.saveTeamPolicy(teamId, policy)
await this.doTeamDeployment(
teamId,
(teamService) => {
Expand Down
17 changes: 13 additions & 4 deletions src/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export function getResourceName(fileMap: FileMap, jsonPath: jsonpath.PathCompone
return resourceName
}

if (fileMap.resourceGroup === 'team') {
// Custom workaround for teamPolicy because it is a mapItem
if (fileMap.resourceGroup === 'team' && fileMap.kind !== 'AplTeamPolicy') {
resourceName = getTeamNameFromJsonPath(jsonPath)
return resourceName
} else {
Expand Down Expand Up @@ -384,11 +385,11 @@ export function getFileMaps(envDir: string): Array<FileMap> {
{
kind: 'AplTeamPolicy',
envDir,
jsonPathExpression: '$.teamConfig.*.policies',
pathGlob: `${envDir}/env/teams/*/policies.yaml`,
jsonPathExpression: '$.teamConfig.*.policies[*]',
pathGlob: `${envDir}/env/teams/*/policies/*.yaml`,
processAs: 'mapItem',
resourceGroup: 'team',
resourceDir: '.',
resourceDir: 'policies',
loadToSpec: true,
v2: true,
},
Expand Down Expand Up @@ -506,6 +507,13 @@ export async function loadFileToSpec(
} else {
ref.push(data?.spec)
}
} else if (fileMap.kind === 'AplTeamPolicy') {
const ref: Record<string, any> = get(spec, jsonPath)
const policy = {
[data?.metadata?.name]: data?.spec,
}
const newRef = merge(cloneDeep(ref), policy)
set(spec, jsonPath, newRef)
} else {
const ref: Record<string, any> = get(spec, jsonPath)
// TODO: Remove workaround for Team settings currently relying on id in console
Expand Down Expand Up @@ -563,6 +571,7 @@ export async function loadValues(envDir: string, deps = { loadToSpec }): Promise
await deps.loadToSpec(spec, fileMap)
}),
)

return spec
}

Expand Down
Loading