Skip to content

WIP #3487

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

WIP #3487

wants to merge 3 commits into from

Conversation

illume
Copy link
Contributor

@illume illume commented Jun 16, 2025

WIP

  • backend/pkg: Add auth package
  • backend: auth: Extract DecodeBase64JSON from headlamp.go
  • backend: auth: Extract GetExpiryUnixTimeUTC from headlamp.go

illume added 3 commits June 16, 2025 07:50
Uses a better name than decodePayload.
Adds some test cases, and a function doc.
The function logic remains the same.
Explain the type of time in the function name to make it
a bit clearer.

The exp field is in UTC, so we return UTC. Generally all server
side code should be using UTC rather than converting to a
local time zone.

Add some documentation and tests with edge cases.
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 16, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: illume

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 16, 2025
@illume illume requested review from Copilot and removed request for joaquimrocha and vyncent-t June 16, 2025 11:21
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces an auth package to encapsulate base64 JSON decoding and token expiry extraction logic formerly located in headlamp.go, and replaces the inline implementations in headlamp.go with calls to the new functions.

  • Adds auth-related functionality in backend/pkg/auth (DecodeBase64JSON and GetExpiryUnixTimeUTC)
  • Introduces comprehensive tests in backend/pkg/auth/auth_test.go
  • Refactors headlamp.go to use the new auth package utilities

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
backend/pkg/auth/auth.go New auth package with functions for decoding base64 JSON and extracting token expiry
backend/pkg/auth/auth_test.go Unit tests for the new auth package functions
backend/cmd/headlamp.go Refactored to remove duplicate code by using the new auth package functions
Comments suppressed due to low confidence (1)

backend/pkg/auth/auth.go:46

  • [nitpick] Consider rephrasing the function documentation for 'GetExpiryUnixTimeUTC' for improved clarity. For example, use: 'Extracts the expiry Unix time, in UTC, from the token payload's "exp" field.'
func GetExpiryUnixTimeUTC(tokenPayload map[string]interface{}) (time.Time, error) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
Development

Successfully merging this pull request may close these issues.

2 participants